summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2022-11-15 16:49:22 (GMT)
committerGitHub <noreply@github.com>2022-11-15 16:49:22 (GMT)
commit65dab1506e9c8ac40b3f9da834121d86c6417275 (patch)
tree4570072af1fdec50b105b1db974472eb71608920 /Lib/test/test_enum.py
parent3c57971a2d3b6d2c6fd1f525ba2108fccb35add2 (diff)
downloadcpython-65dab1506e9c8ac40b3f9da834121d86c6417275.zip
cpython-65dab1506e9c8ac40b3f9da834121d86c6417275.tar.gz
cpython-65dab1506e9c8ac40b3f9da834121d86c6417275.tar.bz2
gh-92647: [Enum] use final status to determine lookup or create (GH-99500)
* use final status to determine lookup or create * 📜🤖 Added by blurb_it. Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_enum.py')
-rw-r--r--Lib/test/test_enum.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 9097a09..fb3d5ad 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -1321,6 +1321,21 @@ class TestSpecial(unittest.TestCase):
self.assertIn(e, MinorEnum)
self.assertIs(type(e), MinorEnum)
+ def test_programmatic_function_is_value_call(self):
+ class TwoPart(Enum):
+ ONE = 1, 1.0
+ TWO = 2, 2.0
+ THREE = 3, 3.0
+ self.assertRaisesRegex(ValueError, '1 is not a valid .*TwoPart', TwoPart, 1)
+ self.assertIs(TwoPart((1, 1.0)), TwoPart.ONE)
+ self.assertIs(TwoPart(1, 1.0), TwoPart.ONE)
+ class ThreePart(Enum):
+ ONE = 1, 1.0, 'one'
+ TWO = 2, 2.0, 'two'
+ THREE = 3, 3.0, 'three'
+ self.assertIs(ThreePart((3, 3.0, 'three')), ThreePart.THREE)
+ self.assertIs(ThreePart(3, 3.0, 'three'), ThreePart.THREE)
+
def test_intenum_from_bytes(self):
self.assertIs(IntStooges.from_bytes(b'\x00\x03', 'big'), IntStooges.MOE)
with self.assertRaises(ValueError):
@@ -1463,7 +1478,7 @@ class TestSpecial(unittest.TestCase):
class EvenMoreColor(Color, IntEnum):
chartruese = 7
#
- with self.assertRaisesRegex(TypeError, "<enum .Foo.> cannot extend <enum .Color.>"):
+ with self.assertRaisesRegex(ValueError, "\(.Foo., \(.pink., .black.\)\) is not a valid .*Color"):
Color('Foo', ('pink', 'black'))
def test_exclude_methods(self):
@@ -4181,7 +4196,7 @@ expected_help_output_with_docs = """\
Help on class Color in module %s:
class Color(enum.Enum)
- | Color(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
+ | Color(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)
|
| Method resolution order:
| Color
@@ -4237,7 +4252,7 @@ expected_help_output_without_docs = """\
Help on class Color in module %s:
class Color(enum.Enum)
- | Color(value, names=None, *, module=None, qualname=None, type=None, start=1)
+ | Color(value, names=None, *values, module=None, qualname=None, type=None, start=1)
|
| Method resolution order:
| Color