def test_filter_file_nonarchive_archivesonly(self): settings = self.get_settings() settings.archivesonly = True settings.searcharchives = True searcher = Searcher(settings) f = SearchFile(path='', filename='FileUtil.pm', filetype=FileType.Text) self.assertFalse(searcher.filter_file(f))
def test_filter_file_is_hidden_file(self): settings = self.get_settings() searcher = Searcher(settings) f = SearchFile(path='', filename='.gitignore', filetype=FileType.Unknown) self.assertFalse(searcher.filter_file(f))
def test_filter_file_archive_no_searcharchives(self): settings = self.get_settings() searcher = Searcher(settings) f = SearchFile(path='', filename='archive.zip', filetype=FileType.Archive) self.assertFalse(searcher.filter_file(f))
def test_filter_file_archive_archivesonly(self): settings = self.get_settings() settings.archivesonly = True settings.searcharchives = True searcher = Searcher(settings) f = SearchFile(path='', filename='archive.zip', filetype=FileType.Archive) self.assertTrue(searcher.filter_file(f))
def test_filter_file_hidden_includehidden(self): settings = self.get_settings() settings.excludehidden = False searcher = Searcher(settings) f = SearchFile(path='', filename='.gitignore', filetype=FileType.Unknown) self.assertTrue(searcher.filter_file(f))
def test_search_multiline_string(self): settings = self.get_settings() searcher = Searcher(settings) testfile = self.get_test_file() results = [] try: fo = open(testfile, 'r') results = searcher.search_line_iterator(fo) fo.close() except IOError as e: print('IOError: {0!s}: {1!s}'.format(e, sf)) self.assertEqual(len(results), 2) firstResult = results[0] self.assertEqual(firstResult.linenum, 23) self.assertEqual(firstResult.match_start_index, 3) self.assertEqual(firstResult.match_end_index, 11) secondResult = results[1] self.assertEqual(secondResult.linenum, 29) self.assertEqual(secondResult.match_start_index, 24) self.assertEqual(secondResult.match_end_index, 32)
def test_search_multiline_string(self): settings = self.get_settings() searcher = Searcher(settings) testfile = self.get_test_file() results = [] try: fo = open(testfile, 'r') results = searcher.search_line_iterator(fo) fo.close() except IOError as e: print('IOError: {0!s}'.format(e)) self.assertEqual(len(results), 2) firstResult = results[0] self.assertEqual(firstResult.linenum, 23) self.assertEqual(firstResult.match_start_index, 3) self.assertEqual(firstResult.match_end_index, 11) secondResult = results[1] self.assertEqual(secondResult.linenum, 29) self.assertEqual(secondResult.match_start_index, 24) self.assertEqual(secondResult.match_end_index, 32)
def test_is_search_file_matches_out_pattern(self): settings = self.get_settings() settings.add_pattern('Search', 'out_filepatterns') searcher = Searcher(settings) f = 'Searcher.pm' self.assertFalse(searcher.is_search_file(f))
def test_is_search_file_no_match_out_extension(self): settings = self.get_settings() settings.add_comma_delimited_exts('py', 'out_extensions') searcher = Searcher(settings) f = 'FileUtil.pm' self.assertTrue(searcher.is_search_file(f))
def test_is_search_file_matches_out_pattern(self): settings = self.get_settings() settings.add_patterns('Search', 'out_filepatterns') searcher = Searcher(settings) f = 'Searcher.pm' self.assertFalse(searcher.is_search_file(f))
def test_is_archive_search_file_matches_by_default(self): settings = self.get_settings() searcher = Searcher(settings) f = 'archive.zip' self.assertTrue(searcher.is_archive_search_file(f))
def test_filter_file_matches_by_default(self): settings = self.get_settings() searcher = Searcher(settings) f = SearchFile(path='', filename='FileUtil.pm', filetype=FileType.Text) self.assertTrue(searcher.filter_file(f))
def test_is_archive_search_file_no_match_out_extension(self): settings = self.get_settings() settings.add_comma_delimited_exts('gz', 'out_archiveextensions') searcher = Searcher(settings) f = 'archive.zip' self.assertTrue(searcher.is_archive_search_file(f))
def test_is_search_dir_no_patterns(self): settings = self.get_settings() searcher = Searcher(settings) dir = 'plsearch' self.assertTrue(searcher.is_search_dir(dir))
def test_is_archive_search_file_no_match_out_pattern(self): settings = self.get_settings() settings.add_patterns('archives', 'out_archivefilepatterns') searcher = Searcher(settings) f = 'archive.zip' self.assertTrue(searcher.is_archive_search_file(f))
def test_is_search_file_no_match_out_pattern(self): settings = self.get_settings() settings.add_pattern('Search', 'out_filepatterns') searcher = Searcher(settings) f = 'FileUtil.pm' self.assertTrue(searcher.is_search_file(f))
def test_is_archive_search_file_no_match_out_extension(self): settings = self.get_settings() settings.add_exts('gz', 'out_archiveextensions') searcher = Searcher(settings) f = 'archive.zip' self.assertTrue(searcher.is_archive_search_file(f))
def test_is_archive_search_file_no_match_out_pattern(self): settings = self.get_settings() settings.add_pattern('archives', 'out_archivefilepatterns') searcher = Searcher(settings) f = 'archive.zip' self.assertTrue(searcher.is_archive_search_file(f))
def test_is_search_dir_double_dot(self): settings = self.get_settings() searcher = Searcher(settings) dir = '..' self.assertTrue(searcher.is_search_dir(dir))
def test_filter_file_not_is_search_file(self): settings = self.get_settings() settings.add_comma_delimited_exts('pl', 'in_extensions') searcher = Searcher(settings) f = SearchFile(path='', filename='FileUtil.pm', filetype=FileType.Text) self.assertFalse(searcher.filter_file(f))
def test_is_search_dir_hidden_dir_include_hidden(self): settings = self.get_settings() settings.excludehidden = False searcher = Searcher(settings) dir = '.git' self.assertTrue(searcher.is_search_dir(dir))
def test_is_search_file_no_match_out_pattern(self): settings = self.get_settings() settings.add_patterns('Search', 'out_filepatterns') searcher = Searcher(settings) f = 'FileUtil.pm' self.assertTrue(searcher.is_search_file(f))
def test_is_search_file_no_match_out_extension(self): settings = self.get_settings() settings.add_exts('py', 'out_extensions') searcher = Searcher(settings) f = 'FileUtil.pm' self.assertTrue(searcher.is_search_file(f))
def test_is_search_dir_no_match_out_pattern(self): settings = self.get_settings() settings.add_patterns('pysearch', 'out_dirpatterns') searcher = Searcher(settings) dir = 'plsearch' self.assertTrue(searcher.is_search_dir(dir))
def test_filter_file_not_is_search_file(self): settings = self.get_settings() settings.add_exts('pl', 'in_extensions') searcher = Searcher(settings) f = SearchFile(path='', filename='FileUtil.pm', filetype=FileType.Text) self.assertFalse(searcher.filter_file(f))
def test_is_search_dir_hidden_dir(self): settings = self.get_settings() searcher = Searcher(settings) dir = '.git' self.assertFalse(searcher.is_search_dir(dir))
def test_is_search_dir_no_match_out_pattern(self): settings = self.get_settings() settings.add_pattern('pysearch', 'out_dirpatterns') searcher = Searcher(settings) dir = 'plsearch' self.assertTrue(searcher.is_search_dir(dir))
def test_is_search_file_matches_by_default(self): settings = self.get_settings() searcher = Searcher(settings) f = 'FileUtil.pm' self.assertTrue(searcher.is_search_file(f))
def test_is_search_file_no_match_in_extension(self): settings = self.get_settings() settings.add_exts('pl', 'in_extensions') searcher = Searcher(settings) f = 'FileUtil.pm' self.assertFalse(searcher.is_search_file(f))