示例#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
文件: base.py 项目: Birdback/pan-scan
 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
文件: base.py 项目: Birdback/pan-scan
 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
文件: base.py 项目: Birdback/pan-scan
    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
文件: base.py 项目: Birdback/pan-scan
 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
文件: base.py 项目: Birdback/pan-scan
 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
文件: base.py 项目: Birdback/pan-scan
 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
文件: base.py 项目: Birdback/pan-scan
    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
文件: base.py 项目: Birdback/pan-scan
 def test_search_string_no_matches(self):
     ps = PanScanner()
     matches = ps.search_string('there is no match :(')
     self.assertEqual(len(matches), 0)
示例#17
0
文件: base.py 项目: Birdback/pan-scan
 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
文件: base.py 项目: Birdback/pan-scan
 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
文件: base.py 项目: Birdback/pan-scan
 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
文件: base.py 项目: Birdback/pan-scan
 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
文件: base.py 项目: Birdback/pan-scan
 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
文件: base.py 项目: Birdback/pan-scan
 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
文件: base.py 项目: Birdback/pan-scan
 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
文件: base.py 项目: Birdback/pan-scan
 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"])