def test__comparision__repr(self):
        # Arrange
        f = SearchResult(os.path.join('C:', 'my', 'path', 'theFile.txt'), 'B',
                         10)

        # Act
        result = f.__repr__()

        # Arrange
        self.assertEqual(str, type(result))
    def test__comparision__gt_file(self):
        # Arrange
        f_a = SearchResult(os.path.join('C:', 'my', 'path', 'theFile.txt'),
                           'SearchTerm', 10)
        f_b = SearchResult(os.path.join('D:', 'my', 'path', 'theFile.txt'),
                           'SearchTerm', 10)

        # Act
        result = f_a > f_b

        # Arrange
        self.assertFalse(result)
    def test__comparision__not_lt(self):
        # Arrange
        f_a = SearchResult(os.path.join('C:', 'my', 'path', 'theFile.txt'),
                           'B', 10)
        f_b = SearchResult(os.path.join('C:', 'my', 'path', 'theFile.txt'),
                           'A', 10)

        # Act
        result = f_a < f_b

        # Arrange
        self.assertFalse(result)
    def test__comparision__lt_line_number(self):
        # Arrange
        f_a = SearchResult(os.path.join('C:', 'my', 'path', 'theFile.txt'),
                           'SearchTerm', 10)
        f_b = SearchResult(os.path.join('C:', 'my', 'path', 'theFile.txt'),
                           'SearchTerm', 12)

        # Act
        result = f_a < f_b

        # Arrange
        self.assertTrue(result)
Ejemplo n.º 5
0
    def test__group_search_results__valid_results__group(self):
        # Arrange
        base = os.path.join("C:/", "My", "Path")
        sr1 = SearchResult(os.path.join(base, "MyFile.txt"), "term1", 10)
        sr2 = SearchResult(os.path.join(base, "MyFile.txt"), "term1", 20)
        sr3 = SearchResult(os.path.join(base, "OtherFile.txt"), "term1", 11)
        sr4 = SearchResult(os.path.join(base, "sub", "MyFile.txt"), "term1", 12)
        sr5 = SearchResult(os.path.join(base, "sub", "OtherFile.txt"), "term2", 13)
        sr6 = SearchResult(os.path.join(base, "sub2", "MyFile.txt"), "term2", 14)
        sr7 = SearchResult(os.path.join(base, "sub2", "OtherFile.txt"), "term3", 15)
        sr8 = SearchResult(os.path.join(base, "sub2", "OtherFile.txt"), "term3", 25)
        input_res = [sr1, sr2, sr3, sr4, sr5, sr6, sr7, sr8]
        output_res = {
            'term1': {
                os.path.join(base, "MyFile.txt"): [10, 20],
                os.path.join(base, "OtherFile.txt"): [11],
                os.path.join(base, "sub", "MyFile.txt"): [12]
            },
            'term2': {
                os.path.join(base, "sub", "OtherFile.txt"): [13],
                os.path.join(base, "sub2", "MyFile.txt"): [14]
            },
            'term3': {
                os.path.join(base, "sub2", "OtherFile.txt"): [15, 25]
            }
        }
        fcs = FileContentSearch(['term', '-d', base])

        # Act
        result = fcs._group_search_results(input_res)

        # Assert
        self.assertEqual(output_res, result)
