gh-116040: [Enum] fix test_empty_names test (GH-116508)

* and fix _not_given usage
This commit is contained in:
Ethan Furman 2024-03-11 13:42:01 -07:00 committed by GitHub
parent 34920f3691
commit 3c0dcef980
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 14 deletions

View File

@ -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,

View File

@ -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):