1
2
3
4
5
6
7
8
9
10 """Unit tests for function callback via boxmin"""
11
12 import unittest
13 import numpy
14 import boxmin.tests.cfitfn_example as cfitfn_example
15 from boxmin import _boxmin
16
18
19 return vec[0]+vec[1]+vec[2]
20
23
26
29 self.p = numpy.asarray([1,2,3],'d')
30
32 """direct call to callback using an array"""
33 self.assertEqual(callback(self.p),6)
34
36 """direct call to callback using a Tuple"""
37 self.assertEqual(callback((1,2,3)),6)
38
40 """pyfn call to callback from C"""
41 self.assertEqual(_boxmin.eval(callback,self.p),6)
42
44 """pyfn call to callback from C with array that is too short"""
45 self.assertRaises(IndexError, _boxmin.eval, callback, self.p[0:1])
46
48 """pyfn callback with bad return type"""
49 self.assertRaises(TypeError, _boxmin.eval, badreturn, self.p)
50
52 """pyfn callback with bad signature"""
53 self.assertRaises(TypeError, _boxmin.eval, badsignature, self.p)
54
56 """pyfn call with insufficient arguments"""
57 self.assertRaises(TypeError, _boxmin.eval, callback)
58
60 """pyfn call with too many arguments"""
61 self.assertRaises(TypeError, _boxmin.eval, callback, self.p, 1)
62
64 """pyfn call with wrong tuple instead of callback"""
65 self.assertRaises(TypeError, _boxmin.eval, (callback, self.p))
66
68 """pyfn call with non-callable function"""
69 self.assertRaises(TypeError, _boxmin.eval, 1, self.p)
70
72 """pyfn call with list value"""
73 self.assertRaises(TypeError, _boxmin.eval, callback, [1,2,3])
74
76 """pyfn call with non-numeric value"""
77 self.assertRaises(TypeError, _boxmin.eval, callback, "hello")
78
79
80
81 if __name__ == "__main__":
82 unittest.main()
83