Skip to content

Commit c564847

Browse files
LamentXU123picnixz
andauthored
gh-89083: Add CLI tests for UUIDv{6,7,8} (#136548)
Co-authored-by: Bénédikt Tran <[email protected]>
1 parent 2301cdb commit c564847

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

Lib/test/test_uuid.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,23 @@ def test_uuid_weakref(self):
11401140
weak = weakref.ref(strong)
11411141
self.assertIs(strong, weak())
11421142

1143+
1144+
class CommandLineTestCases:
1145+
uuid = None # to be defined in subclasses
1146+
1147+
def do_test_standalone_uuid(self, version):
1148+
stdout = io.StringIO()
1149+
with contextlib.redirect_stdout(stdout):
1150+
self.uuid.main()
1151+
output = stdout.getvalue().strip()
1152+
u = self.uuid.UUID(output)
1153+
self.assertEqual(output, str(u))
1154+
self.assertEqual(u.version, version)
1155+
1156+
@mock.patch.object(sys, "argv", ["", "-u", "uuid1"])
1157+
def test_cli_uuid1(self):
1158+
self.do_test_standalone_uuid(1)
1159+
11431160
@mock.patch.object(sys, "argv", ["", "-u", "uuid3", "-n", "@dns"])
11441161
@mock.patch('sys.stderr', new_callable=io.StringIO)
11451162
def test_cli_namespace_required_for_uuid3(self, mock_err):
@@ -1214,13 +1231,25 @@ def test_cli_uuid5_ouputted_with_valid_namespace_and_name(self):
12141231
self.assertEqual(output, str(uuid_output))
12151232
self.assertEqual(uuid_output.version, 5)
12161233

1234+
@mock.patch.object(sys, "argv", ["", "-u", "uuid6"])
1235+
def test_cli_uuid6(self):
1236+
self.do_test_standalone_uuid(6)
1237+
1238+
@mock.patch.object(sys, "argv", ["", "-u", "uuid7"])
1239+
def test_cli_uuid7(self):
1240+
self.do_test_standalone_uuid(7)
1241+
1242+
@mock.patch.object(sys, "argv", ["", "-u", "uuid8"])
1243+
def test_cli_uuid8(self):
1244+
self.do_test_standalone_uuid(8)
1245+
12171246

1218-
class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase):
1247+
class TestUUIDWithoutExtModule(CommandLineTestCases, BaseTestUUID, unittest.TestCase):
12191248
uuid = py_uuid
12201249

12211250

12221251
@unittest.skipUnless(c_uuid, 'requires the C _uuid module')
1223-
class TestUUIDWithExtModule(BaseTestUUID, unittest.TestCase):
1252+
class TestUUIDWithExtModule(CommandLineTestCases, BaseTestUUID, unittest.TestCase):
12241253
uuid = c_uuid
12251254

12261255
def check_has_stable_libuuid_extractable_node(self):

0 commit comments

Comments
 (0)