Skip to content

Commit 52b6603

Browse files
committed
✅ pass tests
1 parent 5b17eeb commit 52b6603

File tree

1 file changed

+51
-18
lines changed

1 file changed

+51
-18
lines changed

tests/test_config.py

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env python3
22
# coding:utf8
33

4-
import sys
54
import os
5+
import sys
66
import unittest
77
from unittest.mock import patch
8-
from code_counter.core.args import CodeCounterArgs
8+
99
from code_counter.conf.config import Config
10+
from code_counter.core.args import CodeCounterArgs
1011

1112
test_path = os.path.abspath('.')
1213
bin_path = os.path.dirname(os.path.join(os.pardir, '..'))
@@ -16,11 +17,11 @@
1617

1718
class CodeCounterConfigTest(unittest.TestCase):
1819
def setUp(self):
19-
self.default_suffix = ["c", "cc", "clj", "cpp", "cs", "cu", "cuh", "dart", "go", "h",
20+
self.default_suffix = {"c", "cc", "clj", "cpp", "cs", "cu", "cuh", "dart", "go", "h",
2021
"hpp", "java", "jl", "js", "kt", "lisp", "lua", "pde", "m", "php",
21-
"py", "R", "rb", "rs", "rust", "sh", "scala", "swift", "ts", "vb"]
22-
self.default_comment = ["#", "//", "/*", "*", "*/", ":", ";", '""""']
23-
self.default_ignore = ["out", "venv", ".git", ".idea", "build", "target", "node_modules", ".vscode", "dist"]
22+
"py", "R", "rb", "rs", "rust", "sh", "scala", "swift", "ts", "vb"}
23+
self.default_comment = {"#", "//", "/*", "*", "*/", ":", ";", '""""'}
24+
self.default_ignore = {"out", "venv", ".git", ".idea", "build", "target", "node_modules", ".vscode", "dist"}
2425

2526
@patch('builtins.input')
2627
def test_Config_restore(self, mock_input):
@@ -59,9 +60,9 @@ def test_Config_reset1(self, mock_input):
5960
self.assertTrue(args.has_config_args())
6061
config.invoke(args.config())
6162

62-
suffix = ['java', 'cpp', 'go', 'js', 'py']
63-
comment = ['//', '#', '/**']
64-
ignore = ['target', 'build', 'node_modules', '__pycache__']
63+
suffix = {'java', 'cpp', 'go', 'js', 'py'}
64+
comment = {'//', '#', '/**'}
65+
ignore = {'target', 'build', 'node_modules', '__pycache__'}
6566

6667
self.assertEqual(config.suffix, suffix)
6768
self.assertEqual(config.comment, comment)
@@ -87,9 +88,9 @@ def test_Config_reset2(self, mock_input):
8788
self.assertTrue(args.has_config_args())
8889
config.invoke(args.config())
8990

90-
suffix = ['java', 'cpp', 'go', 'js', 'py']
91-
comment = ['//', '#', '/**']
92-
ignore = ['target', 'build', 'node_modules', '__pycache__']
91+
suffix = {'java', 'cpp', 'go', 'js', 'py'}
92+
comment = {'//', '#', '/**'}
93+
ignore = {'target', 'build', 'node_modules', '__pycache__'}
9394

9495
self.assertEqual(config.suffix, self.default_suffix)
9596
self.assertEqual(config.comment, comment)
@@ -115,9 +116,9 @@ def test_Config_reset3(self, mock_input):
115116
self.assertTrue(args.has_config_args())
116117
config.invoke(args.config())
117118

118-
suffix = ['java', 'cpp', 'go', 'js', 'py']
119-
comment = ['//', '#', '/**']
120-
ignore = ['target', 'build', 'node_modules', '__pycache__']
119+
suffix = {'java', 'cpp', 'go', 'js', 'py'}
120+
comment = {'//', '#', '/**'}
121+
ignore = {'target', 'build', 'node_modules', '__pycache__'}
121122

122123
self.assertEqual(config.suffix, suffix)
123124
self.assertEqual(config.comment, self.default_comment)
@@ -143,16 +144,48 @@ def test_Config_reset4(self, mock_input):
143144
self.assertTrue(args.has_config_args())
144145
config.invoke(args.config())
145146

146-
suffix = ['java', 'cpp', 'go', 'js', 'py']
147-
comment = ['//', '#', '/**']
148-
ignore = ['target', 'build', 'node_modules', '__pycache__']
147+
suffix = {'java', 'cpp', 'go', 'js', 'py'}
148+
comment = {'//', '#', '/**'}
149+
ignore = {'target', 'build', 'node_modules', '__pycache__'}
149150

150151
self.assertEqual(config.suffix, suffix)
151152
self.assertEqual(config.comment, comment)
152153
self.assertEqual(config.ignore, self.default_ignore)
153154

154155
config.restore()
155156

157+
@patch('builtins.input')
158+
def test_Config_reset_duplicate(self, mock_input):
159+
mock_input.side_effect = ['y', 'y', 'y', 'y', 'y']
160+
161+
config = Config()
162+
config.restore()
163+
164+
options = ['python', app_path,
165+
'config',
166+
'--suffix-reset=py,py,py,py',
167+
'--comment-reset=#,#,#',
168+
'--ignore-reset=__pycache__,__pycache__']
169+
sys.argv[1:] = options[2:]
170+
171+
args = CodeCounterArgs()
172+
self.assertTrue(args.has_config_args())
173+
config.invoke(args.config())
174+
175+
suffix = {'py'}
176+
comment = {'#'}
177+
ignore = {'__pycache__'}
178+
179+
self.assertEqual(len(config.suffix), 1)
180+
self.assertEqual(len(config.comment), 1)
181+
self.assertEqual(len(config.ignore), 1)
182+
183+
self.assertEqual(config.suffix, suffix)
184+
self.assertEqual(config.comment, comment)
185+
self.assertEqual(config.ignore, ignore)
186+
187+
config.restore()
188+
156189
@patch('builtins.input')
157190
def test_Config_add1(self, mock_input):
158191
mock_input.side_effect = ['y', 'y', 'y', 'y', 'y']

0 commit comments

Comments
 (0)