|
@@ -0,0 +1,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):
|
|
|
+
|