diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-01-18 04:36:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-18 04:36:28 (GMT) |
commit | 35e330ba859c915043d2e9808b44120f67328873 (patch) | |
tree | 313c8a54705453a8dfa6ef7806cfb051b44ec9fd /Lib/test | |
parent | 87198f6c2377a52ee7ec779b7f85daa8deef7f02 (diff) | |
download | cpython-35e330ba859c915043d2e9808b44120f67328873.zip cpython-35e330ba859c915043d2e9808b44120f67328873.tar.gz cpython-35e330ba859c915043d2e9808b44120f67328873.tar.bz2 |
[3.12] gh-114149: [Enum] revert GH-114196 and add more tuple-subclass tests (GH-114215) (GH-114218)
gh-114149: [Enum] revert GH-114160 and add more tuple-subclass tests (GH-114215)
This reverts commit 05e142b1543eb9662d6cc33722e7e16250c9219f.
(cherry picked from commit 4c7e09d0129dafddba58979ced9580f856f65efa)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_enum.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 2db3b2f..23be142 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -3163,19 +3163,34 @@ class TestSpecial(unittest.TestCase): [x.value for x in NTEnum], [TTuple(id=0, a=0, blist=[]), TTuple(id=1, a=2, blist=[4]), TTuple(id=2, a=4, blist=[0, 1, 2])], ) + + self.assertRaises(AttributeError, getattr, NTEnum.NONE, 'id') + # + class NTCEnum(TTuple, Enum): + NONE = 0, 0, [] + A = 1, 2, [4] + B = 2, 4, [0, 1, 2] + self.assertEqual(repr(NTCEnum.NONE), "<NTCEnum.NONE: TTuple(id=0, a=0, blist=[])>") + self.assertEqual(NTCEnum.NONE.value, TTuple(id=0, a=0, blist=[])) + self.assertEqual(NTCEnum.NONE.id, 0) + self.assertEqual(NTCEnum.A.a, 2) + self.assertEqual(NTCEnum.B.blist, [0, 1 ,2]) + self.assertEqual( + [x.value for x in NTCEnum], + [TTuple(id=0, a=0, blist=[]), TTuple(id=1, a=2, blist=[4]), TTuple(id=2, a=4, blist=[0, 1, 2])], + ) # class NTDEnum(Enum): - def __new__(cls, t_value): + def __new__(cls, id, a, blist): member = object.__new__(cls) - member._value_ = t_value[0] - member.id = t_value[0] - member.a = t_value[1] - member.blist = t_value[2] + member.id = id + member.a = a + member.blist = blist return member NONE = TTuple(0, 0, []) A = TTuple(1, 2, [4]) B = TTuple(2, 4, [0, 1, 2]) - self.assertEqual(repr(NTDEnum.NONE), "<NTDEnum.NONE: 0>") + self.assertEqual(repr(NTDEnum.NONE), "<NTDEnum.NONE: TTuple(id=0, a=0, blist=[])>") self.assertEqual(NTDEnum.NONE.id, 0) self.assertEqual(NTDEnum.A.a, 2) self.assertEqual(NTDEnum.B.blist, [0, 1 ,2]) |