Пример #1
0
 def test_search_string_non_luhn(self):
     ps = PanScanner()
     n = '4111111111111113'
     test_match = ps.reqex.match(n)
     self.assertTrue(test_match)
     matches = ps.search_string(n)
     self.assertEqual(len(matches), 0)
Пример #2
0
 def test_search_string_non_luhn(self):
     ps = PanScanner()
     n = '4111111111111113'
     test_match = ps.reqex.match(n)
     self.assertTrue(test_match)
     matches = ps.search_string(n)
     self.assertEqual(len(matches), 0)
Пример #3
0
 def test_iter_dir_absolute_path(self):
     ps = PanScanner()
     directory = get_absolute_path('test_dir')
     self.assertEqual(
         [v for v in ps.iter_dir(directory)],
         [get_absolute_path('test_dir/binary.png'),
          get_absolute_path('test_dir/without.py'),
          get_absolute_path('test_dir/deeper/contains.log')])
Пример #4
0
 def test_iter_dir_absolute_path(self):
     ps = PanScanner()
     directory = get_absolute_path('test_dir')
     self.assertEqual([v for v in ps.iter_dir(directory)], [
         get_absolute_path('test_dir/binary.png'),
         get_absolute_path('test_dir/without.py'),
         get_absolute_path('test_dir/deeper/contains.log')
     ])
Пример #5
0
    def test_search_file_binary(self):
        searched_lines = []
        ps = PanScanner()
        ps.search_string = lambda l: searched_lines.append(l)

        filename = get_absolute_path('test_dir/binary.png')
        ps.search_file(filename)
        self.assertEqual(searched_lines, [])
        self.assertEqual(len(ps.failed_to_open), 0)
Пример #6
0
 def test_search_string_two_match(self):
     ps = PanScanner()
     matches = ps.search_string('there is one match: 4111111111111111'
                                'no two matches (!): 4111111111111111')
     self.assertEqual(len(matches), 2)
     self.assertEqual(matches[0].span(), (20, 36))
     self.assertEqual(matches[1].span(), (56, 72))
     self.assertEqual(matches[0].group(0), '4111111111111111')
     self.assertEqual(matches[1].group(0), '4111111111111111')
Пример #7
0
 def test_search_string_two_match(self):
     ps = PanScanner()
     matches = ps.search_string('there is one match: 4111111111111111'
                                'no two matches (!): 4111111111111111')
     self.assertEqual(len(matches), 2)
     self.assertEqual(matches[0].span(), (20, 36))
     self.assertEqual(matches[1].span(), (56, 72))
     self.assertEqual(matches[0].group(0), '4111111111111111')
     self.assertEqual(matches[1].group(0), '4111111111111111')
Пример #8
0
    def test_search_file_binary(self):
        searched_lines = []
        ps = PanScanner()
        ps.search_string = lambda l: searched_lines.append(l)

        filename = get_absolute_path('test_dir/binary.png')
        ps.search_file(filename)
        self.assertEqual(searched_lines, [])
        self.assertEqual(len(ps.failed_to_open), 0)
Пример #9
0
 def test_search_file_text(self):
     ps = PanScanner()
     filename = get_absolute_path('test_dir/deeper/contains.log')
     ps.search_file(filename)
     self.assertEqual(ps._log, [
         'Found card number in %s:\n' % filename,
         '* Card number found at line 1 in interval: (28, 44)\n',
         '* Card number found at line 2 in interval: (16, 32), (57, 73)\n'
     ])
     self.assertEqual(len(ps.failed_to_open), 0)
Пример #10
0
 def test_search(self):
     directory = get_absolute_path('test_dir')
     ps = PanScanner([directory])
     ps.search()
     self.assertEqual(ps._log, [
         'Found card number in %s:\n' %
         get_absolute_path('test_dir/deeper/contains.log'),
         '* Card number found at line 1 in interval: (28, 44)\n',
         '* Card number found at line 2 in interval: (16, 32), (57, 73)\n'
     ])
Пример #11
0
 def test_search_file_text(self):
     ps = PanScanner()
     filename = get_absolute_path('test_dir/deeper/contains.log')
     ps.search_file(filename)
     self.assertEqual(ps._log, [
         'Found card number in %s:\n' % filename,
         '* Card number found at line 1 in interval: (28, 44)\n',
         '* Card number found at line 2 in interval: (16, 32), (57, 73)\n'
     ])
     self.assertEqual(len(ps.failed_to_open), 0)
Пример #12
0
 def test_search(self):
     directory = get_absolute_path('test_dir')
     ps = PanScanner([directory])
     ps.search()
     self.assertEqual(ps._log, [
         'Found card number in %s:\n' %
         get_absolute_path('test_dir/deeper/contains.log'),
         '* Card number found at line 1 in interval: (28, 44)\n',
         '* Card number found at line 2 in interval: (16, 32), (57, 73)\n'
     ])
Пример #13
0
    def test_matches_to_string(self):
        class Match:
            def __init__(self, span):
                self._span = span

            def span(self):
                return self._span
        matches = [Match((1, 2)), Match((10, 11))]
        ps = PanScanner()
        matches_string = ps.matches_to_string(matches)
        self.assertEqual(matches_string, '(1, 2), (10, 11)')
