55import os
66import unittest
77from unittest .mock import patch
8- from code_counter .core .argspaser import CodeCounterArgsParser
8+ from code_counter .core .args import CodeCounterArgs
99from code_counter .conf .config import Config
1010from code_counter .__main__ import main
1111
@@ -27,23 +27,23 @@ def test_print_help(self):
2727 options = ('python' , app_path , '--help' )
2828 sys .argv [1 :] = options [2 :]
2929 try :
30- CodeCounterArgsParser ()
30+ CodeCounterArgs ()
3131 except SystemExit :
3232 pass
3333
3434 def test_print_search_help (self ):
3535 options = ('python' , app_path , 'search' , '--help' )
3636 sys .argv [1 :] = options [2 :]
3737 try :
38- CodeCounterArgsParser ()
38+ CodeCounterArgs ()
3939 except SystemExit :
4040 pass
4141
4242 def test_print_config_help (self ):
4343 options = ('python' , app_path , 'config' , '--help' )
4444 sys .argv [1 :] = options [2 :]
4545 try :
46- CodeCounterArgsParser ()
46+ CodeCounterArgs ()
4747 except SystemExit :
4848 pass
4949
@@ -58,11 +58,11 @@ def test_search_args(self):
5858 '--comment=//,#,/*' ,
5959 '--ignore=.vscode,.idea' ]
6060 sys .argv [1 :] = options [2 :]
61- parser = CodeCounterArgsParser ()
62- self .assertTrue ( 'config' not in parser . args , '"config" is in the "args"' )
63- self .assertTrue ('search' in parser . args , '"search" is not in the "args"' )
64- search_args = parser . args [ ' search' ]
65- self .assertEqual (search_args .path , '../code_counter/' , "search path parsed error." )
61+ args = CodeCounterArgs ()
62+ self .assertFalse ( args . has_config_args () , '"config" is in the "args"' )
63+ self .assertTrue (args . has_search_args () , '"search" is not in the "args"' )
64+ search_args = args . search ()
65+ self .assertEqual (search_args .input_path , [ '../code_counter/' ] , "search path parsed error." )
6666 self .assertTrue (search_args .verbose , '-v,--verbose flag parsed error.' )
6767 self .assertTrue (search_args .graph , '-g,--graph flag parsed error.' )
6868 self .assertEqual (search_args .output_path , 'output.txt' , "output path parsed error." )
@@ -82,10 +82,10 @@ def test_config_args(self):
8282 '--ignore-reset=target' ,
8383 '--restore' ]
8484 sys .argv [1 :] = options [2 :]
85- parser = CodeCounterArgsParser ()
86- self .assertTrue ('config' in parser . args , '"config" is not in the "args"' )
87- self .assertTrue ( 'search' not in parser . args , '"search" is in the "args"' )
88- config_args = parser . args [ ' config' ]
85+ args = CodeCounterArgs ()
86+ self .assertTrue (args . has_config_args () , '"config" is not in the "args"' )
87+ self .assertFalse ( args . has_search_args () , '"search" is in the "args"' )
88+ config_args = args . config ()
8989 self .assertTrue (config_args .show_list , '--list flag parsed error.' )
9090 self .assertEqual (config_args .suffix_add , ['lisp' ], "suffix_add flag and values parsed error." )
9191 self .assertEqual (config_args .suffix_reset , ['clj' ], "suffix_reset flag and values parsed error." )
@@ -103,11 +103,12 @@ def test_Config_restore(self, mock_input):
103103 'config' ,
104104 '--restore' ]
105105 sys .argv [1 :] = options [2 :]
106- parser = CodeCounterArgsParser ()
107- args = parser .args
106+
107+ args = CodeCounterArgs ()
108+ self .assertTrue (args .has_config_args ())
109+
108110 config = Config ()
109- self .assertTrue ('config' in args )
110- config .invoke (args ['config' ])
111+ config .invoke (args .config ())
111112
112113 self .assertEqual (config .suffix , self .default_suffix , "the suffix doesn't equal" )
113114 self .assertEqual (config .comment , self .default_comment , "the comment doesn't equal" )
@@ -126,10 +127,10 @@ def test_Config_reset1(self, mock_input):
126127 '--comment-reset=//,#,/**' ,
127128 '--ignore-reset=target,build,node_modules,__pycache__' ]
128129 sys .argv [1 :] = options [2 :]
129- parser = CodeCounterArgsParser ()
130- args = parser . args
131- self .assertTrue ('config' in args )
132- config .invoke (args [ ' config' ] )
130+
131+ args = CodeCounterArgs ()
132+ self .assertTrue (args . has_config_args () )
133+ config .invoke (args . config () )
133134
134135 suffix = ['java' , 'cpp' , 'go' , 'js' , 'py' ]
135136 comment = ['//' , '#' , '/**' ]
@@ -154,10 +155,10 @@ def test_Config_reset2(self, mock_input):
154155 '--comment-reset=//,#,/**' ,
155156 '--ignore-reset=target,build,node_modules,__pycache__' ]
156157 sys .argv [1 :] = options [2 :]
157- parser = CodeCounterArgsParser ()
158- args = parser . args
159- self .assertTrue ('config' in args )
160- config .invoke (args [ ' config' ] )
158+
159+ args = CodeCounterArgs ()
160+ self .assertTrue (args . has_config_args () )
161+ config .invoke (args . config () )
161162
162163 suffix = ['java' , 'cpp' , 'go' , 'js' , 'py' ]
163164 comment = ['//' , '#' , '/**' ]
@@ -182,10 +183,10 @@ def test_Config_reset3(self, mock_input):
182183 '--comment-reset=//,#,/**' ,
183184 '--ignore-reset=target,build,node_modules,__pycache__' ]
184185 sys .argv [1 :] = options [2 :]
185- parser = CodeCounterArgsParser ()
186- args = parser . args
187- self .assertTrue ('config' in args )
188- config .invoke (args [ ' config' ] )
186+
187+ args = CodeCounterArgs ()
188+ self .assertTrue (args . has_config_args () )
189+ config .invoke (args . config () )
189190
190191 suffix = ['java' , 'cpp' , 'go' , 'js' , 'py' ]
191192 comment = ['//' , '#' , '/**' ]
@@ -210,10 +211,10 @@ def test_Config_reset4(self, mock_input):
210211 '--comment-reset=//,#,/**' ,
211212 '--ignore-reset=target,build,node_modules,__pycache__' ]
212213 sys .argv [1 :] = options [2 :]
213- parser = CodeCounterArgsParser ()
214- args = parser . args
215- self .assertTrue ('config' in args )
216- config .invoke (args [ ' config' ] )
214+
215+ args = CodeCounterArgs ()
216+ self .assertTrue (args . has_config_args () )
217+ config .invoke (args . config () )
217218
218219 suffix = ['java' , 'cpp' , 'go' , 'js' , 'py' ]
219220 comment = ['//' , '#' , '/**' ]
@@ -238,10 +239,10 @@ def test_Config_add1(self, mock_input):
238239 '--comment-add=TEST_COMMENT' ,
239240 '--ignore-add=TEST_IGNORE' ]
240241 sys .argv [1 :] = options [2 :]
241- parser = CodeCounterArgsParser ()
242- args = parser . args
243- self .assertTrue ('config' in args )
244- config .invoke (args [ ' config' ] )
242+
243+ args = CodeCounterArgs ()
244+ self .assertTrue (args . has_config_args () )
245+ config .invoke (args . config () )
245246
246247 suffix = 'TEST_SUFFIX'
247248 comment = 'TEST_COMMENT'
@@ -266,10 +267,10 @@ def test_Config_add2(self, mock_input):
266267 '--comment-add=TEST_COMMENT' ,
267268 '--ignore-add=TEST_IGNORE' ]
268269 sys .argv [1 :] = options [2 :]
269- parser = CodeCounterArgsParser ()
270- args = parser . args
271- self .assertTrue ('config' in args )
272- config .invoke (args [ ' config' ] )
270+
271+ args = CodeCounterArgs ()
272+ self .assertTrue (args . has_config_args () )
273+ config .invoke (args . config () )
273274
274275 suffix = 'TEST_SUFFIX'
275276 comment = 'TEST_COMMENT'
@@ -294,10 +295,10 @@ def test_Config_add3(self, mock_input):
294295 '--comment-add=TEST_COMMENT' ,
295296 '--ignore-add=TEST_IGNORE' ]
296297 sys .argv [1 :] = options [2 :]
297- parser = CodeCounterArgsParser ()
298- args = parser . args
299- self .assertTrue ('config' in args )
300- config .invoke (args [ ' config' ] )
298+
299+ args = CodeCounterArgs ()
300+ self .assertTrue (args . has_config_args () )
301+ config .invoke (args . config () )
301302
302303 suffix = 'TEST_SUFFIX'
303304 comment = 'not TEST_COMMENT'
@@ -322,10 +323,10 @@ def test_Config_add4(self, mock_input):
322323 '--comment-add=TEST_COMMENT' ,
323324 '--ignore-add=TEST_IGNORE' ]
324325 sys .argv [1 :] = options [2 :]
325- parser = CodeCounterArgsParser ()
326- args = parser . args
327- self .assertTrue ('config' in args )
328- config .invoke (args [ ' config' ] )
326+
327+ args = CodeCounterArgs ()
328+ self .assertTrue (args . has_config_args () )
329+ config .invoke (args . config () )
329330
330331 suffix = 'TEST_SUFFIX'
331332 comment = 'TEST_COMMENT'
0 commit comments