Ejemplo n.º 6
0
    def test__group_search_results__valid_results_without_line__group(self):
        # Arrange
        base = os.path.join("C:/", "My", "Path")
        sr1 = SearchResult(os.path.join(base, "MyFile.txt"), "term1", None)
        sr2 = SearchResult(os.path.join(base, "MyFile.txt"), "term1", None)
        sr3 = SearchResult(os.path.join(base, "OtherFile.txt"), "term1", None)
        sr4 = SearchResult(os.path.join(base, "sub", "MyFile.txt"), "term1", None)
        sr5 = SearchResult(os.path.join(base, "sub", "OtherFile.txt"), "term2", None)
        sr6 = SearchResult(os.path.join(base, "sub2", "MyFile.txt"), "term2", None)
        sr7 = SearchResult(os.path.join(base, "sub2", "OtherFile.txt"), "term3", None)
        sr8 = SearchResult(os.path.join(base, "sub2", "OtherFile.txt"), "term3", None)
        input_res = [sr1, sr2, sr3, sr4, sr5, sr6, sr7, sr8]
        output_res = {
            'term1': {
                os.path.join(base, "MyFile.txt"): [None],
                os.path.join(base, "OtherFile.txt"): [None],
                os.path.join(base, "sub", "MyFile.txt"): [None]
            },
            'term2': {
                os.path.join(base, "sub", "OtherFile.txt"): [None],
                os.path.join(base, "sub2", "MyFile.txt"): [None]
            },
            'term3': {
                os.path.join(base, "sub2", "OtherFile.txt"): [None]
            }
        }
        fcs = FileContentSearch(['term', '-d', base])

        # Act
        result = fcs._group_search_results(input_res)

        # Assert
        self.assertEqual(output_res, result)
    def test__comparision__eq(self):
        # Arrange
        f_a = SearchResult(os.path.join('C:', 'my', 'path', 'theFile.txt'),
                           'SearchTerm', 10)

        # Act
        result = f_a == f_a

        # Arrange
        self.assertTrue(result)
    def test__search_result__setting_values(self):
        # Act
        f = SearchResult(os.path.join('C:', 'my', 'path', 'theFile.txt'),
                         'SearchTerm', 10)

        # Assert
        self.assertEqual(os.path.join('C:', 'my', 'path', 'theFile.txt'),
                         f.file)
        self.assertEqual('SearchTerm', f.term)
        self.assertEqual(10, f.line_number)
    def test__comparision__ne_other_object(self):
        # Arrange
        f_a = SearchResult(os.path.join('C:', 'my', 'path', 'theFile.txt'),
                           'A', 10)
        f_b = "other object"

        # Act
        result = f_a != f_b

        # Arrange
        self.assertTrue(result)
Ejemplo n.º 10
0
    def test__prepare_results_for_output_complex__full_paths(self):
        # Arrange
        base = os.path.join("C:/", "My", "Path")
        sr1 = SearchResult(os.path.join(base, "MyFile.txt"), "term1", 10)
        sr2 = SearchResult(os.path.join(base, "MyFile.txt"), "term1", 20)
        sr3 = SearchResult(os.path.join(base, "OtherFile.txt"), "term1", 11)
        sr4 = SearchResult(os.path.join(base, "sub", "MyFile.txt"), "term1", 12)
        sr5 = SearchResult(os.path.join(base, "sub", "OtherFile.txt"), "term2", 13)
        sr6 = SearchResult(os.path.join(base, "sub2", "MyFile.txt"), "term2", 14)
        sr7 = SearchResult(os.path.join(base, "sub2", "OtherFile.txt"), "term3", 15)
        sr8 = SearchResult(os.path.join(base, "sub2", "OtherFile.txt"), "term3", 25)
        input_res = [sr1, sr2, sr3, sr4, sr5, sr6, sr7, sr8]
        fcs = FileContentSearch(['term', '-d', base, '--long'])

        # Act
        result = fcs._prepare_results_for_output_complex(input_res)

        # Assert
        self.assertIn(os.path.join(base, "MyFile.txt"), result)
        self.assertIn(os.path.join(base, "OtherFile.txt"), result)
        self.assertIn(os.path.join(base, "sub", "MyFile.txt"), result)
        self.assertIn(os.path.join(base, "sub", "OtherFile.txt"), result)
        self.assertIn(os.path.join(base, "sub2", "MyFile.txt"), result)
        self.assertIn(os.path.join(base, "sub2", "OtherFile.txt"), result)