FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet-rawsvnmig/pythonnet/src/tests/test_enum.py at master · pythonnet/pythonnet-rawsvnmig · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Jun 4, 2019. It is now read-only.
pythonnet
/
pythonnet-rawsvnmig
Public archive
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet-rawsvnmig
/
pythonnet
/
src
/
tests
/
test_enum.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
171 lines (118 loc) · 5 KB
Breadcrumbs
pythonnet-rawsvnmig
/
pythonnet
/
src
/
tests
/
test_enum.py
Copy path
File metadata and controls
171 lines (118 loc) · 5 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# ===========================================================================
# 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
from
System
import
DayOfWeek
from
Python
import
Test
class
EnumTests
(
unittest
.
TestCase
):
"""Test CLR enum support."""
def
testEnumStandardAttrs
(
self
):
"""Test standard enum attributes."""
self
.
assertTrue
(
DayOfWeek
.
__name__
==
'DayOfWeek'
)
self
.
assertTrue
(
DayOfWeek
.
__module__
==
'System'
)
self
.
assertTrue
(
type
(
DayOfWeek
.
__dict__
)
==
types
.
DictProxyType
)
self
.
assertTrue
(
DayOfWeek
.
__doc__
==
None
)
def
testEnumGetMember
(
self
):
"""Test access to enum members."""
self
.
assertTrue
(
DayOfWeek
.
Sunday
==
0
)
self
.
assertTrue
(
DayOfWeek
.
Monday
==
1
)
self
.
assertTrue
(
DayOfWeek
.
Tuesday
==
2
)
self
.
assertTrue
(
DayOfWeek
.
Wednesday
==
3
)
self
.
assertTrue
(
DayOfWeek
.
Thursday
==
4
)
self
.
assertTrue
(
DayOfWeek
.
Friday
==
5
)
self
.
assertTrue
(
DayOfWeek
.
Saturday
==
6
)
def
testByteEnum
(
self
):
"""Test byte enum."""
self
.
assertTrue
(
Test
.
ByteEnum
.
Zero
==
0
)
self
.
assertTrue
(
Test
.
ByteEnum
.
One
==
1
)
self
.
assertTrue
(
Test
.
ByteEnum
.
Two
==
2
)
def
testSByteEnum
(
self
):
"""Test sbyte enum."""
self
.
assertTrue
(
Test
.
SByteEnum
.
Zero
==
0
)
self
.
assertTrue
(
Test
.
SByteEnum
.
One
==
1
)
self
.
assertTrue
(
Test
.
SByteEnum
.
Two
==
2
)
def
testShortEnum
(
self
):
"""Test short enum."""
self
.
assertTrue
(
Test
.
ShortEnum
.
Zero
==
0
)
self
.
assertTrue
(
Test
.
ShortEnum
.
One
==
1
)
self
.
assertTrue
(
Test
.
ShortEnum
.
Two
==
2
)
def
testUShortEnum
(
self
):
"""Test ushort enum."""
self
.
assertTrue
(
Test
.
UShortEnum
.
Zero
==
0
)
self
.
assertTrue
(
Test
.
UShortEnum
.
One
==
1
)
self
.
assertTrue
(
Test
.
UShortEnum
.
Two
==
2
)
def
testIntEnum
(
self
):
"""Test int enum."""
self
.
assertTrue
(
Test
.
IntEnum
.
Zero
==
0
)
self
.
assertTrue
(
Test
.
IntEnum
.
One
==
1
)
self
.
assertTrue
(
Test
.
IntEnum
.
Two
==
2
)
def
testUIntEnum
(
self
):
"""Test uint enum."""
self
.
assertTrue
(
Test
.
UIntEnum
.
Zero
==
0L
)
self
.
assertTrue
(
Test
.
UIntEnum
.
One
==
1L
)
self
.
assertTrue
(
Test
.
UIntEnum
.
Two
==
2L
)
def
testLongEnum
(
self
):
"""Test long enum."""
self
.
assertTrue
(
Test
.
LongEnum
.
Zero
==
0L
)
self
.
assertTrue
(
Test
.
LongEnum
.
One
==
1L
)
self
.
assertTrue
(
Test
.
LongEnum
.
Two
==
2L
)
def
testULongEnum
(
self
):
"""Test ulong enum."""
self
.
assertTrue
(
Test
.
ULongEnum
.
Zero
==
0L
)
self
.
assertTrue
(
Test
.
ULongEnum
.
One
==
1L
)
self
.
assertTrue
(
Test
.
ULongEnum
.
Two
==
2L
)
def
testInstantiateEnumFails
(
self
):
"""Test that instantiation of an enum class fails."""
def
test
():
ob
=
DayOfWeek
()
self
.
assertRaises
(
TypeError
,
test
)
def
testSubclassEnumFails
(
self
):
"""Test that subclassing of an enumeration fails."""
def
test
():
class
Boom
(
DayOfWeek
):
pass
self
.
assertRaises
(
TypeError
,
test
)
def
testEnumSetMemberFails
(
self
):
"""Test that setattr operations on enumerations fail."""
def
test
():
DayOfWeek
.
Sunday
=
13
self
.
assertRaises
(
TypeError
,
test
)
def
test
():
del
DayOfWeek
.
Sunday
self
.
assertRaises
(
TypeError
,
test
)
def
testEnumWithFlagsAttrConversion
(
self
):
"""Test enumeration conversion with FlagsAttribute set."""
from
System
.
Windows
.
Forms
import
Label
# This works because the AnchorStyles enum has FlagsAttribute.
label
=
Label
()
label
.
Anchor
=
99
# This should fail because our test enum doesn't have it.
def
test
():
Test
.
FieldTest
().
EnumField
=
99
self
.
assertRaises
(
ValueError
,
test
)
def
testEnumConversion
(
self
):
"""Test enumeration conversion."""
object
=
Test
.
FieldTest
()
self
.
assertTrue
(
object
.
EnumField
==
0
)
object
.
EnumField
=
Test
.
ShortEnum
.
One
self
.
assertTrue
(
object
.
EnumField
==
1
)
def
test
():
Test
.
FieldTest
().
EnumField
=
20
self
.
assertRaises
(
ValueError
,
test
)
def
test
():
Test
.
FieldTest
().
EnumField
=
100000
self
.
assertRaises
(
OverflowError
,
test
)
def
test
():
Test
.
FieldTest
().
EnumField
=
"str"
self
.
assertRaises
(
TypeError
,
test
)
def
test_suite
():
return
unittest
.
makeSuite
(
EnumTests
)
def
main
():
unittest
.
TextTestRunner
().
run
(
test_suite
())
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL