mirror of
https://github.com/python/cpython.git
synced 2025-08-31 22:18:28 +00:00
Close issue21706: add 'start' parameter to functional API
This commit is contained in:
parent
52351c7037
commit
d9925a18ec
3 changed files with 80 additions and 11 deletions
|
@ -634,6 +634,23 @@ class TestEnum(unittest.TestCase):
|
|||
self.assertIn(e, SummerMonth)
|
||||
self.assertIs(type(e), SummerMonth)
|
||||
|
||||
def test_programatic_function_string_with_start(self):
|
||||
SummerMonth = Enum('SummerMonth', 'june july august', start=10)
|
||||
lst = list(SummerMonth)
|
||||
self.assertEqual(len(lst), len(SummerMonth))
|
||||
self.assertEqual(len(SummerMonth), 3, SummerMonth)
|
||||
self.assertEqual(
|
||||
[SummerMonth.june, SummerMonth.july, SummerMonth.august],
|
||||
lst,
|
||||
)
|
||||
for i, month in enumerate('june july august'.split(), 10):
|
||||
e = SummerMonth(i)
|
||||
self.assertEqual(int(e.value), i)
|
||||
self.assertNotEqual(e, i)
|
||||
self.assertEqual(e.name, month)
|
||||
self.assertIn(e, SummerMonth)
|
||||
self.assertIs(type(e), SummerMonth)
|
||||
|
||||
def test_programatic_function_string_list(self):
|
||||
SummerMonth = Enum('SummerMonth', ['june', 'july', 'august'])
|
||||
lst = list(SummerMonth)
|
||||
|
@ -651,6 +668,23 @@ class TestEnum(unittest.TestCase):
|
|||
self.assertIn(e, SummerMonth)
|
||||
self.assertIs(type(e), SummerMonth)
|
||||
|
||||
def test_programatic_function_string_list_with_start(self):
|
||||
SummerMonth = Enum('SummerMonth', ['june', 'july', 'august'], start=20)
|
||||
lst = list(SummerMonth)
|
||||
self.assertEqual(len(lst), len(SummerMonth))
|
||||
self.assertEqual(len(SummerMonth), 3, SummerMonth)
|
||||
self.assertEqual(
|
||||
[SummerMonth.june, SummerMonth.july, SummerMonth.august],
|
||||
lst,
|
||||
)
|
||||
for i, month in enumerate('june july august'.split(), 20):
|
||||
e = SummerMonth(i)
|
||||
self.assertEqual(int(e.value), i)
|
||||
self.assertNotEqual(e, i)
|
||||
self.assertEqual(e.name, month)
|
||||
self.assertIn(e, SummerMonth)
|
||||
self.assertIs(type(e), SummerMonth)
|
||||
|
||||
def test_programatic_function_iterable(self):
|
||||
SummerMonth = Enum(
|
||||
'SummerMonth',
|
||||
|
@ -707,6 +741,22 @@ class TestEnum(unittest.TestCase):
|
|||
self.assertIn(e, SummerMonth)
|
||||
self.assertIs(type(e), SummerMonth)
|
||||
|
||||
def test_programatic_function_type_with_start(self):
|
||||
SummerMonth = Enum('SummerMonth', 'june july august', type=int, start=30)
|
||||
lst = list(SummerMonth)
|
||||
self.assertEqual(len(lst), len(SummerMonth))
|
||||
self.assertEqual(len(SummerMonth), 3, SummerMonth)
|
||||
self.assertEqual(
|
||||
[SummerMonth.june, SummerMonth.july, SummerMonth.august],
|
||||
lst,
|
||||
)
|
||||
for i, month in enumerate('june july august'.split(), 30):
|
||||
e = SummerMonth(i)
|
||||
self.assertEqual(e, i)
|
||||
self.assertEqual(e.name, month)
|
||||
self.assertIn(e, SummerMonth)
|
||||
self.assertIs(type(e), SummerMonth)
|
||||
|
||||
def test_programatic_function_type_from_subclass(self):
|
||||
SummerMonth = IntEnum('SummerMonth', 'june july august')
|
||||
lst = list(SummerMonth)
|
||||
|
@ -723,6 +773,22 @@ class TestEnum(unittest.TestCase):
|
|||
self.assertIn(e, SummerMonth)
|
||||
self.assertIs(type(e), SummerMonth)
|
||||
|
||||
def test_programatic_function_type_from_subclass_with_start(self):
|
||||
SummerMonth = IntEnum('SummerMonth', 'june july august', start=40)
|
||||
lst = list(SummerMonth)
|
||||
self.assertEqual(len(lst), len(SummerMonth))
|
||||
self.assertEqual(len(SummerMonth), 3, SummerMonth)
|
||||
self.assertEqual(
|
||||
[SummerMonth.june, SummerMonth.july, SummerMonth.august],
|
||||
lst,
|
||||
)
|
||||
for i, month in enumerate('june july august'.split(), 40):
|
||||
e = SummerMonth(i)
|
||||
self.assertEqual(e, i)
|
||||
self.assertEqual(e.name, month)
|
||||
self.assertIn(e, SummerMonth)
|
||||
self.assertIs(type(e), SummerMonth)
|
||||
|
||||
def test_subclassing(self):
|
||||
if isinstance(Name, Exception):
|
||||
raise Name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue