@@ -36,80 +36,74 @@ def __getattr__(self, name):
3636class TestCLIGetArgs :
3737 # get_args
3838
39- @patch (
40- "argparse.ArgumentParser.parse_args" ,
41- return_value = ArgsMock (
42- commit_message = "commit message" ,
43- file = None ,
44- hash = None ,
45- from_hash = None ,
46- quiet = None ,
47- ),
48- )
39+ @patch ("sys.argv" , ["prog" , "commit message" ])
4940 def test__get_args__with_commit_message (self , * _ ):
5041 args = get_args ()
5142 assert args .commit_message == "commit message"
52- assert args .file is None
53- assert args .hash is None
54- assert args .from_hash is None
55- assert args .quiet is None
5643
57- @patch (
58- "argparse.ArgumentParser.parse_args" ,
59- return_value = ArgsMock (file = "path/to/file.txt" ),
60- )
44+ @patch ("sys.argv" , ["prog" ])
45+ def test__get_args__without_commit_message (self , * _ ):
46+ with pytest .raises (SystemExit ) as ex :
47+ get_args ()
48+ assert ex .value .code == 2
49+
50+ @patch ("sys.argv" , ["prog" , "--file" , "path/to/file.txt" ])
6151 def test__get_args__with_file (self , * _ ):
6252 args = get_args ()
6353 assert args .file == "path/to/file.txt"
6454
65- @patch (
66- "argparse.ArgumentParser.parse_args" ,
67- return_value = ArgsMock (hash = "commit_hash" , file = None ),
68- )
55+ @patch ("sys.argv" , ["prog" , "--hash" , "commit_hash" ])
6956 def test__get_args__with_hash (self , * _ ):
7057 args = get_args ()
7158 assert args .hash == "commit_hash"
72- assert args .file is None
7359
74- @patch (
75- "argparse.ArgumentParser.parse_args" ,
76- return_value = ArgsMock (from_hash = "from_commit_hash" , file = None , hash = None ),
77- )
60+ @patch ("sys.argv" , ["prog" , "--from-hash" , "from_commit_hash" ])
7861 def test__get_args__with_from_hash (self , * _ ):
7962 args = get_args ()
8063 assert args .from_hash == "from_commit_hash"
81- assert args .file is None
82- assert args .hash is None
64+ assert args .to_hash == "HEAD"
65+
66+ @patch ("sys.argv" , ["prog" , "--to-hash" , "to_commit_hash" ])
67+ def test__get_args__with_to_hash_without_from_hash (self , * _ ):
68+ with pytest .raises (SystemExit ) as ex :
69+ get_args ()
70+ assert ex .value .code == 2
8371
8472 @patch (
85- "argparse.ArgumentParser.parse_args" ,
86- return_value = ArgsMock (
87- from_hash = "from_commit_hash" , to_hash = "to_commit_hash" , file = None , hash = None
88- ),
73+ "sys.argv" ,
74+ ["prog" , "--from-hash" , "from_commit_hash" , "--to-hash" , "to_commit_hash" ],
8975 )
9076 def test__get_args__with_to_hash (self , * _ ):
9177 args = get_args ()
9278 assert args .from_hash == "from_commit_hash"
9379 assert args .to_hash == "to_commit_hash"
94- assert args .file is None
95- assert args .hash is None
9680
97- @patch (
98- "argparse.ArgumentParser.parse_args" ,
99- return_value = ArgsMock (skip_detail = True ),
100- )
81+ @patch ("sys.argv" , ["prog" , "--skip-detail" , "commit_msg" ])
10182 def test__get_args__with_skip_detail (self , * _ ):
10283 args = get_args ()
10384 assert args .skip_detail is True
10485
105- @patch (
106- "argparse.ArgumentParser.parse_args" ,
107- return_value = ArgsMock (hide_input = True ),
108- )
86+ @patch ("sys.argv" , ["prog" , "--hide-input" , "commit_msg" ])
10987 def test__get_args__with_hide_input (self , * _ ):
11088 args = get_args ()
11189 assert args .hide_input is True
11290
91+ @patch ("sys.argv" , ["prog" , "--verbose" , "commit_msg" ])
92+ def test__get_args__with_verbose (self , * _ ):
93+ args = get_args ()
94+ assert args .verbose is True
95+
96+ @patch ("sys.argv" , ["prog" , "--quiet" , "commit_msg" ])
97+ def test__get_args__with_quiet (self , * _ ):
98+ args = get_args ()
99+ assert args .quiet is True
100+
101+ @patch ("sys.argv" , ["prog" , "--quiet" , "--verbose" , "commit_msg" ])
102+ def test__get_args___fails_with_quiet_and_verbose (self , * _ ):
103+ with pytest .raises (SystemExit ) as ex :
104+ get_args ()
105+ assert ex .value .code == 2
106+
113107
114108@patch ("commitlint.console.success" )
115109@patch ("commitlint.console.error" )
0 commit comments