@@ -1223,6 +1223,29 @@ def test_cli_uuid3_ouputted_with_valid_namespace_and_name(self):
12231223 self .assertEqual (output , str (uuid_output ))
12241224 self .assertEqual (uuid_output .version , 3 )
12251225
1226+ @mock .patch .object (sys , "argv" , ["" , "-u" , "uuid3" , "-n" , "any UUID" , "-N" , "python.org" ])
1227+ @mock .patch ('sys.stderr' , new_callable = io .StringIO )
1228+ def test_cli_uuid3_with_invalid_namespace (self , mock_err ):
1229+ with self .assertRaises (SystemExit ) as cm :
1230+ self .uuid .main ()
1231+ # Check that exception code is the same as argparse.ArgumentParser.error
1232+ self .assertEqual (cm .exception .code , 2 )
1233+ self .assertIn ("error: badly formed hexadecimal UUID string" , mock_err .getvalue ())
1234+
1235+ @mock .patch .object (sys , "argv" ,
1236+ ["" , "-u" , "uuid3" , "-n" , "0d6a16cc-34a7-47d8-b660-214d0ae184d2" , "-N" , "some.user" ])
1237+ def test_cli_uuid3_ouputted_with_user_provided_namespace_and_name (self ):
1238+ stdout = io .StringIO ()
1239+ with contextlib .redirect_stdout (stdout ):
1240+ self .uuid .main ()
1241+
1242+ output = stdout .getvalue ().strip ()
1243+ uuid_output = self .uuid .UUID (output )
1244+
1245+ # Output should be in the form of uuid5
1246+ self .assertEqual (output , str (uuid_output ))
1247+ self .assertEqual (uuid_output .version , 3 )
1248+
12261249 @mock .patch .object (sys , "argv" ,
12271250 ["" , "-u" , "uuid5" , "-n" , "@dns" , "-N" , "python.org" ])
12281251 def test_cli_uuid5_ouputted_with_valid_namespace_and_name (self ):
@@ -1237,6 +1260,29 @@ def test_cli_uuid5_ouputted_with_valid_namespace_and_name(self):
12371260 self .assertEqual (output , str (uuid_output ))
12381261 self .assertEqual (uuid_output .version , 5 )
12391262
1263+ @mock .patch .object (sys , "argv" , ["" , "-u" , "uuid5" , "-n" , "any UUID" , "-N" , "python.org" ])
1264+ @mock .patch ('sys.stderr' , new_callable = io .StringIO )
1265+ def test_cli_uuid5_with_invalid_namespace (self , mock_err ):
1266+ with self .assertRaises (SystemExit ) as cm :
1267+ self .uuid .main ()
1268+ # Check that exception code is the same as argparse.ArgumentParser.error
1269+ self .assertEqual (cm .exception .code , 2 )
1270+ self .assertIn ("error: badly formed hexadecimal UUID string" , mock_err .getvalue ())
1271+
1272+ @mock .patch .object (sys , "argv" ,
1273+ ["" , "-u" , "uuid5" , "-n" , "0d6a16cc-34a7-47d8-b660-214d0ae184d2" , "-N" , "some.user" ])
1274+ def test_cli_uuid5_ouputted_with_user_provided_namespace_and_name (self ):
1275+ stdout = io .StringIO ()
1276+ with contextlib .redirect_stdout (stdout ):
1277+ self .uuid .main ()
1278+
1279+ output = stdout .getvalue ().strip ()
1280+ uuid_output = self .uuid .UUID (output )
1281+
1282+ # Output should be in the form of uuid5
1283+ self .assertEqual (output , str (uuid_output ))
1284+ self .assertEqual (uuid_output .version , 5 )
1285+
12401286 @mock .patch .object (sys , "argv" , ["" , "-u" , "uuid6" ])
12411287 def test_cli_uuid6 (self ):
12421288 self .do_test_standalone_uuid (6 )
0 commit comments