@@ -1182,6 +1182,47 @@ def test_cli_name_required_for_uuid3(self, mock_err):
11821182 self .assertEqual (cm .exception .code , 2 )
11831183 self .assertIn ("error: Incorrect number of arguments" , mock_err .getvalue ())
11841184
1185+ @mock .patch .object (sys , "argv" ,
1186+ ["" , "-u" , "uuid3" , "-n" , "@dns" , "-N" , "python.org" ])
1187+ def test_cli_uuid3_outputted_with_valid_namespace_and_name (self ):
1188+ stdout = io .StringIO ()
1189+ with contextlib .redirect_stdout (stdout ):
1190+ self .uuid .main ()
1191+
1192+ output = stdout .getvalue ().strip ()
1193+ uuid_output = self .uuid .UUID (output )
1194+
1195+ # Output should be in the form of uuid3
1196+ self .assertEqual (output , str (uuid_output ))
1197+ self .assertEqual (uuid_output .version , 3 )
1198+
1199+ @mock .patch .object (sys , "argv" ,
1200+ ["" , "-u" , "uuid3" , "-n" ,
1201+ "0d6a16cc-34a7-47d8-b660-214d0ae184d2" ,
1202+ "-N" , "some.user" ])
1203+ def test_cli_uuid3_outputted_with_custom_namespace_and_name (self ):
1204+ stdout = io .StringIO ()
1205+ with contextlib .redirect_stdout (stdout ):
1206+ self .uuid .main ()
1207+
1208+ output = stdout .getvalue ().strip ()
1209+ uuid_output = self .uuid .UUID (output )
1210+
1211+ # Output should be in the form of uuid3
1212+ self .assertEqual (output , str (uuid_output ))
1213+ self .assertEqual (uuid_output .version , 3 )
1214+
1215+ @mock .patch .object (sys , "argv" ,
1216+ ["" , "-u" , "uuid3" , "-n" , "any UUID" , "-N" , "python.org" ])
1217+ @mock .patch ('sys.stderr' , new_callable = io .StringIO )
1218+ def test_cli_uuid3_with_invalid_namespace (self , mock_err ):
1219+ with self .assertRaises (SystemExit ) as cm :
1220+ self .uuid .main ()
1221+ # Check that exception code is the same as argparse.ArgumentParser.error
1222+ self .assertEqual (cm .exception .code , 2 )
1223+ self .assertIn ("error: badly formed hexadecimal UUID string" ,
1224+ mock_err .getvalue ())
1225+
11851226 @mock .patch .object (sys , "argv" , ["" ])
11861227 def test_cli_uuid4_outputted_with_no_args (self ):
11871228 stdout = io .StringIO ()
@@ -1210,8 +1251,8 @@ def test_cli_uuid4_outputted_with_count(self):
12101251 self .assertEqual (uuid_output .version , 4 )
12111252
12121253 @mock .patch .object (sys , "argv" ,
1213- ["" , "-u" , "uuid3 " , "-n" , "@dns" , "-N" , "python.org" ])
1214- def test_cli_uuid3_ouputted_with_valid_namespace_and_name (self ):
1254+ ["" , "-u" , "uuid5 " , "-n" , "@dns" , "-N" , "python.org" ])
1255+ def test_cli_uuid5_outputted_with_valid_namespace_and_name (self ):
12151256 stdout = io .StringIO ()
12161257 with contextlib .redirect_stdout (stdout ):
12171258 self .uuid .main ()
@@ -1221,11 +1262,13 @@ def test_cli_uuid3_ouputted_with_valid_namespace_and_name(self):
12211262
12221263 # Output should be in the form of uuid5
12231264 self .assertEqual (output , str (uuid_output ))
1224- self .assertEqual (uuid_output .version , 3 )
1265+ self .assertEqual (uuid_output .version , 5 )
12251266
12261267 @mock .patch .object (sys , "argv" ,
1227- ["" , "-u" , "uuid5" , "-n" , "@dns" , "-N" , "python.org" ])
1228- def test_cli_uuid5_ouputted_with_valid_namespace_and_name (self ):
1268+ ["" , "-u" , "uuid5" , "-n" ,
1269+ "0d6a16cc-34a7-47d8-b660-214d0ae184d2" ,
1270+ "-N" , "some.user" ])
1271+ def test_cli_uuid5_ouputted_with_custom_namespace_and_name (self ):
12291272 stdout = io .StringIO ()
12301273 with contextlib .redirect_stdout (stdout ):
12311274 self .uuid .main ()
@@ -1237,6 +1280,17 @@ def test_cli_uuid5_ouputted_with_valid_namespace_and_name(self):
12371280 self .assertEqual (output , str (uuid_output ))
12381281 self .assertEqual (uuid_output .version , 5 )
12391282
1283+ @mock .patch .object (sys , "argv" ,
1284+ ["" , "-u" , "uuid5" , "-n" , "any UUID" , "-N" , "python.org" ])
1285+ @mock .patch ('sys.stderr' , new_callable = io .StringIO )
1286+ def test_cli_uuid5_with_invalid_namespace (self , mock_err ):
1287+ with self .assertRaises (SystemExit ) as cm :
1288+ self .uuid .main ()
1289+ # Check that exception code is the same as argparse.ArgumentParser.error
1290+ self .assertEqual (cm .exception .code , 2 )
1291+ self .assertIn ("error: badly formed hexadecimal UUID string" ,
1292+ mock_err .getvalue ())
1293+
12401294 @mock .patch .object (sys , "argv" , ["" , "-u" , "uuid6" ])
12411295 def test_cli_uuid6 (self ):
12421296 self .do_test_standalone_uuid (6 )
0 commit comments