Skip to content
Prev Previous commit
Next Next commit
Add standalone function for uuid tests
  • Loading branch information
LamentXU123 authored Jul 11, 2025
commit 50996af2e3903649e461a1b433584cedc41297a6
76 changes: 23 additions & 53 deletions Lib/test/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,20 @@

class TestUUIDCli(BaseTestUUID, unittest.TestCase):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need all CAPS on term CLI?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just check how other classes testing CLIs are named.

Comment thread
picnixz marked this conversation as resolved.
Outdated
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):
Expand Down Expand Up @@ -1217,61 +1231,17 @@
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):

Check failure on line 1235 in Lib/test/test_uuid.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F811)

Lib/test/test_uuid.py:1235:9: F811 Redefinition of unused `test_uuid1` from line 1157
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):

Check failure on line 1239 in Lib/test/test_uuid.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F811)

Lib/test/test_uuid.py:1239:9: F811 Redefinition of unused `test_uuid1` from line 1235
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):

Check failure on line 1243 in Lib/test/test_uuid.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F811)

Lib/test/test_uuid.py:1243:9: F811 Redefinition of unused `test_uuid1` from line 1239
self.do_test_standalone_uuid(8)
Comment thread
LamentXU123 marked this conversation as resolved.


class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase):
Expand Down
Loading