Esempio n. 1
0
 def test_singleline_longer_colorize_searchresult(self):
     formatter = SearchResultFormatter(
         SearchSettings(colorize=True, maxlinelength=100))
     pattern = 'maxlen'
     filename = 'maxlen.txt'
     sf = SearchFile(path='.', filename=filename, filetype=FileType.TEXT)
     linenum = 10
     match_start_index = 53
     match_end_index = 59
     line = '0123456789012345678901234567890123456789012345678901' + \
            'maxlen' + \
            '8901234567890123456789012345678901234567890123456789'
     linesbefore = []
     linesafter = []
     searchresult = SearchResult(pattern=pattern,
                                 file=sf,
                                 linenum=linenum,
                                 match_start_index=match_start_index,
                                 match_end_index=match_end_index,
                                 line=line,
                                 lines_before=linesbefore,
                                 lines_after=linesafter)
     expectedline = '...89012345678901234567890123456789012345678901' + \
                    Color.GREEN + 'maxlen' + Color.RESET + \
                    '89012345678901234567890123456789012345678901...'
     expectedoutput = "{0:s}: {1:d}: [{2:d}:{3:d}]: {4:s}".format(
         os.path.join('.', filename), linenum, match_start_index,
         match_end_index, expectedline)
     output = formatter.format(searchresult)
     self.assertEqual(expectedoutput, output)
Esempio n. 2
0
 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))
Esempio n. 3
0
 def test_singleline_searchresult(self):
     formatter = SearchResultFormatter(SearchSettings(colorize=False))
     pattern = "Search"
     filename = 'Searcher.cs'
     sf = SearchFile(path=self.cssearch_path,
                     filename=filename,
                     filetype=FileType.CODE)
     linenum = 10
     match_start_index = 15
     match_end_index = 23
     line = "\tpublic class Searcher\n"
     linesbefore = []
     linesafter = []
     searchresult = SearchResult(pattern=pattern,
                                 file=sf,
                                 linenum=linenum,
                                 match_start_index=match_start_index,
                                 match_end_index=match_end_index,
                                 line=line,
                                 lines_before=linesbefore,
                                 lines_after=linesafter)
     expectedoutput = "{0:s}: {1:d}: [{2:d}:{3:d}]: {4:s}".format(
         os.path.join(self.cssearch_path, filename), linenum,
         match_start_index, match_end_index, line.strip())
     output = formatter.format(searchresult)
     self.assertEqual(expectedoutput, output)
Esempio n. 4
0
    def test_multiline_searchresult(self):
        pattern = "Search"
        filename = 'Searcher.cs'
        sf = SearchFile(path=self.cssearch_path,
                        filename=filename,
                        filetype=FileType.TEXT)
        linenum = 10
        match_start_index = 15
        match_end_index = 23
        line = "\tpublic class Searcher\n"
        linesbefore = ["namespace CsSearch\n", "{\n"]
        linesafter = ["\t{\n", "\t\tprivate readonly FileTypes _fileTypes;\n"]
        searchresult = SearchResult(pattern=pattern,
                                    file=sf,
                                    linenum=linenum,
                                    match_start_index=match_start_index,
                                    match_end_index=match_end_index,
                                    line=line,
                                    lines_before=linesbefore,
                                    lines_after=linesafter)
        expectedoutput = """================================================================================
%s: %d: [%d:%d]
--------------------------------------------------------------------------------
   8 | namespace CsSearch
   9 | {
> 10 | \tpublic class Searcher
  11 | \t{
  12 | \t\tprivate readonly FileTypes _fileTypes;
""" % (os.path.join(self.cssearch_path,
                    filename), linenum, match_start_index, match_end_index)
        self.assertEqual(expectedoutput, str(searchresult))
Esempio n. 5
0
 def test_binaryfile_searchresult(self):
     formatter = SearchResultFormatter(SearchSettings())
     pattern = "Search"
     filename = 'Searcher.exe'
     sf = SearchFile(path=self.cssearch_path,
                     filename=filename,
                     filetype=FileType.BINARY)
     linenum = 0
     match_start_index = 0
     match_end_index = 0
     line = ''
     linesbefore = []
     linesafter = []
     searchresult = SearchResult(pattern=pattern,
                                 file=sf,
                                 linenum=linenum,
                                 match_start_index=match_start_index,
                                 match_end_index=match_end_index,
                                 line=line,
                                 lines_before=linesbefore,
                                 lines_after=linesafter)
     expectedoutput = "{0:s} matches at [{1:d}:{2:d}]".format(
         os.path.join(self.cssearch_path, filename), match_start_index,
         match_end_index)
     output = formatter.format(searchresult)
     self.assertEqual(expectedoutput, output)
Esempio n. 6
0
 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))
