Skip to content

Commit

Permalink
added --dirs tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenZcience committed Nov 4, 2023
1 parent 3c3e966 commit 78284d2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
49 changes: 42 additions & 7 deletions cat_win/tests/test_argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
# import sys
# sys.path.append('../cat_win')


test_file_dir = os.path.join(os.path.dirname(__file__), 'texts')
test_file_dir = os.path.dirname(__file__)
project_dir = os.path.dirname(test_file_dir)
test_text_file_dir = os.path.join(test_file_dir, 'texts')


class TestArgParser(TestCase):
Expand Down Expand Up @@ -121,7 +122,7 @@ def test_get_arguments_replace(self):
def test_get_arguments_dir(self):
arg_parser = ArgParser()
args, unknown_args, unknown_files, echo_args = arg_parser.get_arguments(
['CAT', test_file_dir])
['CAT', test_text_file_dir])
known_files = arg_parser.get_files()
self.assertCountEqual(args, [])
self.assertCountEqual(unknown_args, [])
Expand All @@ -131,9 +132,9 @@ def test_get_arguments_dir(self):

def test_get_arguments_files_equal_dir(self):
arg_parser = ArgParser()
arg_parser.get_arguments(['CAT', test_file_dir])
arg_parser.get_arguments(['CAT', test_text_file_dir])
known_files_dir = arg_parser.get_files()
arg_parser.get_arguments(['CAT', test_file_dir + '/**.txt'])
arg_parser.get_arguments(['CAT', test_text_file_dir + '/**.txt'])
known_files_files = arg_parser.get_files()
self.assertCountEqual(known_files_dir, known_files_files)

Expand All @@ -158,14 +159,14 @@ def test_get_arguments_unknown_args(self):
def test_get_arguments_echo_args(self):
arg_parser = ArgParser()
args, unknown_args, unknown_files, echo_args = arg_parser.get_arguments(
['CAT', '-n', '-E', '-n', 'random', test_file_dir])
['CAT', '-n', '-E', '-n', 'random', test_text_file_dir])
known_files = arg_parser.get_files()
args = list(map(lambda x: x[1], args))
self.assertCountEqual(args, ['-n', '-E'])
self.assertCountEqual(unknown_args, [])
self.assertCountEqual(known_files, [])
self.assertCountEqual(unknown_files, [])
self.assertCountEqual(echo_args, ['-n', 'random', test_file_dir])
self.assertCountEqual(echo_args, ['-n', 'random', test_text_file_dir])

def test_get_arguments_echo_args_recursive(self):
arg_parser = ArgParser()
Expand Down Expand Up @@ -215,3 +216,37 @@ def test_levenshtein(self):
81.8181, 3)
self.assertAlmostEqual(levenshtein('lower!', 'LOWER?'), 83.3333, 3)
self.assertAlmostEqual(levenshtein('--hecksview', '--hexview'), 66.6666, 3)

def test_known_directories(self):
inside_project_dirs = [
'const',
'persistence',
'tests',
'util',
'web',
]
inside_test_dirs = [
'mocks',
'resources',
'texts',
]
arg_parser = ArgParser()
arg_parser._add_argument(test_file_dir)
arg_parser.get_files()
dirs = '\n'.join(arg_parser.get_dirs())
for dir in inside_test_dirs:
self.assertIn(dir, dirs)

arg_parser = ArgParser()
arg_parser._add_argument(project_dir)
arg_parser.get_files()
dirs = '\n'.join(arg_parser.get_dirs())
for dir in inside_project_dirs:
self.assertIn(dir, dirs)

arg_parser = ArgParser()
arg_parser._add_argument(project_dir + '/**')
arg_parser.get_files()
dirs = '\n'.join(arg_parser.get_dirs())
for dir in inside_project_dirs + inside_test_dirs:
self.assertIn(dir, dirs)
7 changes: 7 additions & 0 deletions cat_win/tests/test_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,11 @@ def test__get_file_prefix(self):
prefix = cat._get_file_prefix('pre ', 0, True)
self.assertEqual(prefix, 'pre test_uri/b/c.x ')

@patch('cat_win.cat.arg_parser._known_directories', new=['dirA', 'dirB'])
def test__dirs_output(self):
with patch('cat_win.cat.sys.stdout', new=StdOutMock()) as fake_out:
cat._show_dirs()
self.assertIn('dirA', fake_out.getvalue())
self.assertIn('dirB', fake_out.getvalue())

# python -m unittest discover -s cat_win.tests -p test*.py

0 comments on commit 78284d2

Please sign in to comment.