aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/deprecated/python/enum34/patches/02-fix-tests.patch
blob: 96e67e60b89c620549a673a0bd4f00b83c0b1b56 (plain) (blame)
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
--- contrib/deprecated/python/enum34/enum/test.py	(index)
+++ contrib/deprecated/python/enum34/enum/test.py	(working tree)
@@ -94,7 +94,9 @@ try:
 except Exception:
     pass
 
-def test_pickle_dump_load(assertion, source, target=None,
+import pytest
+
+def check_pickle_dump_load(assertion, source, target=None,
         protocol=(0, HIGHEST_PROTOCOL)):
     start, stop = protocol
     failures = []
@@ -110,7 +112,7 @@ def test_pickle_dump_load(assertion, source, target=None,
     if failures:
         raise ValueError('Failed with protocols: %s' % ', '.join(failures))
 
-def test_pickle_exception(assertion, exception, obj,
+def check_pickle_exception(assertion, exception, obj,
         protocol=(0, HIGHEST_PROTOCOL)):
     start, stop = protocol
     failures = []
@@ -610,32 +612,32 @@ class TestEnum(unittest.TestCase):
     def test_pickle_enum(self):
         if isinstance(Stooges, Exception):
             raise Stooges
-        test_pickle_dump_load(self.assertTrue, Stooges.CURLY)
-        test_pickle_dump_load(self.assertTrue, Stooges)
+        check_pickle_dump_load(self.assertTrue, Stooges.CURLY)
+        check_pickle_dump_load(self.assertTrue, Stooges)
 
     def test_pickle_int(self):
         if isinstance(IntStooges, Exception):
             raise IntStooges
-        test_pickle_dump_load(self.assertTrue, IntStooges.CURLY)
-        test_pickle_dump_load(self.assertTrue, IntStooges)
+        check_pickle_dump_load(self.assertTrue, IntStooges.CURLY)
+        check_pickle_dump_load(self.assertTrue, IntStooges)
 
     def test_pickle_float(self):
         if isinstance(FloatStooges, Exception):
             raise FloatStooges
-        test_pickle_dump_load(self.assertTrue, FloatStooges.CURLY)
-        test_pickle_dump_load(self.assertTrue, FloatStooges)
+        check_pickle_dump_load(self.assertTrue, FloatStooges.CURLY)
+        check_pickle_dump_load(self.assertTrue, FloatStooges)
 
     def test_pickle_enum_function(self):
         if isinstance(Answer, Exception):
             raise Answer
-        test_pickle_dump_load(self.assertTrue, Answer.him)
-        test_pickle_dump_load(self.assertTrue, Answer)
+        check_pickle_dump_load(self.assertTrue, Answer.him)
+        check_pickle_dump_load(self.assertTrue, Answer)
 
     def test_pickle_enum_function_with_module(self):
         if isinstance(Question, Exception):
             raise Question
-        test_pickle_dump_load(self.assertTrue, Question.who)
-        test_pickle_dump_load(self.assertTrue, Question)
+        check_pickle_dump_load(self.assertTrue, Question.who)
+        check_pickle_dump_load(self.assertTrue, Question)
 
     if pyver == 3.4:
         def test_class_nested_enum_and_pickle_protocol_four(self):
@@ -646,10 +648,10 @@ class TestEnum(unittest.TestCase):
 
             self.__class__.NestedEnum = NestedEnum
             self.NestedEnum.__qualname__ = '%s.NestedEnum' % self.__class__.__name__
-            test_pickle_exception(
+            check_pickle_exception(
                     self.assertRaises, PicklingError, self.NestedEnum.twigs,
                     protocol=(0, 3))
-            test_pickle_dump_load(self.assertTrue, self.NestedEnum.twigs,
+            check_pickle_dump_load(self.assertTrue, self.NestedEnum.twigs,
                     protocol=(4, HIGHEST_PROTOCOL))
 
     elif pyver == 3.5:
@@ -661,15 +663,15 @@ class TestEnum(unittest.TestCase):
 
             self.__class__.NestedEnum = NestedEnum
             self.NestedEnum.__qualname__ = '%s.NestedEnum' % self.__class__.__name__
-            test_pickle_dump_load(self.assertTrue, self.NestedEnum.twigs,
+            check_pickle_dump_load(self.assertTrue, self.NestedEnum.twigs,
                     protocol=(0, HIGHEST_PROTOCOL))
 
     def test_exploding_pickle(self):
         BadPickle = Enum('BadPickle', 'dill sweet bread_n_butter')
         enum._make_class_unpicklable(BadPickle)
         globals()['BadPickle'] = BadPickle
-        test_pickle_exception(self.assertRaises, TypeError, BadPickle.dill)
-        test_pickle_exception(self.assertRaises, PicklingError, BadPickle)
+        check_pickle_exception(self.assertRaises, TypeError, BadPickle.dill)
+        check_pickle_exception(self.assertRaises, PicklingError, BadPickle)
 
     def test_string_enum(self):
         class SkillLevel(str, Enum):
@@ -1066,7 +1068,7 @@ class TestEnum(unittest.TestCase):
         self.assertEqual(Name.BDFL, 'Guido van Rossum')
         self.assertTrue(Name.BDFL, Name('Guido van Rossum'))
         self.assertTrue(Name.BDFL is getattr(Name, 'BDFL'))
-        test_pickle_dump_load(self.assertTrue, Name.BDFL)
+        check_pickle_dump_load(self.assertTrue, Name.BDFL)
 
     def test_extending(self):
         def bad_extension():
@@ -1291,9 +1293,9 @@ class TestEnum(unittest.TestCase):
         globals()['NEI'] = NEI
         NI5 = NamedInt('test', 5)
         self.assertEqual(NI5, 5)
-        test_pickle_dump_load(self.assertTrue, NI5, 5)
+        check_pickle_dump_load(self.assertTrue, NI5, 5)
         self.assertEqual(NEI.y.value, 2)
-        test_pickle_dump_load(self.assertTrue, NEI.y)
+        check_pickle_dump_load(self.assertTrue, NEI.y)
 
     if pyver >= 3.4:
         def test_subclasses_with_getnewargs_ex(self):
@@ -1348,9 +1350,9 @@ class TestEnum(unittest.TestCase):
             globals()['NEI'] = NEI
             NI5 = NamedInt('test', 5)
             self.assertEqual(NI5, 5)
-            test_pickle_dump_load(self.assertEqual, NI5, 5, protocol=(4, HIGHEST_PROTOCOL))
+            check_pickle_dump_load(self.assertEqual, NI5, 5, protocol=(4, HIGHEST_PROTOCOL))
             self.assertEqual(NEI.y.value, 2)
-            test_pickle_dump_load(self.assertTrue, NEI.y, protocol=(4, HIGHEST_PROTOCOL))
+            check_pickle_dump_load(self.assertTrue, NEI.y, protocol=(4, HIGHEST_PROTOCOL))
 
     def test_subclasses_with_reduce(self):
         class NamedInt(int):
@@ -1404,9 +1406,9 @@ class TestEnum(unittest.TestCase):
         globals()['NEI'] = NEI
         NI5 = NamedInt('test', 5)
         self.assertEqual(NI5, 5)
-        test_pickle_dump_load(self.assertEqual, NI5, 5)
+        check_pickle_dump_load(self.assertEqual, NI5, 5)
         self.assertEqual(NEI.y.value, 2)
-        test_pickle_dump_load(self.assertTrue, NEI.y)
+        check_pickle_dump_load(self.assertTrue, NEI.y)
 
     def test_subclasses_with_reduce_ex(self):
         class NamedInt(int):
@@ -1460,9 +1462,9 @@ class TestEnum(unittest.TestCase):
         globals()['NEI'] = NEI
         NI5 = NamedInt('test', 5)
         self.assertEqual(NI5, 5)
-        test_pickle_dump_load(self.assertEqual, NI5, 5)
+        check_pickle_dump_load(self.assertEqual, NI5, 5)
         self.assertEqual(NEI.y.value, 2)
-        test_pickle_dump_load(self.assertTrue, NEI.y)
+        check_pickle_dump_load(self.assertTrue, NEI.y)
 
     def test_subclasses_without_direct_pickle_support(self):
         class NamedInt(int):
@@ -1514,8 +1516,8 @@ class TestEnum(unittest.TestCase):
         NI5 = NamedInt('test', 5)
         self.assertEqual(NI5, 5)
         self.assertEqual(NEI.y.value, 2)
-        test_pickle_exception(self.assertRaises, TypeError, NEI.x)
-        test_pickle_exception(self.assertRaises, PicklingError, NEI)
+        check_pickle_exception(self.assertRaises, TypeError, NEI.x)
+        check_pickle_exception(self.assertRaises, PicklingError, NEI)
 
     def test_subclasses_without_direct_pickle_support_using_name(self):
         class NamedInt(int):
@@ -1569,8 +1571,8 @@ class TestEnum(unittest.TestCase):
         NI5 = NamedInt('test', 5)
         self.assertEqual(NI5, 5)
         self.assertEqual(NEI.y.value, 2)
-        test_pickle_dump_load(self.assertTrue, NEI.y)
-        test_pickle_dump_load(self.assertTrue, NEI)
+        check_pickle_dump_load(self.assertTrue, NEI.y)
+        check_pickle_dump_load(self.assertTrue, NEI)
 
     def test_tuple_subclass(self):
         class SomeTuple(tuple, Enum):
@@ -1582,7 +1584,7 @@ class TestEnum(unittest.TestCase):
         self.assertTrue(isinstance(SomeTuple.second, tuple))
         self.assertEqual(SomeTuple.third, (3, 'for the music'))
         globals()['SomeTuple'] = SomeTuple
-        test_pickle_dump_load(self.assertTrue, SomeTuple.first)
+        check_pickle_dump_load(self.assertTrue, SomeTuple.first)
 
     def test_duplicate_values_give_unique_enum_items(self):
         class AutoNumber(Enum):
@@ -1832,6 +1834,30 @@ class TestUnique(unittest.TestCase):
         self.assertTrue('double -> single' in message)
         self.assertTrue('turkey -> triple' in message)
 
+    def test_unique_class(self):
+        values = [
+            ('switzerland', 1),
+            ('sweden', 2),
+            ('usa', 3),
+            ('iran', 4),
+            ('iraq', 4),
+        ]
+        with self.assertRaises(ValueError):
+            enum.Enum('Country', values, allow_synonyms=False)
+
+        with self.assertRaises(ValueError):
+            class Country(enum.Enum):
+                __allow_synonyms__ = False
+
+                austria = 1
+                australia = 1
+
+        with self.assertRaises(ValueError):
+            class NoDuplicatesAllowed(enum.Enum):
+                __allow_synonyms__ = False
+
+            t = NoDuplicatesAllowed('NewEnum', [('russia', 1), ('belorussia', 1)])
+
 
 class TestMe(unittest.TestCase):