Skip to content
59 changes: 59 additions & 0 deletions Lib/test/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,9 @@ def test_uuid_weakref(self):
weak = weakref.ref(strong)
self.assertIs(strong, weak())


class TestUUIDCli(BaseTestUUID, unittest.TestCase):
Copy link
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
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.

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):
Expand Down Expand Up @@ -1214,6 +1217,62 @@ 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
Expand Down
Loading