|
7 | 7 | from unittest.mock import patch |
8 | 8 | from code_counter.core.args import CodeCounterArgs |
9 | 9 | from code_counter.conf.config import Config |
10 | | -from code_counter.__main__ import main |
11 | 10 |
|
12 | 11 | test_path = os.path.abspath('.') |
13 | 12 | bin_path = os.path.dirname(os.path.join(os.pardir, '..')) |
14 | 13 | lib_path = os.path.abspath(os.path.join(bin_path, 'code_counter')) |
15 | 14 | app_path = os.path.join(lib_path, '__main__.py') |
16 | 15 |
|
17 | 16 |
|
18 | | -class CodeCounterTest(unittest.TestCase): |
| 17 | +class CodeCounterConfigTest(unittest.TestCase): |
19 | 18 | def setUp(self): |
20 | 19 | self.default_suffix = ["c", "cc", "clj", "cpp", "cs", "cu", "cuh", "dart", "go", "h", |
21 | 20 | "hpp", "java", "jl", "js", "kt", "lisp", "lua", "pde", "m", "php", |
22 | 21 | "py", "R", "rb", "rs", "rust", "sh", "scala", "swift", "ts", "vb"] |
23 | 22 | self.default_comment = ["#", "//", "/*", "*", "*/", ":", ";", '""""'] |
24 | 23 | self.default_ignore = ["out", "venv", ".git", ".idea", "build", "target", "node_modules", ".vscode", "dist"] |
25 | 24 |
|
26 | | - def test_print_help(self): |
27 | | - options = ('python', app_path, '--help') |
28 | | - sys.argv[1:] = options[2:] |
29 | | - try: |
30 | | - CodeCounterArgs() |
31 | | - except SystemExit: |
32 | | - pass |
33 | | - |
34 | | - def test_print_search_help(self): |
35 | | - options = ('python', app_path, 'search', '--help') |
36 | | - sys.argv[1:] = options[2:] |
37 | | - try: |
38 | | - CodeCounterArgs() |
39 | | - except SystemExit: |
40 | | - pass |
41 | | - |
42 | | - def test_print_config_help(self): |
43 | | - options = ('python', app_path, 'config', '--help') |
44 | | - sys.argv[1:] = options[2:] |
45 | | - try: |
46 | | - CodeCounterArgs() |
47 | | - except SystemExit: |
48 | | - pass |
49 | | - |
50 | | - def test_search_args(self): |
51 | | - options = ['python', app_path, |
52 | | - 'search', |
53 | | - '../code_counter/', |
54 | | - '-v', |
55 | | - '-g', |
56 | | - '-o=output.txt', |
57 | | - '--suffix=py,java,cpp', |
58 | | - '--comment=//,#,/*', |
59 | | - '--ignore=.vscode,.idea'] |
60 | | - sys.argv[1:] = options[2:] |
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.") |
66 | | - self.assertTrue(search_args.verbose, '-v,--verbose flag parsed error.') |
67 | | - self.assertTrue(search_args.graph, '-g,--graph flag parsed error.') |
68 | | - self.assertEqual(search_args.output_path, 'output.txt', "output path parsed error.") |
69 | | - self.assertEqual(search_args.suffix, ['py', 'java', 'cpp'], "suffix flag and values parsed error.") |
70 | | - self.assertEqual(search_args.comment, ['//', '#', '/*'], "comment flag and values parsed error.") |
71 | | - self.assertEqual(search_args.ignore, ['.vscode', '.idea'], "ignore flag and values parsed error.") |
72 | | - |
73 | | - def test_config_args(self): |
74 | | - options = ['python', app_path, |
75 | | - 'config', |
76 | | - '--list', |
77 | | - '--suffix-add=lisp', |
78 | | - '--suffix-reset=clj', |
79 | | - '--comment-add=//', |
80 | | - '--comment-reset=;', |
81 | | - '--ignore-add=.idea', |
82 | | - '--ignore-reset=target', |
83 | | - '--restore'] |
84 | | - sys.argv[1:] = options[2:] |
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() |
89 | | - self.assertTrue(config_args.show_list, '--list flag parsed error.') |
90 | | - self.assertEqual(config_args.suffix_add, ['lisp'], "suffix_add flag and values parsed error.") |
91 | | - self.assertEqual(config_args.suffix_reset, ['clj'], "suffix_reset flag and values parsed error.") |
92 | | - self.assertEqual(config_args.comment_add, ['//'], "comment_add flag and values parsed error.") |
93 | | - self.assertEqual(config_args.comment_reset, [';'], "comment_reset flag and values parsed error.") |
94 | | - self.assertEqual(config_args.ignore_add, ['.idea'], "ignore_add flag and values parsed error.") |
95 | | - self.assertEqual(config_args.ignore_reset, ['target'], "ignore_reset flag and values parsed error.") |
96 | | - self.assertTrue(config_args.restore, '--restore flag parsed error.') |
97 | | - |
98 | 25 | @patch('builtins.input') |
99 | 26 | def test_Config_restore(self, mock_input): |
100 | 27 | mock_input.side_effect = ['y'] |
@@ -337,16 +264,3 @@ def test_Config_add4(self, mock_input): |
337 | 264 | self.assertTrue(ignore not in config.ignore) |
338 | 265 |
|
339 | 266 | config.restore() |
340 | | - |
341 | | - def test_search_case1(self): |
342 | | - options = ['python', app_path, |
343 | | - 'search', |
344 | | - '..', |
345 | | - '-v', |
346 | | - '-o=output.txt'] |
347 | | - sys.argv[1:] = options[2:] |
348 | | - main() |
349 | | - |
350 | | - output_path = os.path.join(test_path, 'output.txt') |
351 | | - self.assertTrue(os.path.exists(output_path)) |
352 | | - os.remove(output_path) |
0 commit comments