コード例 #1
0
    def test_stop_condition(self):

        grep = GrepCount(None, ANY_FILE_FILTER, None, 'cat', stop_object='lolcat', metrics_logger=Mock())
        grep.pre_files_scan('test-module')
        grep.wants_file('test.log')
        self.assertTrue(grep.on_read_line('catalogue'))
        self.assertFalse(grep.on_read_line('lolcat'))
        self.assertEqual(2, grep.value, 'should have 2 hits')
コード例 #2
0
    def test_matches_with_string(self):

        grep = GrepCount(None, ANY_FILE_FILTER, None, 'ism', metrics_logger=Mock())
        grep.pre_files_scan('test-module')
        grep.wants_file('test.log')
        self.assertTrue(grep.on_read_line('buddhism'))
        self.assertTrue(grep.on_read_line('ismypizzaready?'))
        self.assertTrue(grep.on_read_line('kissme'))
        self.assertTrue(grep.on_read_line('mismatch'))
        self.assertEqual(3, grep.value, 'should have 3 hits')
コード例 #3
0
    def test_grep_matches_with_function(self):
        grep_count_dates = GrepCount(None, ANY_FILE_FILTER, None, lambda line: '45' in line, metrics_logger=Mock())
        grep_count_dates.pre_files_scan('test-module')
        grep_count_dates.wants_file('test.log')

        #when
        self.assertTrue(grep_count_dates.on_read_line('sad 1345 sad '))
        self.assertTrue(grep_count_dates.on_read_line('sad 43445 sad '))
        self.assertTrue(grep_count_dates.on_read_line('sad 12335 sad '))

        #then
        self.assertEqual(grep_count_dates.value, 2, 'should have two hits')
コード例 #4
0
    def test_grep_matches_with_list_of_strings(self):
        grep_count_dates = GrepCount(None, ANY_FILE_FILTER, None, ['13', '2'], metrics_logger=Mock())
        grep_count_dates.pre_files_scan('test-module')
        grep_count_dates.wants_file('test.log')

        #when
        self.assertTrue(grep_count_dates.on_read_line('sad 1345 sad '))
        self.assertTrue(grep_count_dates.on_read_line('sad 434 sad '))
        self.assertTrue(grep_count_dates.on_read_line('sad 12345 sad '))

        #then
        self.assertEqual(grep_count_dates.value, 2, 'should have two hits')
コード例 #5
0
    def test_grep_regex_matches_with_list_of_regex_expressions(self):
        #having
        grep_count_dates = GrepCount(None, ANY_FILE_FILTER, None, ['1[1-9]{3}', '2+'], use_regex=True, metrics_logger=Mock())
        grep_count_dates.pre_files_scan('test-module')
        grep_count_dates.wants_file('test.log')

        #when
        self.assertTrue(grep_count_dates.on_read_line('sad 1345 sad '))
        self.assertTrue(grep_count_dates.on_read_line('sad 2345 sad '))
        self.assertTrue(grep_count_dates.on_read_line('sad 12345 sad '))

        #then
        self.assertEqual(grep_count_dates.value, 3, 'should have three hits')
コード例 #6
0
    def test_grep_with_regex_matches(self):
        #having
        grep_count_dates = GrepCount(None, ANY_FILE_FILTER, None, '1[1-9]{3}', use_regex=True, metrics_logger=Mock())
        grep_count_dates.pre_files_scan('test-module')
        grep_count_dates.wants_file('test.log')

        #when
        self.assertTrue(grep_count_dates.on_read_line('sad 1345 sad '))
        #then
        self.assertEqual(grep_count_dates.value, 1, 'should have one hit ')
コード例 #7
0
    def test_grep_with_regex_not_matches(self):
        #having
        grep_count_dates = GrepCount(None, ANY_FILE_FILTER, None, '1[1-9]{3]', use_regex=True, metrics_logger=Mock())
        grep_count_dates.pre_files_scan('test-module')
        grep_count_dates.wants_file('test.log')

        #when
        should_continue = grep_count_dates.on_read_line('2345')
        self.assertTrue(should_continue)
        self.assertEqual(grep_count_dates.value, 0, 'should not have any hits ')