Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[3.14] gh-89083: Add CLI tests for UUIDv{6,7,8} (GH-136548) #136576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions Lib/test/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,23 @@ def test_uuid_weakref(self):
weak = weakref.ref(strong)
self.assertIs(strong, weak())


class CommandLineTestCases:
uuid = None # to be defined in subclasses

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_cli_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):
Expand Down Expand Up @@ -1214,13 +1231,25 @@ 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", "uuid6"])
def test_cli_uuid6(self):
self.do_test_standalone_uuid(6)

@mock.patch.object(sys, "argv", ["", "-u", "uuid7"])
def test_cli_uuid7(self):
self.do_test_standalone_uuid(7)

@mock.patch.object(sys, "argv", ["", "-u", "uuid8"])
def test_cli_uuid8(self):
self.do_test_standalone_uuid(8)


class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase):
class TestUUIDWithoutExtModule(CommandLineTestCases, BaseTestUUID, unittest.TestCase):
uuid = py_uuid


@unittest.skipUnless(c_uuid, 'requires the C _uuid module')
class TestUUIDWithExtModule(BaseTestUUID, unittest.TestCase):
class TestUUIDWithExtModule(CommandLineTestCases, BaseTestUUID, unittest.TestCase):
uuid = c_uuid

def check_has_stable_libuuid_extractable_node(self):
Expand Down
Loading