mirror of
https://github.com/python/cpython.git
synced 2024-11-27 03:45:08 +08:00
gh-116040: [Enum] fix test_empty_names test (GH-116508)
* and fix _not_given usage
This commit is contained in:
parent
34920f3691
commit
3c0dcef980
@ -165,8 +165,6 @@ def _dedent(text):
|
||||
class _not_given:
|
||||
def __repr__(self):
|
||||
return('<not given>')
|
||||
def __bool__(self):
|
||||
return False
|
||||
_not_given = _not_given()
|
||||
|
||||
class _auto_null:
|
||||
@ -727,7 +725,7 @@ class EnumType(type):
|
||||
)
|
||||
return cls._create_(
|
||||
class_name=value,
|
||||
names=names or None,
|
||||
names=None if names is _not_given else names,
|
||||
module=module,
|
||||
qualname=qualname,
|
||||
type=type,
|
||||
|
@ -3431,17 +3431,13 @@ class TestSpecial(unittest.TestCase):
|
||||
Flag(7)
|
||||
|
||||
def test_empty_names(self):
|
||||
for nothing, e_type in (
|
||||
('', None),
|
||||
('', int),
|
||||
([], None),
|
||||
([], int),
|
||||
({}, None),
|
||||
({}, int),
|
||||
):
|
||||
empty_enum = Enum('empty_enum', nothing, type=e_type)
|
||||
self.assertEqual(len(empty_enum), 0)
|
||||
self.assertRaises(TypeError, 'has no members', empty_enum, 0)
|
||||
for nothing in '', [], {}:
|
||||
for e_type in None, int:
|
||||
empty_enum = Enum('empty_enum', nothing, type=e_type)
|
||||
self.assertEqual(len(empty_enum), 0)
|
||||
self.assertRaisesRegex(TypeError, 'has no members', empty_enum, 0)
|
||||
self.assertRaisesRegex(TypeError, '.int. object is not iterable', Enum, 'bad_enum', names=0)
|
||||
self.assertRaisesRegex(TypeError, '.int. object is not iterable', Enum, 'bad_enum', 0, type=int)
|
||||
|
||||
|
||||
class TestOrder(unittest.TestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user