| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
import jpype |
| 19 |
from jpype.types import * |
| 20 |
import sys |
| 21 |
import logging |
| 22 |
import time |
| 23 |
import common |
| 24 |
|
| 25 |
|
| 26 |
def haveNumpy(): |
| 27 |
try: |
| 28 |
import numpy |
| 29 |
return True |
| 30 |
except ImportError: |
| 31 |
return False |
| 32 |
|
| 33 |
|
| 34 |
class ConversionIntTestCase(common.JPypeTestCase): |
| 35 |
def setUp(self): |
| 36 |
common.JPypeTestCase.setUp(self) |
| 37 |
self.Test = jpype.JClass("jpype.common.Fixture")() |
| 38 |
|
| 39 |
def testIntFromInt(self): |
| 40 |
self.assertEqual(self.Test.callInt(int(123)), 123) |
| 41 |
|
| 42 |
@common.unittest.skipUnless(haveNumpy(), "numpy not available") |
| 43 |
def testIntFromNPInt(self): |
| 44 |
import numpy as np |
| 45 |
self.assertEqual(self.Test.callInt(np.int_(123)), 123) |
| 46 |
|
| 47 |
@common.unittest.skipUnless(haveNumpy(), "numpy not available") |
| 48 |
def testIntFromNPInt8(self): |
| 49 |
import numpy as np |
| 50 |
self.assertEqual(self.Test.callInt(np.int8(123)), 123) |
| 51 |
self.assertEqual(self.Test.callInt(np.uint8(123)), 123) |
| 52 |
|
| 53 |
@common.unittest.skipUnless(haveNumpy(), "numpy not available") |
| 54 |
def testIntFromNPInt16(self): |
| 55 |
import numpy as np |
| 56 |
self.assertEqual(self.Test.callInt(np.int16(123)), 123) |
| 57 |
self.assertEqual(self.Test.callInt(np.uint16(123)), 123) |
| 58 |
|
| 59 |
@common.unittest.skipUnless(haveNumpy(), "numpy not available") |
| 60 |
def testIntFromNPInt32(self): |
| 61 |
import numpy as np |
| 62 |
self.assertEqual(self.Test.callInt(np.int32(123)), 123) |
| 63 |
self.assertEqual(self.Test.callInt(np.uint32(123)), 123) |
| 64 |
|
| 65 |
@common.unittest.skipUnless(haveNumpy(), "numpy not available") |
| 66 |
def testIntFromNPInt64(self): |
| 67 |
import numpy as np |
| 68 |
self.assertEqual(self.Test.callInt(np.int64(123)), 123) |
| 69 |
self.assertEqual(self.Test.callInt(np.uint64(123)), 123) |
| 70 |
|
| 71 |
def testIntFromFloat(self): |
| 72 |
with self.assertRaises(TypeError): |
| 73 |
self.Test.callInt(float(2)) |
| 74 |
|
| 75 |
@common.unittest.skipUnless(haveNumpy(), "numpy not available") |
| 76 |
def testIntFromNPFloat16(self): |
| 77 |
import numpy as np |
| 78 |
with self.assertRaises(TypeError): |
| 79 |
self.Test.callInt(np.float16(2)) |
| 80 |
|
| 81 |
@common.unittest.skipUnless(haveNumpy(), "numpy not available") |
| 82 |
def testIntFromNPFloat32(self): |
| 83 |
import numpy as np |
| 84 |
with self.assertRaises(TypeError): |
| 85 |
self.Test.callInt(np.float32(2)) |
| 86 |
|
| 87 |
@common.unittest.skipUnless(haveNumpy(), "numpy not available") |
| 88 |
def testIntFromNPFloat64(self): |
| 89 |
import numpy as np |
| 90 |
with self.assertRaises(TypeError): |
| 91 |
self.Test.callInt(np.float64(2)) |
| 92 |
|
| 93 |
def testIntRange(self): |
| 94 |
with self.assertRaises(OverflowError): |
| 95 |
self.Test.callInt(int(1e10)) |
| 96 |
with self.assertRaises(OverflowError): |
| 97 |
self.Test.callInt(int(-1e10)) |
| 98 |
|
| 99 |
def testIntFromNone(self): |
| 100 |
with self.assertRaises(TypeError): |
| 101 |
self.Test.callInt(None) |