Example #1
0
 def test_grouped_pattern(self):
     compare = FilesComparison()
     cpatterns = compare.compile_patterns(['(a|an) (grapefruit|apple)'])
     self.assertTrue(compare.check_patterns(cpatterns,
                                            'a grapefruit', 'an apple'))
     self.assertTrue(compare.check_patterns(cpatterns,
                                            'I have a grapefruit', 'I have an apple'))
     self.assertTrue(compare.check_patterns(cpatterns,
                                            'I have a grapefruit and an apple',
                                            'I have an apple and a grapefruit'))
     self.assertFalse(compare.check_patterns(cpatterns,
                                            'I have a grapefruit and a banana',
                                            'I have an apple and a grapefruit'))
Example #2
0
 def test_anchored_patterns(self):
     compare = FilesComparison()
     cpatterns = compare.compile_patterns([r'^\d+$'])
     for actual, expected in [('2', '222222222222'), ('2', '2'),
                              ('02', '2'), ('2', '23'), ('123', '564')]:
         self.assertTrue(
             compare.check_patterns(cpatterns, actual, expected),
             '%s <--> %s' % (actual, expected))
     for actual, expected in [('2', '222222222222a22'), ('', '23'),
                              ('123', '')]:
         self.assertFalse(
             compare.check_patterns(cpatterns, actual, expected),
             '%s <--> %s' % (actual, expected))
Example #3
0
 def test_grouped_pattern(self):
     compare = FilesComparison()
     cpatterns = compare.compile_patterns(['(a|an) (grapefruit|apple)'])
     self.assertTrue(
         compare.check_patterns(cpatterns, 'a grapefruit', 'an apple'))
     self.assertTrue(
         compare.check_patterns(cpatterns, 'I have a grapefruit',
                                'I have an apple'))
     self.assertTrue(
         compare.check_patterns(cpatterns,
                                'I have a grapefruit and an apple',
                                'I have an apple and a grapefruit'))
     self.assertFalse(
         compare.check_patterns(cpatterns,
                                'I have a grapefruit and a banana',
                                'I have an apple and a grapefruit'))
Example #4
0
 def test_unanchored_patterns(self):
     compare = FilesComparison()
     cpatterns = compare.compile_patterns(['A\d{2}B', 'X[a-z]+Y'])
     for actual, expected in [('A22BC', 'A99BC'), ('XappleY', 'XtrafficY'),
                              ('A22BXappleY', 'A99BXtrafficY'),
                              ('froggyA22BXappleY', 'froggyA99BXtrafficY'),
                              ('frA22BXappleYoggy', 'frA99BXtrafficYoggy'),
                              ('A22BA99B', 'A99BA22B')]:
         self.assertTrue(
             compare.check_patterns(cpatterns, actual, expected),
             '%s <--> %s' % (actual, expected))
     for actual, expected in [('A222BC', 'A99BC'), ('222BC', 'A99BC'),
                              ('XappleYXappleY', 'XappleY')]:
         self.assertFalse(
             compare.check_patterns(cpatterns, actual, expected),
             '%s <--> %s' % (actual, expected))
Example #5
0
 def test_anchored_patterns(self):
     compare = FilesComparison()
     cpatterns = compare.compile_patterns([r'^\d+$'])
     for actual, expected in [('2', '222222222222'),
                              ('2', '2'),
                              ('02', '2'),
                              ('2', '23'),
                              ('123', '564')]:
         self.assertTrue(compare.check_patterns(cpatterns,
                                                actual, expected),
                         '%s <--> %s' % (actual, expected))
     for actual, expected in [('2', '222222222222a22'),
                              ('', '23'),
                              ('123', '')]:
         self.assertFalse(compare.check_patterns(cpatterns,
                                                 actual, expected),
                          '%s <--> %s' % (actual, expected))
Example #6
0
 def test_unanchored_patterns(self):
     compare = FilesComparison()
     cpatterns = compare.compile_patterns(['A\d{2}B', 'X[a-z]+Y'])
     for actual, expected in [('A22BC', 'A99BC'),
                              ('XappleY', 'XtrafficY'),
                              ('A22BXappleY', 'A99BXtrafficY'),
                              ('froggyA22BXappleY', 'froggyA99BXtrafficY'),
                              ('frA22BXappleYoggy', 'frA99BXtrafficYoggy'),
                              ('A22BA99B', 'A99BA22B')]:
         self.assertTrue(compare.check_patterns(cpatterns,
                                                actual, expected),
                         '%s <--> %s' % (actual, expected))
     for actual, expected in [('A222BC', 'A99BC'),
                              ('222BC', 'A99BC'),
                              ('XappleYXappleY', 'XappleY')]:
         self.assertFalse(compare.check_patterns(cpatterns,
                                                 actual, expected),
                          '%s <--> %s' % (actual, expected))
Example #7
0
 def test_single_pattern(self):
     compare = FilesComparison()
     cpatterns = compare.compile_patterns(['gr.*t'])
     self.assertTrue(compare.check_patterns(cpatterns,
                                            'great', 'grapefruit'))
Example #8
0
 def test_single_pattern(self):
     compare = FilesComparison()
     cpatterns = compare.compile_patterns(['gr.*t'])
     self.assertTrue(
         compare.check_patterns(cpatterns, 'great', 'grapefruit'))