forked from fkarb/pythonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_constructors.py
More file actions
71 lines (50 loc) · 2.1 KB
/
test_constructors.py
File metadata and controls
71 lines (50 loc) · 2.1 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
# ===========================================================================
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# ===========================================================================
import sys, os, string, unittest, types
import clr
clr.AddReference("Python.Test")
import Python.Test as Test
import System
class ConstructorTests(unittest.TestCase):
"""Test CLR class constructor support."""
def testEnumConstructor(self):
"""Test enum constructor args"""
from System import TypeCode
from Python.Test import EnumConstructorTest
ob = EnumConstructorTest(TypeCode.Int32)
self.assertTrue(ob.value == TypeCode.Int32)
def testFlagsConstructor(self):
"""Test flags constructor args"""
from Python.Test import FlagsConstructorTest
from System.IO import FileAccess
flags = FileAccess.Read | FileAccess.Write
ob = FlagsConstructorTest(flags)
self.assertTrue(ob.value == flags)
def testStructConstructor(self):
"""Test struct constructor args"""
from System import Guid
from Python.Test import StructConstructorTest
guid = Guid.NewGuid()
ob = StructConstructorTest(guid)
self.assertTrue(ob.value == guid)
def testSubclassConstructor(self):
"""Test subclass constructor args"""
from Python.Test import SubclassConstructorTest
class sub(System.Exception):
pass
instance = sub()
ob = SubclassConstructorTest(instance)
print(ob)
self.assertTrue(isinstance(ob.value, System.Exception))
def test_suite():
return unittest.makeSuite(ConstructorTests)
def main():
unittest.TextTestRunner().run(test_suite())
if __name__ == '__main__':
main()