Skip to content

Commit 50996af

Browse files
authored
Add standalone function for uuid tests
1 parent 5d29f9e commit 50996af

File tree

1 file changed

+23
-53
lines changed

1 file changed

+23
-53
lines changed

Lib/test/test_uuid.py

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,20 @@ def test_uuid_weakref(self):
11431143

11441144
class TestUUIDCli(BaseTestUUID, unittest.TestCase):
11451145
uuid = py_uuid
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_uuid1(self):
1158+
self.do_test_standalone_uuid(1)
1159+
11461160
@mock.patch.object(sys, "argv", ["", "-u", "uuid3", "-n", "@dns"])
11471161
@mock.patch('sys.stderr', new_callable=io.StringIO)
11481162
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):
12171231
self.assertEqual(output, str(uuid_output))
12181232
self.assertEqual(uuid_output.version, 5)
12191233

1220-
@mock.patch.object(sys, "argv",
1221-
["", "-u", "uuid1"])
1222-
def test_cli_uuid1(self):
1223-
stdout = io.StringIO()
1224-
with contextlib.redirect_stdout(stdout):
1225-
self.uuid.main()
1226-
1227-
output = stdout.getvalue().strip()
1228-
uuid_output = self.uuid.UUID(output)
1229-
1230-
# Output should be in the form of uuid1
1231-
self.assertEqual(output, str(uuid_output))
1232-
self.assertEqual(uuid_output.version, 1)
1233-
1234-
@mock.patch.object(sys, "argv",
1235-
["", "-u", "uuid6"])
1236-
def test_cli_uuid6(self):
1237-
stdout = io.StringIO()
1238-
with contextlib.redirect_stdout(stdout):
1239-
self.uuid.main()
1240-
1241-
output = stdout.getvalue().strip()
1242-
uuid_output = self.uuid.UUID(output)
1243-
1244-
# Output should be in the form of uuid6
1245-
self.assertEqual(output, str(uuid_output))
1246-
self.assertEqual(uuid_output.version, 6)
1247-
1248-
@mock.patch.object(sys, "argv",
1249-
["", "-u", "uuid7"])
1250-
def test_cli_uuid7(self):
1251-
stdout = io.StringIO()
1252-
with contextlib.redirect_stdout(stdout):
1253-
self.uuid.main()
1254-
1255-
output = stdout.getvalue().strip()
1256-
uuid_output = self.uuid.UUID(output)
1257-
1258-
# Output should be in the form of uuid7
1259-
self.assertEqual(output, str(uuid_output))
1260-
self.assertEqual(uuid_output.version, 7)
1261-
1262-
@mock.patch.object(sys, "argv",
1263-
["", "-u", "uuid8"])
1264-
def test_cli_uuid8(self):
1265-
stdout = io.StringIO()
1266-
with contextlib.redirect_stdout(stdout):
1267-
self.uuid.main()
1234+
@mock.patch.object(sys, "argv", ["", "-u", "uuid6"])
1235+
def test_uuid1(self):
1236+
self.do_test_standalone_uuid(6)
12681237

1269-
output = stdout.getvalue().strip()
1270-
uuid_output = self.uuid.UUID(output)
1238+
@mock.patch.object(sys, "argv", ["", "-u", "uuid7"])
1239+
def test_uuid1(self):
1240+
self.do_test_standalone_uuid(7)
12711241

1272-
# Output should be in the form of uuid8
1273-
self.assertEqual(output, str(uuid_output))
1274-
self.assertEqual(uuid_output.version, 8)
1242+
@mock.patch.object(sys, "argv", ["", "-u", "uuid8"])
1243+
def test_uuid1(self):
1244+
self.do_test_standalone_uuid(8)
12751245

12761246

12771247
class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase):

0 commit comments

Comments
 (0)