Beispiel #1
0
    def test_ignore_patterns(self):
        compare = FilesComparison()

        # red != blue, banana != grapefruit => 2 failures
        self.assertEqual(
            compare.check_strings(['abc', 'red', 'banana'],
                                  ['abc', 'blue', 'grapefruit']),
            (1, ['2 lines are different, starting at line 2', 'No files']))

        # red != blue, banana !~ gr.*t => 2 failures
        self.assertEqual(
            compare.check_strings(['abc', 'red', 'banana'],
                                  ['abc', 'blue', 'grapefruit'],
                                  ignore_patterns=['gr.*t']),
            (1, [
                '2 lines are different, starting at line 2', 'No files',
                'Note exclusions:', '    gr.*t'
            ]))

        # red != blue, but great DOES ~ gr.*t => 1 failure
        self.assertEqual(
            compare.check_strings(['abc', 'red', 'great'],
                                  ['abc', 'blue', 'grapefruit'],
                                  ignore_patterns=['gr.*t']),
            (1, [
                '1 line is different, starting at line 2', 'No files',
                'Note exclusions:', '    gr.*t'
            ]))

        # spangle DOES ~ sp......, and breadfruit DOES ~ .*fruit => success
        self.assertEqual(
            compare.check_strings(['abc', 'spangle', 'breadfruit'],
                                  ['abc', 'spanner', 'grapefruit'],
                                  ignore_patterns=['sp.....', '[bg].*fruit']),
            (0, []))
Beispiel #2
0
 def test_print(self):
     msgs = []
     compare = FilesComparison(print_fn=lambda x: msgs.append(x))
     compare.check_strings(['a'], ['b'], create_temporaries=False)
     self.assertEqual(msgs, [
         '1 line is different, starting at line 1',
         'No files available for comparison'
     ])
Beispiel #3
0
 def test_strings_fail(self):
     compare = FilesComparison()
     self.assertEqual(compare.check_strings([], ['x']),
                      (1, ['Strings have different numbers of lines',
                           'No files']))
     self.assertEqual(compare.check_strings(['y'], ['x']),
                      (1, ['1 line is different, starting at line 1',
                           'No files']))
Beispiel #4
0
 def test_strings_fail(self):
     compare = FilesComparison()
     self.assertEqual(compare.check_strings([], ['x'], create_temporaries=False),
                      (1, ['Strings have different numbers of lines, '
                           'differences start at end of actual string',
                           'No files available for comparison']))
     self.assertEqual(compare.check_strings(['y'], ['x'], create_temporaries=False),
                      (1, ['1 line is different, starting at line 1',
                           'No files available for comparison']))
Beispiel #5
0
 def test_strip(self):
     compare = FilesComparison()
     self.assertEqual(compare.check_strings(['   abc'], ['abc']),
                      (1, ['1 line is different, starting at line 1',
                           'No files']))
     self.assertEqual(compare.check_strings(['   abc'], ['abc'],
                                            lstrip=True), (0, []))
     self.assertEqual(compare.check_strings(['abc   '], ['abc'],
                                            rstrip=True), (0, []))
     self.assertEqual(compare.check_strings(['   abc   '], ['abc'],
                                            lstrip=True, rstrip=True),
                      (0, []))
Beispiel #6
0
 def test_strip(self):
     compare = FilesComparison()
     self.assertEqual(compare.check_strings(['   abc'], ['abc'],
                                            create_temporaries=False),
                      (1, ['1 line is different, starting at line 1',
                           'No files available for comparison']))
     self.assertEqual(compare.check_strings(['   abc'], ['abc'],
                                            lstrip=True), (0, []))
     self.assertEqual(compare.check_strings(['abc   '], ['abc'],
                                            rstrip=True), (0, []))
     self.assertEqual(compare.check_strings(['   abc   '], ['abc'],
                                            lstrip=True, rstrip=True),
                      (0, []))
Beispiel #7
0
 def test_strings_fail(self):
     compare = FilesComparison()
     self.assertEqual(
         compare.check_strings([], ['x'], create_temporaries=False), (1, [
             'Strings have different numbers of lines, '
             'differences start at end of actual string',
             'No files available for comparison'
         ]))
     self.assertEqual(
         compare.check_strings(['y'], ['x'], create_temporaries=False),
         (1, [
             '1 line is different, starting at line 1',
             'No files available for comparison'
         ]))
