diff options
author | Ethan Furman <ethan@stoneleaf.us> | 2021-06-16 01:50:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-16 01:50:59 (GMT) |
commit | 41c2a4a727d3d559632598759433e0ec1bf594f5 (patch) | |
tree | 97744d0c093754c267099125153bfdbafdd0cb28 /Lib | |
parent | 0f99324f61d5a2edd8729be5eed6f172c892af24 (diff) | |
download | cpython-41c2a4a727d3d559632598759433e0ec1bf594f5.zip cpython-41c2a4a727d3d559632598759433e0ec1bf594f5.tar.gz cpython-41c2a4a727d3d559632598759433e0ec1bf594f5.tar.bz2 |
[3.10] bpo-44342: [Enum] improve test, add andrei kulakov to ACKS (GH-26726)
* [3.10] [Enum] improve test, add andrei kulakov to ACKS (GH-26726).
(cherry picked from commit cb2014f2077c92c35486bf0db7e646a68478a7a5)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/enum.py | 2 | ||||
-rw-r--r-- | Lib/test/test_enum.py | 27 |
2 files changed, 26 insertions, 3 deletions
diff --git a/Lib/enum.py b/Lib/enum.py index 49c46ea..9077798 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -1637,7 +1637,7 @@ class verify: else: value = 'combined values of 0x%x' % missing_value raise ValueError( - 'invalid Flag %r: %s %s [use `enum.show_flag_values(value)` for details]' + 'invalid Flag %r: %s %s [use enum.show_flag_values(value) for details]' % (cls_name, alias, value) ) return enumeration diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 956b834..c4c458e 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -660,12 +660,35 @@ class TestEnum(unittest.TestCase): self.assertEqual(repr(MyEnum.A), '<MyEnum.A: 0x1>') # class SillyInt(HexInt): + __qualname__ = 'SillyInt' pass class MyOtherEnum(SillyInt, enum.Enum): + __qualname__ = 'MyOtherEnum' D = 4 E = 5 F = 6 self.assertIs(MyOtherEnum._member_type_, SillyInt) + globals()['SillyInt'] = SillyInt + globals()['MyOtherEnum'] = MyOtherEnum + test_pickle_dump_load(self.assertIs, MyOtherEnum.E) + test_pickle_dump_load(self.assertIs, MyOtherEnum) + # + # This did not work in 3.9, but does now with pickling by name + class UnBrokenInt(int): + __qualname__ = 'UnBrokenInt' + def __new__(cls, value): + return int.__new__(cls, value) + class MyUnBrokenEnum(UnBrokenInt, Enum): + __qualname__ = 'MyUnBrokenEnum' + G = 7 + H = 8 + I = 9 + self.assertIs(MyUnBrokenEnum._member_type_, UnBrokenInt) + self.assertIs(MyUnBrokenEnum(7), MyUnBrokenEnum.G) + globals()['UnBrokenInt'] = UnBrokenInt + globals()['MyUnBrokenEnum'] = MyUnBrokenEnum + test_pickle_dump_load(self.assertIs, MyUnBrokenEnum.I) + test_pickle_dump_load(self.assertIs, MyUnBrokenEnum) def test_too_many_data_types(self): with self.assertRaisesRegex(TypeError, 'too many data types'): @@ -3591,7 +3614,7 @@ class TestVerify(unittest.TestCase): self.assertEqual(Bizarre.d.value, 6) with self.assertRaisesRegex( ValueError, - "invalid Flag 'Bizarre': aliases b and d are missing combined values of 0x3 .use `enum.show_flag_values.value.` for details.", + "invalid Flag 'Bizarre': aliases b and d are missing combined values of 0x3 .use enum.show_flag_values.value. for details.", ): @verify(NAMED_FLAGS) class Bizarre(Flag): @@ -3610,7 +3633,7 @@ class TestVerify(unittest.TestCase): self.assertEqual(Bizarre.d.value, 6) with self.assertRaisesRegex( ValueError, - "invalid Flag 'Bizarre': alias d is missing value 0x2 .use `enum.show_flag_values.value.` for details.", + "invalid Flag 'Bizarre': alias d is missing value 0x2 .use enum.show_flag_values.value. for details.", ): @verify(NAMED_FLAGS) class Bizarre(IntFlag): |