From 609ab56fbabcfabd4b1e1368f1a104b309a07c50 Mon Sep 17 00:00:00 2001 From: Weilin Du <108666168+LamentXU123@users.noreply.github.com> Date: Fri, 11 Jul 2025 23:28:03 +0800 Subject: [PATCH 01/13] Update test_uuid.py --- Lib/test/test_uuid.py | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index 7ddacf07a2c789..e9ba06bb9a56de 100755 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -1214,6 +1214,64 @@ def test_cli_uuid5_ouputted_with_valid_namespace_and_name(self): self.assertEqual(output, str(uuid_output)) self.assertEqual(uuid_output.version, 5) + @mock.patch.object(sys, "argv", + ["", "-u", "uuid1"]) + def test_cli_uuid1(self): + stdout = io.StringIO() + with contextlib.redirect_stdout(stdout): + self.uuid.main() + + output = stdout.getvalue().strip() + uuid_output = self.uuid.UUID(output) + + # Output should be in the form of uuid1 + self.assertEqual(output, str(uuid_output)) + self.assertEqual(uuid_output.version, 1) + + + @mock.patch.object(sys, "argv", + ["", "-u", "uuid6"]) + def test_cli_uuid6(self): + stdout = io.StringIO() + with contextlib.redirect_stdout(stdout): + self.uuid.main() + + output = stdout.getvalue().strip() + uuid_output = self.uuid.UUID(output) + + # Output should be in the form of uuid6 + self.assertEqual(output, str(uuid_output)) + self.assertEqual(uuid_output.version, 6) + + + @mock.patch.object(sys, "argv", + ["", "-u", "uuid7"]) + def test_cli_uuid7(self): + stdout = io.StringIO() + with contextlib.redirect_stdout(stdout): + self.uuid.main() + + output = stdout.getvalue().strip() + uuid_output = self.uuid.UUID(output) + + # Output should be in the form of uuid7 + self.assertEqual(output, str(uuid_output)) + self.assertEqual(uuid_output.version, 7) + + + @mock.patch.object(sys, "argv", + ["", "-u", "uuid8"]) + def test_cli_uuid8(self): + stdout = io.StringIO() + with contextlib.redirect_stdout(stdout): + self.uuid.main() + + output = stdout.getvalue().strip() + uuid_output = self.uuid.UUID(output) + + # Output should be in the form of uuid8 + self.assertEqual(output, str(uuid_output)) + self.assertEqual(uuid_output.version, 8) class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase): uuid = py_uuid From adfcc244114851bf66cf4288c37bffdd53b8016f Mon Sep 17 00:00:00 2001 From: Weilin Du <108666168+LamentXU123@users.noreply.github.com> Date: Fri, 11 Jul 2025 23:42:46 +0800 Subject: [PATCH 02/13] Add a blank line --- Lib/test/test_uuid.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index e9ba06bb9a56de..47d60720df0f8a 100755 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -1273,6 +1273,7 @@ def test_cli_uuid8(self): self.assertEqual(output, str(uuid_output)) self.assertEqual(uuid_output.version, 8) + class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase): uuid = py_uuid From 4e36078b2414bcb0c184eae0869a05c776c3746a Mon Sep 17 00:00:00 2001 From: Weilin Du <108666168+LamentXU123@users.noreply.github.com> Date: Sat, 12 Jul 2025 00:10:10 +0800 Subject: [PATCH 03/13] add seperate class for cli tests --- Lib/test/test_uuid.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index 47d60720df0f8a..4a72f70e526004 100755 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -1140,6 +1140,9 @@ def test_uuid_weakref(self): weak = weakref.ref(strong) self.assertIs(strong, weak()) + +class TestUUIDCli(BaseTestUUID, unittest.TestCase): + uuid = py_uuid @mock.patch.object(sys, "argv", ["", "-u", "uuid3", "-n", "@dns"]) @mock.patch('sys.stderr', new_callable=io.StringIO) def test_cli_namespace_required_for_uuid3(self, mock_err): @@ -1228,7 +1231,6 @@ def test_cli_uuid1(self): self.assertEqual(output, str(uuid_output)) self.assertEqual(uuid_output.version, 1) - @mock.patch.object(sys, "argv", ["", "-u", "uuid6"]) def test_cli_uuid6(self): @@ -1243,7 +1245,6 @@ def test_cli_uuid6(self): self.assertEqual(output, str(uuid_output)) self.assertEqual(uuid_output.version, 6) - @mock.patch.object(sys, "argv", ["", "-u", "uuid7"]) def test_cli_uuid7(self): @@ -1258,7 +1259,6 @@ def test_cli_uuid7(self): self.assertEqual(output, str(uuid_output)) self.assertEqual(uuid_output.version, 7) - @mock.patch.object(sys, "argv", ["", "-u", "uuid8"]) def test_cli_uuid8(self): @@ -1273,7 +1273,6 @@ def test_cli_uuid8(self): self.assertEqual(output, str(uuid_output)) self.assertEqual(uuid_output.version, 8) - class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase): uuid = py_uuid From 5d29f9e7b0828d524d7219d3efa5bab2ac659790 Mon Sep 17 00:00:00 2001 From: Weilin Du <108666168+LamentXU123@users.noreply.github.com> Date: Sat, 12 Jul 2025 00:11:04 +0800 Subject: [PATCH 04/13] add blank line --- Lib/test/test_uuid.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index 4a72f70e526004..befc0bd7128702 100755 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -1273,6 +1273,7 @@ def test_cli_uuid8(self): self.assertEqual(output, str(uuid_output)) self.assertEqual(uuid_output.version, 8) + class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase): uuid = py_uuid From 50996af2e3903649e461a1b433584cedc41297a6 Mon Sep 17 00:00:00 2001 From: Weilin Du <108666168+LamentXU123@users.noreply.github.com> Date: Sat, 12 Jul 2025 00:21:03 +0800 Subject: [PATCH 05/13] Add standalone function for uuid tests --- Lib/test/test_uuid.py | 76 +++++++++++++------------------------------ 1 file changed, 23 insertions(+), 53 deletions(-) diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index befc0bd7128702..d04349dd4e4723 100755 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -1143,6 +1143,20 @@ def test_uuid_weakref(self): class TestUUIDCli(BaseTestUUID, unittest.TestCase): uuid = py_uuid + + def do_test_standalone_uuid(self, version): + stdout = io.StringIO() + with contextlib.redirect_stdout(stdout): + self.uuid.main() + output = stdout.getvalue().strip() + u = self.uuid.UUID(output) + self.assertEqual(output, str(u)) + self.assertEqual(u.version, version) + + @mock.patch.object(sys, "argv", ["", "-u", "uuid1"]) + def test_uuid1(self): + self.do_test_standalone_uuid(1) + @mock.patch.object(sys, "argv", ["", "-u", "uuid3", "-n", "@dns"]) @mock.patch('sys.stderr', new_callable=io.StringIO) def test_cli_namespace_required_for_uuid3(self, mock_err): @@ -1217,61 +1231,17 @@ def test_cli_uuid5_ouputted_with_valid_namespace_and_name(self): self.assertEqual(output, str(uuid_output)) self.assertEqual(uuid_output.version, 5) - @mock.patch.object(sys, "argv", - ["", "-u", "uuid1"]) - def test_cli_uuid1(self): - stdout = io.StringIO() - with contextlib.redirect_stdout(stdout): - self.uuid.main() - - output = stdout.getvalue().strip() - uuid_output = self.uuid.UUID(output) - - # Output should be in the form of uuid1 - self.assertEqual(output, str(uuid_output)) - self.assertEqual(uuid_output.version, 1) - - @mock.patch.object(sys, "argv", - ["", "-u", "uuid6"]) - def test_cli_uuid6(self): - stdout = io.StringIO() - with contextlib.redirect_stdout(stdout): - self.uuid.main() - - output = stdout.getvalue().strip() - uuid_output = self.uuid.UUID(output) - - # Output should be in the form of uuid6 - self.assertEqual(output, str(uuid_output)) - self.assertEqual(uuid_output.version, 6) - - @mock.patch.object(sys, "argv", - ["", "-u", "uuid7"]) - def test_cli_uuid7(self): - stdout = io.StringIO() - with contextlib.redirect_stdout(stdout): - self.uuid.main() - - output = stdout.getvalue().strip() - uuid_output = self.uuid.UUID(output) - - # Output should be in the form of uuid7 - self.assertEqual(output, str(uuid_output)) - self.assertEqual(uuid_output.version, 7) - - @mock.patch.object(sys, "argv", - ["", "-u", "uuid8"]) - def test_cli_uuid8(self): - stdout = io.StringIO() - with contextlib.redirect_stdout(stdout): - self.uuid.main() + @mock.patch.object(sys, "argv", ["", "-u", "uuid6"]) + def test_uuid1(self): + self.do_test_standalone_uuid(6) - output = stdout.getvalue().strip() - uuid_output = self.uuid.UUID(output) + @mock.patch.object(sys, "argv", ["", "-u", "uuid7"]) + def test_uuid1(self): + self.do_test_standalone_uuid(7) - # Output should be in the form of uuid8 - self.assertEqual(output, str(uuid_output)) - self.assertEqual(uuid_output.version, 8) + @mock.patch.object(sys, "argv", ["", "-u", "uuid8"]) + def test_uuid1(self): + self.do_test_standalone_uuid(8) class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase): From 73f8de9accfa7d709760315e88e5103cd39c9fc9 Mon Sep 17 00:00:00 2001 From: Weilin Du <108666168+LamentXU123@users.noreply.github.com> Date: Sat, 12 Jul 2025 00:25:14 +0800 Subject: [PATCH 06/13] Update test_uuid.py --- Lib/test/test_uuid.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index d04349dd4e4723..39f0774bb6cfef 100755 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -1154,7 +1154,7 @@ def do_test_standalone_uuid(self, version): self.assertEqual(u.version, version) @mock.patch.object(sys, "argv", ["", "-u", "uuid1"]) - def test_uuid1(self): + def test_cli_uuid1(self): self.do_test_standalone_uuid(1) @mock.patch.object(sys, "argv", ["", "-u", "uuid3", "-n", "@dns"]) @@ -1232,15 +1232,15 @@ def test_cli_uuid5_ouputted_with_valid_namespace_and_name(self): self.assertEqual(uuid_output.version, 5) @mock.patch.object(sys, "argv", ["", "-u", "uuid6"]) - def test_uuid1(self): + def test_cli_uuid6(self): self.do_test_standalone_uuid(6) @mock.patch.object(sys, "argv", ["", "-u", "uuid7"]) - def test_uuid1(self): + def test_cli_uuid7(self): self.do_test_standalone_uuid(7) @mock.patch.object(sys, "argv", ["", "-u", "uuid8"]) - def test_uuid1(self): + def test_cli_uuid8(self): self.do_test_standalone_uuid(8) From d63e3a7ed24b0e9a256e433862e57d9ca5ca9784 Mon Sep 17 00:00:00 2001 From: Weilin Du <108666168+LamentXU123@users.noreply.github.com> Date: Sat, 12 Jul 2025 00:28:13 +0800 Subject: [PATCH 07/13] Update test_uuid.py --- Lib/test/test_uuid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index 39f0774bb6cfef..eb8ab02eae1eed 100755 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -1141,7 +1141,7 @@ def test_uuid_weakref(self): self.assertIs(strong, weak()) -class TestUUIDCli(BaseTestUUID, unittest.TestCase): +class TestUUIDCli(unittest.TestCase): uuid = py_uuid def do_test_standalone_uuid(self, version): From 0c2b23191542b70ee65c3637781483a829f29eba Mon Sep 17 00:00:00 2001 From: Weilin Du <108666168+LamentXU123@users.noreply.github.com> Date: Sat, 12 Jul 2025 00:30:47 +0800 Subject: [PATCH 08/13] Change class name to TestUUIDCommandLineRunTime --- Lib/test/test_uuid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index eb8ab02eae1eed..c0ac7da4890d0e 100755 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -1141,7 +1141,7 @@ def test_uuid_weakref(self): self.assertIs(strong, weak()) -class TestUUIDCli(unittest.TestCase): +class TestUUIDCommandLineRunTime(unittest.TestCase): uuid = py_uuid def do_test_standalone_uuid(self, version): From 142324a543910df80850f4d77518b43fcd7fdaef Mon Sep 17 00:00:00 2001 From: Weilin Du <108666168+LamentXU123@users.noreply.github.com> Date: Sat, 12 Jul 2025 00:44:35 +0800 Subject: [PATCH 09/13] Make the CLI test a mixin class --- Lib/test/test_uuid.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index c0ac7da4890d0e..cfb1d2fadc4eb3 100755 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -1141,9 +1141,7 @@ def test_uuid_weakref(self): self.assertIs(strong, weak()) -class TestUUIDCommandLineRunTime(unittest.TestCase): - uuid = py_uuid - +class TestUUIDCommandLineRunTimeMixin: def do_test_standalone_uuid(self, version): stdout = io.StringIO() with contextlib.redirect_stdout(stdout): @@ -1244,12 +1242,12 @@ def test_cli_uuid8(self): self.do_test_standalone_uuid(8) -class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase): +class TestUUIDWithoutExtModule(TestUUIDCommandLineRunTimeMixin, BaseTestUUID, unittest.TestCase): uuid = py_uuid @unittest.skipUnless(c_uuid, 'requires the C _uuid module') -class TestUUIDWithExtModule(BaseTestUUID, unittest.TestCase): +class TestUUIDWithExtModule(TestUUIDCommandLineRunTimeMixin, BaseTestUUID, unittest.TestCase): uuid = c_uuid def check_has_stable_libuuid_extractable_node(self): From 98234f342fc86bc11193c87399f015a829440358 Mon Sep 17 00:00:00 2001 From: Weilin Du <108666168+LamentXU123@users.noreply.github.com> Date: Sat, 12 Jul 2025 00:46:45 +0800 Subject: [PATCH 10/13] Change back the class name --- Lib/test/test_uuid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index cfb1d2fadc4eb3..f8d93f615a79d0 100755 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -1141,7 +1141,7 @@ def test_uuid_weakref(self): self.assertIs(strong, weak()) -class TestUUIDCommandLineRunTimeMixin: +class CommandLineRunTime: def do_test_standalone_uuid(self, version): stdout = io.StringIO() with contextlib.redirect_stdout(stdout): From 3e4bf3cc3c9983fe0d1bc8245ccd851652d5bfd0 Mon Sep 17 00:00:00 2001 From: Weilin Du <108666168+LamentXU123@users.noreply.github.com> Date: Sat, 12 Jul 2025 00:47:08 +0800 Subject: [PATCH 11/13] Update test_uuid.py --- Lib/test/test_uuid.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index f8d93f615a79d0..4ab3d4bb9c2c75 100755 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -1242,12 +1242,12 @@ def test_cli_uuid8(self): self.do_test_standalone_uuid(8) -class TestUUIDWithoutExtModule(TestUUIDCommandLineRunTimeMixin, BaseTestUUID, unittest.TestCase): +class TestUUIDWithoutExtModule(CommandLineRunTime, BaseTestUUID, unittest.TestCase): uuid = py_uuid @unittest.skipUnless(c_uuid, 'requires the C _uuid module') -class TestUUIDWithExtModule(TestUUIDCommandLineRunTimeMixin, BaseTestUUID, unittest.TestCase): +class TestUUIDWithExtModule(CommandLineRunTime, BaseTestUUID, unittest.TestCase): uuid = c_uuid def check_has_stable_libuuid_extractable_node(self): From a873bf8f6253d7e9cdf3d7ae1244ad8a516397be Mon Sep 17 00:00:00 2001 From: Weilin Du <108666168+LamentXU123@users.noreply.github.com> Date: Sat, 12 Jul 2025 00:58:31 +0800 Subject: [PATCH 12/13] Update Lib/test/test_uuid.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Lib/test/test_uuid.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index 4ab3d4bb9c2c75..66efce259fe7bd 100755 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -1141,7 +1141,9 @@ def test_uuid_weakref(self): self.assertIs(strong, weak()) -class CommandLineRunTime: +class CommandLineTestCases: + uuid = None # to be defined in subclasses + def do_test_standalone_uuid(self, version): stdout = io.StringIO() with contextlib.redirect_stdout(stdout): From a8d40ed9b4616f6ab5a14f9c5883d4c440228370 Mon Sep 17 00:00:00 2001 From: Weilin Du <108666168+LamentXU123@users.noreply.github.com> Date: Sat, 12 Jul 2025 01:04:48 +0800 Subject: [PATCH 13/13] Update test_uuid.py --- Lib/test/test_uuid.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index 66efce259fe7bd..0e1a723ce3a151 100755 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -1244,12 +1244,12 @@ def test_cli_uuid8(self): self.do_test_standalone_uuid(8) -class TestUUIDWithoutExtModule(CommandLineRunTime, BaseTestUUID, unittest.TestCase): +class TestUUIDWithoutExtModule(CommandLineTestCases, BaseTestUUID, unittest.TestCase): uuid = py_uuid @unittest.skipUnless(c_uuid, 'requires the C _uuid module') -class TestUUIDWithExtModule(CommandLineRunTime, BaseTestUUID, unittest.TestCase): +class TestUUIDWithExtModule(CommandLineTestCases, BaseTestUUID, unittest.TestCase): uuid = c_uuid def check_has_stable_libuuid_extractable_node(self):