-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfoo.py
More file actions
72 lines (59 loc) · 2.04 KB
/
foo.py
File metadata and controls
72 lines (59 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
'''Test APIs'''
import unittest
import pythonnative
from pythonnative.foo import pyFoo
#import pythonnative.foo.pyFoo as foo
if __debug__:
print(f'version: {pythonnative.__version__}')
print(f'pythonnative: ${dir(pythonnative)}')
print(f'pythonnative.foo: ${dir(pythonnative.foo)}')
print(f'pyFoo: ${dir(pyFoo)}')
class TestpyFoo(unittest.TestCase):
'''Test pyFoo'''
def test_free_function(self):
pyFoo.free_function(2147483647) # max int
pyFoo.free_function(2147483647+1) # max int + 1
def test_string_vector(self):
v = pyFoo.string_vector_output(3)
self.assertEqual(3, len(v))
def test_string_jagged_array(self):
v = pyFoo.string_jagged_array_output(5)
self.assertEqual(5, len(v))
for i in range(5):
self.assertEqual(i+1, len(v[i]))
self.assertEqual(
3,
pyFoo.string_jagged_array_input([['1'],['2','3'],['4','5','6']]))
def test_int_pair(self):
p = pyFoo.IntPair(3, 5)
if __debug__:
print(f"class IntPair: {dir(p)}")
self.assertEqual(3, p[0])
self.assertEqual(5, p[1])
self.assertEqual(f'{p}', '(3, 5)')
def test_pair_vector(self):
v = pyFoo.pair_vector_output(3)
self.assertEqual(3, len(v))
def test_pair_jagged_array(self):
v = pyFoo.pair_jagged_array_output(5)
self.assertEqual(5, len(v))
for i in range(5):
self.assertEqual(i+1, len(v[i]))
def test_pyFoo_static_methods(self):
f = pyFoo.Foo()
if __debug__:
print(f'class Foo: ${dir(f)}')
f.static_function(1)
f.static_function(2147483647)
f.static_function(2147483647+1)
def test_pyFoo_int_methods(self):
f = pyFoo.Foo()
f.set_int(13)
self.assertEqual(f.get_int(), 13)
def test_pyFoo_int64_methods(self):
f = pyFoo.Foo()
f.set_int64(31)
self.assertEqual(f.get_int64(), 31)
if __name__ == '__main__':
unittest.main(verbosity=2)