File: test_objmodel.py

package info (click to toggle)
mpi4py 2.0.0-2.1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,680 kB
  • sloc: python: 15,291; ansic: 7,099; makefile: 719; f90: 158; sh: 156; cpp: 121
file content (115 lines) | stat: -rw-r--r-- 3,601 bytes parent folder | download | duplicates (2)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from mpi4py import MPI
import mpiunittest as unittest
import sys


class TestObjModel(unittest.TestCase):

    objects = [
        MPI.Status(),
        MPI.DATATYPE_NULL,
        MPI.REQUEST_NULL,
        MPI.INFO_NULL,
        MPI.ERRHANDLER_NULL,
        MPI.GROUP_NULL,
        MPI.WIN_NULL,
        MPI.OP_NULL,
        MPI.FILE_NULL,
        MPI.MESSAGE_NULL,
        MPI.COMM_NULL,
    ]

    def testEq(self):
        for i, obj1 in enumerate(self.objects):
            objects = self.objects[:]
            obj2 = objects[i]
            self.assertTrue(obj1 == obj2)
            self.assertFalse(obj1 != obj2)
            del objects[i]
            for obj2 in objects:
                self.assertTrue(obj1 != obj2)
                self.assertTrue(obj2 != obj1)
                self.assertFalse(obj1 == obj2)
                self.assertFalse(obj2 == obj1)
            self.assertFalse(None == obj1 )
            self.assertFalse(obj1 == None )
            self.assertFalse(obj1 == True )
            self.assertFalse(obj1 == False)
            self.assertFalse(obj1 == 12345)
            self.assertFalse(obj1 == "abc")
            self.assertFalse(obj1 == [123])
            self.assertFalse(obj1 == (1,2))
            self.assertFalse(obj1 == {0:0})
            self.assertFalse(obj1 == set())

    def testNe(self):
        for i, obj1 in enumerate(self.objects):
            objects = self.objects[:]
            obj2 = objects[i]
            self.assertFalse(obj1 != obj2)
            del objects[i]
            for obj2 in objects:
                self.assertTrue (obj1 != obj2)
            self.assertTrue(None != obj1 )
            self.assertTrue(obj1 != None )
            self.assertTrue(obj1 != True )
            self.assertTrue(obj1 != False)
            self.assertTrue(obj1 != 12345)
            self.assertTrue(obj1 != "abc")
            self.assertTrue(obj1 != [123])
            self.assertTrue(obj1 != (1,2))
            self.assertTrue(obj1 != {0:0})
            self.assertTrue(obj1 != set())

    def testBool(self):
        for obj in self.objects[1:]:
            self.assertFalse(not not obj)
            self.assertTrue(not obj)
            self.assertFalse(obj)

    def testHash(self):
        try:
            hash(MPI.COMM_NULL)
        except TypeError:
            pass
        else:
            if hasattr(sys, 'pypy_version_info'): return
        for obj in self.objects:
            ob_hash = lambda: hash(obj)
            self.assertRaises(TypeError, ob_hash)

    def testInit(self):
        for i, obj in enumerate(self.objects):
            klass = type(obj)
            new = klass()
            self.assertEqual(new, obj)
            new = klass(obj)
            self.assertEqual(new, obj)
            objects = self.objects[:]
            del objects[i]
            for other in objects:
                ob_init = lambda: klass(other)
                self.assertRaises(TypeError, ob_init)
            ob_init = lambda: klass(1234)
            self.assertRaises(TypeError, ob_init)
            ob_init = lambda: klass("abc")
            self.assertRaises(TypeError, ob_init)

    def testSizeOf(self):
        for obj in self.objects:
            n1 = MPI._sizeof(obj)
            n2 = MPI._sizeof(type(obj))
            self.assertEqual(n1, n2)

    def testAddressOf(self):
        for obj in self.objects:
            addr = MPI._addressof(obj)

    def testAHandleOf(self):
        for obj in self.objects:
            if isinstance(obj, MPI.Status): continue
            hdl = MPI._handleof(obj)


if __name__ == '__main__':
    unittest.main()