Beispiel #8
0
 def test_preprocess(self):
     compare = FilesComparison()
     def strip_first_five(strings):
         return [s[5:] for s in strings]
     def strip_first_seven(strings):
         return [s[7:] for s in strings]
     self.assertEqual(compare.check_strings(['abc','spangle', 'breadfruit'],
                                            ['abc','spanner', 'grapefruit'],
                                            preprocess=strip_first_five),
                      (1, ['1 line is different, starting at line 2',
                           'No files']))
     self.assertEqual(compare.check_strings(['abc','spangle', 'breadfruit'],
                                            ['abc','spanner', 'grapefruit'],
                                            preprocess=strip_first_seven),
                      (0, []))
Beispiel #9
0
 def test_permutations(self):
     compare = FilesComparison()
     self.assertEqual(compare.check_strings(['abc','spangle', 'spanner'],
                                            ['spangle','spanner', 'abc'],
                                            max_permutation_cases=1),
                      (1, ['3 lines are different, starting at line 1',
                           'No files']))
     self.assertEqual(compare.check_strings(['abc','spangle', 'spanner'],
                                            ['abc','spanner', 'spangle'],
                                            max_permutation_cases=2),
                      (0, []))
     self.assertEqual(compare.check_strings(['abc','spangle', 'spanner'],
                                            ['spangle','spanner', 'abc'],
                                            max_permutation_cases=3),
                      (0, []))
Beispiel #10
0
 def test_permutations(self):
     compare = FilesComparison()
     self.assertEqual(compare.check_strings(['abc','spangle', 'spanner'],
                                            ['spangle','spanner', 'abc'],
                                            max_permutation_cases=1,
                                            create_temporaries=False),
                      (1, ['3 lines are different, starting at line 1',
                           'No files available for comparison']))
     self.assertEqual(compare.check_strings(['abc','spangle', 'spanner'],
                                            ['abc','spanner', 'spangle'],
                                            max_permutation_cases=2),
                      (0, []))
     self.assertEqual(compare.check_strings(['abc','spangle', 'spanner'],
                                            ['spangle','spanner', 'abc'],
                                            max_permutation_cases=3),
                      (0, []))
Beispiel #11
0
 def test_preprocess(self):
     compare = FilesComparison()
     def strip_first_five(strings):
         return [s[5:] for s in strings]
     def strip_first_seven(strings):
         return [s[7:] for s in strings]
     self.assertEqual(compare.check_strings(['abc','spangle', 'breadfruit'],
                                            ['abc','spanner', 'grapefruit'],
                                            preprocess=strip_first_five,
                                            create_temporaries=False),
                      (1, ['1 line is different, starting at line 2',
                           'No files available for comparison']))
     self.assertEqual(compare.check_strings(['abc','spangle', 'breadfruit'],
                                            ['abc','spanner', 'grapefruit'],
                                            preprocess=strip_first_seven),
                      (0, []))
Beispiel #12
0
 def test_ignore_substrings(self):
     compare = FilesComparison()
     self.assertEqual(compare.check_strings(['abc','red', 'banana'],
                                            ['abc','blue', 'grapefruit']),
                      (1, ['2 lines are different, starting at line 2',
                           'No files']))
     self.assertEqual(compare.check_strings(['abc','red', 'banana'],
                                            ['abc','blue', 'grapefruit'],
                                            ignore_substrings=['re']),
                      (1, ['1 line is different, starting at line 3',
                           'No files',
                           'Note exclusions:', '    re']))
     self.assertEqual(compare.check_strings(['abc','red', 'banana'],
                                            ['abc','blue', 'grapefruit'],
                                            ignore_substrings=['ue','gra']),
                      (0, []))
Beispiel #13
0
 def test_ignore_patterns(self):
     compare = FilesComparison()
     self.assertEqual(compare.check_strings(['abc','red', 'banana'],
                                            ['abc','blue', 'grapefruit']),
                      (1, ['2 lines are different, starting at line 2',
                           'No files']))
     self.assertEqual(compare.check_strings(['abc','red', 'banana'],
                                            ['abc','blue', 'grapefruit'],
                                            ignore_patterns=['gr.*t']),
                      (1, ['2 lines are different, starting at line 2',
                           'No files',
                           'Note exclusions:', '    gr.*t']))
     self.assertEqual(compare.check_strings(['abc','spangle', 'breadfruit'],
                                            ['abc','spanner', 'grapefruit'],
                                            ignore_patterns=['sp.....',
                                                             '.*fruit']),
                      (0, []))