Esempio n. 7
0
    def test_multiline_searchresult(self):
        formatter = SearchResultFormatter(SearchSettings(colorize=False))
        pattern = "Search"
        filename = 'Searcher.cs'
        sf = SearchFile(path=self.cssearch_path,
                        filename=filename,
                        filetype=FileType.TEXT)
        linenum = 10
        match_start_index = 15
        match_end_index = 23
        line = "\tpublic class Searcher\n"
        linesbefore = ["namespace CsSearch\n", "{\n"]
        linesafter = ["\t{\n", "\t\tprivate readonly FileTypes _fileTypes;\n"]
        searchresult = SearchResult(pattern=pattern,
                                    file=sf,
                                    linenum=linenum,
                                    match_start_index=match_start_index,
                                    match_end_index=match_end_index,
                                    line=line,
                                    lines_before=linesbefore,
                                    lines_after=linesafter)
        expectedoutput = "================================================================================\n" + \
            '{0:s}: {1:d}: [{2:d}:{3:d}]\n'.format(os.path.join(self.cssearch_path, filename), linenum, match_start_index, match_end_index) + \
            """--------------------------------------------------------------------------------
   8 | namespace CsSearch
   9 | {
> 10 | \tpublic class Searcher
  11 | \t{
  12 | \t\tprivate readonly FileTypes _fileTypes;
"""
        output = formatter.format(searchresult)
        self.assertEqual(expectedoutput, output)
Esempio n. 8
0
 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))
Esempio n. 9
0
 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))
Esempio n. 10
0
 def test_searchfile_rel_path3(self):
     path = '..'
     filename = 'searchfile.py'
     searchfile = SearchFile(path=path,
                             filename=filename,
                             filetype=FileType.CODE)
     self.assertEqual('../searchfile.py', searchfile.relativepath)
     self.assertEqual('../searchfile.py', str(searchfile))
Esempio n. 11
0
 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))
Esempio n. 12
0
 def test_searchfile_abs_path(self):
     path = '/Users/cary/src/xsearch/python/pysearch'
     filename = 'searchfile.py'
     searchfile = SearchFile(path=path,
                             filename=filename,
                             filetype=FileType.CODE)
     self.assertEqual(
         '/Users/cary/src/xsearch/python/pysearch/searchfile.py',
         searchfile.relativepath)
     self.assertEqual(
         '/Users/cary/src/xsearch/python/pysearch/searchfile.py',
         str(searchfile))
Esempio n. 13
0
 def test_binaryfile_searchresult(self):
     pattern = "Search"
     filename = 'Searcher.exe'
     sf = SearchFile(path=self.cssearch_path,
                     filename=filename,
                     filetype=FileType.BINARY)
     linenum = 0
     match_start_index = 0
     match_end_index = 0
     line = ''
     linesbefore = []
     linesafter = []
     searchresult = SearchResult(pattern=pattern,
                                 file=sf,
                                 linenum=linenum,
                                 match_start_index=match_start_index,
                                 match_end_index=match_end_index,
                                 line=line,
                                 lines_before=linesbefore,
                                 lines_after=linesafter)
     expectedoutput = "%s matches at [%d:%d]" % (os.path.join(
         self.cssearch_path, filename), match_start_index, match_end_index)
     self.assertEqual(expectedoutput, str(searchresult))
Esempio n. 14
0
 def test_singleline_searchresult(self):
     pattern = "Search"
     filename = 'Searcher.cs'
     sf = SearchFile(path=self.cssearch_path,
                     filename=filename,
                     filetype=FileType.TEXT)
     linenum = 10
     match_start_index = 15
     match_end_index = 23
     line = "\tpublic class Searcher\n"
     linesbefore = []
     linesafter = []
     searchresult = SearchResult(pattern=pattern,
                                 file=sf,
                                 linenum=linenum,
                                 match_start_index=match_start_index,
                                 match_end_index=match_end_index,
                                 line=line,
                                 lines_before=linesbefore,
                                 lines_after=linesafter)
     expectedoutput = "%s: %d: [%d:%d]: %s" % (
         os.path.join(self.cssearch_path, filename), linenum,
         match_start_index, match_end_index, line.strip())
     self.assertEqual(expectedoutput, str(searchresult))
Esempio n. 15
0
 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))
Esempio n. 16
0
 def test_is_search_file_matches_by_default(self):
     settings = self.get_settings()
     searcher = Searcher(settings)
     f = SearchFile(path='.', filename='FileUtil.pm', filetype=FileType.CODE)
     self.assertTrue(searcher.is_search_file(f))
Esempio n. 17
0
 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))
Esempio n. 18
0
 def test_is_search_file_no_match_out_pattern(self):
     settings = self.get_settings()
     settings.add_patterns('Search', 'out_filepatterns')
     searcher = Searcher(settings)
     f = SearchFile(path='.', filename='FileUtil.pm', filetype=FileType.CODE)
     self.assertTrue(searcher.is_search_file(f))
Esempio n. 19
0
 def test_is_search_file_matches_out_extension(self):
     settings = self.get_settings()
     settings.add_exts('pm', 'out_extensions')
     searcher = Searcher(settings)
     f = SearchFile(path='.', filename='FileUtil.pm', filetype=FileType.CODE)
     self.assertFalse(searcher.is_search_file(f))