diff --git a/cat_win/tests/test_argparser.py b/cat_win/tests/test_argparser.py index faed26dc..fcab0f75 100644 --- a/cat_win/tests/test_argparser.py +++ b/cat_win/tests/test_argparser.py @@ -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): @@ -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, []) @@ -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) @@ -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() @@ -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) diff --git a/cat_win/tests/test_cat.py b/cat_win/tests/test_cat.py index 4187642a..084d6d04 100644 --- a/cat_win/tests/test_cat.py +++ b/cat_win/tests/test_cat.py @@ -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