Пример #14
0
    def test_matches_to_string(self):
        class Match:
            def __init__(self, span):
                self._span = span

            def span(self):
                return self._span

        matches = [Match((1, 2)), Match((10, 11))]
        ps = PanScanner()
        matches_string = ps.matches_to_string(matches)
        self.assertEqual(matches_string, '(1, 2), (10, 11)')
Пример #15
0
 def test_search_missing_file(self):
     ps = PanScanner()
     path = get_absolute_path('test_dir/does_not_exist.txt')
     ps.search_file(path)
     self.assertEqual(ps.failed_to_open, [path])
Пример #16
0
 def test_search_string_no_matches(self):
     ps = PanScanner()
     matches = ps.search_string('there is no match :(')
     self.assertEqual(len(matches), 0)
Пример #17
0
 def test_search_string_one_match(self):
     ps = PanScanner()
     matches = ps.search_string('there is one match: 4111111111111111')
     self.assertEqual(len(matches), 1)
     self.assertEqual(matches[0].span(), (20, 36))
     self.assertEqual(matches[0].group(0), '4111111111111111')
Пример #18
0
 def test_search_string_ignore_test_card_numbers(self):
     ps = PanScanner(ignore_test_card_numbers=True)
     matches = ps.search_string('4111111111111111')
     self.assertEqual(len(matches), 0)
     matches = ps.search_string('4716334938933348')
     self.assertEqual(len(matches), 1)
Пример #19
0
 def test_search_string_number_surrounded(self):
     ps = PanScanner()
     matches = ps.search_string('3334111111111111111333')
     self.assertEqual(len(matches), 0)
Пример #20
0
 def test_search_string_letter_surrounded(self):
     ps = PanScanner()
     matches = ps.search_string('asd4111111111111111asd')
     self.assertEqual(len(matches), 1)
     self.assertEqual(matches[0].group(0), '4111111111111111')
Пример #21
0
 def test_search_string_comma_surrounded(self):
     ps = PanScanner()
     matches = ps.search_string(',4111111111111111')
     self.assertEqual(len(matches), 0)
     matches = ps.search_string('4111111111111111,')
     self.assertEqual(len(matches), 0)
Пример #22
0
 def test_search_string_number_surrounded(self):
     ps = PanScanner()
     matches = ps.search_string('3334111111111111111333')
     self.assertEqual(len(matches), 0)
Пример #23
0
 def test_search_string_comma_surrounded(self):
     ps = PanScanner()
     matches = ps.search_string(',4111111111111111')
     self.assertEqual(len(matches), 0)
     matches = ps.search_string('4111111111111111,')
     self.assertEqual(len(matches), 0)
Пример #24
0
 def test_search_string_letter_surrounded(self):
     ps = PanScanner()
     matches = ps.search_string('asd4111111111111111asd')
     self.assertEqual(len(matches), 1)
     self.assertEqual(matches[0].group(0), '4111111111111111')
Пример #25
0
 def test_search_string_no_matches(self):
     ps = PanScanner()
     matches = ps.search_string('there is no match :(')
     self.assertEqual(len(matches), 0)
Пример #26
0
 def test_search_string_one_match(self):
     ps = PanScanner()
     matches = ps.search_string('there is one match: 4111111111111111')
     self.assertEqual(len(matches), 1)
     self.assertEqual(matches[0].span(), (20, 36))
     self.assertEqual(matches[0].group(0), '4111111111111111')
Пример #27
0
 def test_log_failed_to_open_none(self):
     ps = PanScanner()
     ps.failed_to_open = []
     ps.log_failed_to_open()
     self.assertEqual(len(ps._log), 0)
Пример #28
0
 def test_log_failed_to_open_none(self):
     ps = PanScanner()
     ps.failed_to_open = []
     ps.log_failed_to_open()
     self.assertEqual(len(ps._log), 0)
Пример #29
0
 def test_search_string_ignore_test_card_numbers(self):
     ps = PanScanner(ignore_test_card_numbers=True)
     matches = ps.search_string('4111111111111111')
     self.assertEqual(len(matches), 0)
     matches = ps.search_string('4716334938933348')
     self.assertEqual(len(matches), 1)
Пример #30
0
 def test_search_missing_file(self):
     ps = PanScanner()
     path = get_absolute_path('test_dir/does_not_exist.txt')
     ps.search_file(path)
     self.assertEqual(ps.failed_to_open, [path])
Пример #31
0
 def test_log_failed_to_open_one(self):
     ps = PanScanner()
     ps.failed_to_open = ['/testfile.txt']
     ps.log_failed_to_open()
     self.assertEqual(ps._log, ["Failed to open:\n* /testfile.txt\n"])
Пример #32
0
 def test_log_failed_to_open_one(self):
     ps = PanScanner()
     ps.failed_to_open = ['/testfile.txt']
     ps.log_failed_to_open()
     self.assertEqual(ps._log, ["Failed to open:\n* /testfile.txt\n"])