Beispiel #14
0
 def test_strip(self):
     compare = FilesComparison()
     self.assertEqual(
         compare.check_strings(['   abc'], ['abc'],
                               create_temporaries=False),
         (1, [
             '1 line is different, starting at line 1',
             'No files available for comparison'
         ]))
     self.assertEqual(
         compare.check_strings(['   abc'], ['abc'], lstrip=True), (0, []))
     self.assertEqual(
         compare.check_strings(['abc   '], ['abc'], rstrip=True), (0, []))
     self.assertEqual(
         compare.check_strings(['   abc   '], ['abc'],
                               lstrip=True,
                               rstrip=True), (0, []))
Beispiel #15
0
 def test_ignore_substrings(self):
     compare = FilesComparison()
     self.assertEqual(compare.check_strings(['abc','red', 'banana'],
                                            ['abc','blue', 'grapefruit'],
                                            create_temporaries=False),
                      (1, ['2 lines are different, starting at line 2',
                           'No files available for comparison']))
     self.assertEqual(compare.check_strings(['abc','blue', 'banana'],
                                            ['abc','red', 'grapefruit'],
                                            ignore_substrings=['re'],
                                            create_temporaries=False),
                      (1, ['1 line is different, starting at line 3',
                           'No files available for comparison',
                           'Note exclusions:',
                           '    ignore_substrings:',
                           '        re']))
     self.assertEqual(compare.check_strings(['abc','red', 'banana'],
                                            ['abc','blue', 'grapefruit'],
                                            ignore_substrings=['ue','gra']),
                      (0, []))
Beispiel #16
0
    def test_ignore_patterns(self):
        compare = FilesComparison()

        # red != blue, banana != grapefruit => 2 failures
        self.assertEqual(compare.check_strings(['abc','red', 'banana'],
                                               ['abc','blue', 'grapefruit'],
                                               create_temporaries=False),
                         (1, ['2 lines are different, starting at line 2',
                              'No files available for comparison']))

        # red != blue, banana !~ gr.*t => 2 failures
        self.assertEqual(compare.check_strings(['abc','red', 'banana'],
                                               ['abc','blue', 'grapefruit'],
                                               ignore_patterns=['gr.*t'],
                                               create_temporaries=False),
                         (1, ['2 lines are different, starting at line 2',
                              'No files available for comparison',
                              'Note exclusions:',
                              '    ignore_patterns:',
                              '        gr.*t']))

        # red != blue, but great DOES ~ gr.*t => 1 failure
        self.assertEqual(compare.check_strings(['abc','red', 'great'],
                                               ['abc','blue', 'grapefruit'],
                                               ignore_patterns=['gr.*t'],
                                               create_temporaries=False),
                         (1, ['1 line is different, starting at line 2',
                              'No files available for comparison',
                              'Note exclusions:',
                              '    ignore_patterns:',
                              '        gr.*t']))

        # spangle DOES ~ sp......, and breadfruit DOES ~ .*fruit => success
        self.assertEqual(compare.check_strings(['abc','spangle', 'breadfruit'],
                                               ['abc','spanner', 'grapefruit'],
                                               ignore_patterns=[
                                                   'sp.....',
                                                   '[bg].*fruit'
                                               ]),
                         (0, []))
Beispiel #17
0
 def test_strings_ok(self):
     compare = FilesComparison()
     self.assertEqual(compare.check_strings([], []), (0, []))
     self.assertEqual(compare.check_strings(['abc'], ['abc']), (0, []))
     self.assertEqual(compare.check_strings(['ab', 'c'], ['ab', 'c']),
                      (0, []))
Beispiel #18
0
 def test_print(self):
     msgs = []
     compare = FilesComparison(print_fn=lambda x: msgs.append(x))
     compare.check_strings(['a'], ['b'], create_temporaries=False)
     self.assertEqual(msgs, ['1 line is different, starting at line 1',
                             'No files available for comparison'])
Beispiel #19
0
 def test_print(self):
     msgs = []
     compare = FilesComparison(print_fn=lambda x: msgs.append(x))
     compare.check_strings(['a'], ['b'])
     self.assertEqual(msgs, ['1 line is different, starting at line 1',
                             'No files'])
Beispiel #20
0
 def test_strings_ok(self):
     compare = FilesComparison()
     self.assertEqual(compare.check_strings([], []), (0, []))
     self.assertEqual(compare.check_strings(['abc'], ['abc']), (0, []))
     self.assertEqual(compare.check_strings(['ab', 'c'], ['ab', 'c']),
                      (0, []))