From 025fad810b2335491ec4779f206e4a136d893f25 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 5 Jan 2022 01:39:44 +0300 Subject: [PATCH 1/3] bpo-46262: cover error path in `enum.Flag._missing` --- Lib/test/test_enum.py | 26 +++++++++++++++++++ .../2022-01-05-01-38-45.bpo-46262.MhiLWP.rst | 1 + 2 files changed, 27 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2022-01-05-01-38-45.bpo-46262.MhiLWP.rst diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index eecb9fd4835c40..51a31e5ebf8076 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -3414,6 +3414,19 @@ class NeverEnum(WhereEnum): self.assertFalse(NeverEnum.__dict__.get('_test1', False)) self.assertFalse(NeverEnum.__dict__.get('_test2', False)) + def test_default_missing(self): + with self.assertRaisesRegex( + ValueError, + "'RED' is not a valid TestFlag.Color", + ) as ctx: + self.Color('RED') + self.assertIs(ctx.exception.__context__, None) + + P = Flag('P', 'X Y') + with self.assertRaisesRegex(ValueError, "'X' is not a valid P") as ctx: + P('X') + self.assertIs(ctx.exception.__context__, None) + class TestIntFlag(unittest.TestCase): """Tests of the IntFlags.""" @@ -3975,6 +3988,19 @@ def cycle_enum(): 'at least one thread failed while creating composite members') self.assertEqual(256, len(seen), 'too many composite members created') + def test_default_missing(self): + with self.assertRaisesRegex( + ValueError, + "'RED' is not a valid TestIntFlag.Color", + ) as ctx: + self.Color('RED') + self.assertIs(ctx.exception.__context__, None) + + P = IntFlag('P', 'X Y') + with self.assertRaisesRegex(ValueError, "'X' is not a valid P") as ctx: + P('X') + self.assertIs(ctx.exception.__context__, None) + class TestEmptyAndNonLatinStrings(unittest.TestCase): diff --git a/Misc/NEWS.d/next/Tests/2022-01-05-01-38-45.bpo-46262.MhiLWP.rst b/Misc/NEWS.d/next/Tests/2022-01-05-01-38-45.bpo-46262.MhiLWP.rst new file mode 100644 index 00000000000000..412be215b37fc4 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2022-01-05-01-38-45.bpo-46262.MhiLWP.rst @@ -0,0 +1 @@ +Cover `ValueError` path in :meth:`enum.Flag._missing_`. From dd8b6cb69dd8afdeba4312deb48443a6b6b86c08 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Wed, 5 Jan 2022 01:41:12 +0300 Subject: [PATCH 2/3] Update 2022-01-05-01-38-45.bpo-46262.MhiLWP.rst --- Misc/NEWS.d/next/Tests/2022-01-05-01-38-45.bpo-46262.MhiLWP.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2022-01-05-01-38-45.bpo-46262.MhiLWP.rst b/Misc/NEWS.d/next/Tests/2022-01-05-01-38-45.bpo-46262.MhiLWP.rst index 412be215b37fc4..53a35b751d80e3 100644 --- a/Misc/NEWS.d/next/Tests/2022-01-05-01-38-45.bpo-46262.MhiLWP.rst +++ b/Misc/NEWS.d/next/Tests/2022-01-05-01-38-45.bpo-46262.MhiLWP.rst @@ -1 +1 @@ -Cover `ValueError` path in :meth:`enum.Flag._missing_`. +Cover ``ValueError`` path in :meth:`enum.Flag._missing_`. From 5daef2c29a1b3d1fd689377a95480aefc609911d Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Tue, 4 Jan 2022 14:50:29 -0800 Subject: [PATCH 3/3] Update Misc/NEWS.d/next/Tests/2022-01-05-01-38-45.bpo-46262.MhiLWP.rst Co-authored-by: Alex Waygood --- Misc/NEWS.d/next/Tests/2022-01-05-01-38-45.bpo-46262.MhiLWP.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2022-01-05-01-38-45.bpo-46262.MhiLWP.rst b/Misc/NEWS.d/next/Tests/2022-01-05-01-38-45.bpo-46262.MhiLWP.rst index 53a35b751d80e3..456d1359e47327 100644 --- a/Misc/NEWS.d/next/Tests/2022-01-05-01-38-45.bpo-46262.MhiLWP.rst +++ b/Misc/NEWS.d/next/Tests/2022-01-05-01-38-45.bpo-46262.MhiLWP.rst @@ -1 +1 @@ -Cover ``ValueError`` path in :meth:`enum.Flag._missing_`. +Cover ``ValueError`` path in tests for :meth:`enum.Flag._missing_`.