def test_too_long_matching_start( self ): expected = "start of a" line = make_string( expected + " multiline\\\n" ) matcher = ContinuePast( self.start_pattern, self.continuation_pattern, max_line_length = 10 ) current_time = time.time() actual = matcher.readline( line, current_time ) self.assertEqual( expected, actual ) actual = line.readline() self.assertEqual( " multiline\\\n", actual )
def test_too_long_after_matching_continue( self ): expected = "start of a multiline\\\ncontinuing\\\nthis line " remainder = "will be cut\n" line = make_string( expected + remainder ) matcher = ContinuePast( self.start_pattern, self.continuation_pattern, max_line_length = 44 ) current_time = time.time() actual = matcher.readline( line, current_time ) self.assertEqual( expected, actual ) actual = line.readline() self.assertEqual( remainder, actual )
def test_too_long_matching_start(self): expected = "start of a" line = make_string(expected + " multiline\\\n") matcher = ContinuePast(self.start_pattern, self.continuation_pattern, max_line_length=10) current_time = time.time() actual = matcher.readline(line, current_time) self.assertEqual(expected, actual) actual = line.readline() self.assertEqual(" multiline\\\n", actual)
def test_no_match(self): line1 = "single line\n" line2 = "another single line\n" line = make_string(line1 + line2) matcher = ContinuePast(self.start_pattern, self.continuation_pattern) current_time = time.time() actual = matcher.readline(line, current_time) self.assertEqual('', actual) actual = matcher.readline(line, current_time) self.assertEqual('', actual) actual = line.readline() self.assertEqual(line1, actual)
def test_timeout_after_matching_continue( self ): expected = "start of a multiline\\\ncontinuation of a multiline\\\n" line = make_string( expected ) matcher = ContinuePast( self.start_pattern, self.continuation_pattern, line_completion_wait_time = 5 ) current_time = time.time() actual = matcher.readline( line, current_time - 6 ) self.assertEqual( '', actual ) actual = matcher.readline( line, current_time ) self.assertEqual( expected, actual ) actual = line.readline() self.assertEqual( '', actual )
def test_no_match( self ): line1 = "single line\n" line2 = "another single line\n" line = make_string( line1 + line2 ) matcher = ContinuePast( self.start_pattern, self.continuation_pattern ) current_time = time.time() actual = matcher.readline( line, current_time ) self.assertEqual( '', actual ) actual = matcher.readline( line, current_time ) self.assertEqual( '', actual ) actual = line.readline() self.assertEqual( line1, actual )
def test_too_long_after_matching_continue(self): expected = "start of a multiline\\\ncontinuing\\\nthis line " remainder = "will be cut\n" line = make_string(expected + remainder) matcher = ContinuePast(self.start_pattern, self.continuation_pattern, max_line_length=44) current_time = time.time() actual = matcher.readline(line, current_time) self.assertEqual(expected, actual) actual = line.readline() self.assertEqual(remainder, actual)
def test_continue_past(self): expected = "This is a multiline \\\nstring with each line\\\nseparated by backslashes\n" expected_next = "next line\n" line = make_string(expected + expected_next) matcher = ContinuePast(self.start_pattern, self.continuation_pattern) current_time = time.time() actual = matcher.readline(line, current_time) self.assertEqual(expected, actual) actual = matcher.readline(line, current_time) self.assertEqual('', actual) actual = line.readline() self.assertEqual(expected_next, actual)
def test_continue_past( self ): expected = "This is a multiline \\\nstring with each line\\\nseparated by backslashes\n" expected_next = "next line\n" line = make_string( expected + expected_next ) matcher = ContinuePast( self.start_pattern, self.continuation_pattern ) current_time = time.time() actual = matcher.readline( line, current_time ) self.assertEqual( expected, actual ) actual = matcher.readline( line, current_time ) self.assertEqual( '', actual ) actual = line.readline() self.assertEqual( expected_next, actual )
def test_timeout_after_matching_continue(self): expected = "start of a multiline\\\ncontinuation of a multiline\\\n" line = make_string(expected) matcher = ContinuePast(self.start_pattern, self.continuation_pattern, line_completion_wait_time=5) current_time = time.time() actual = matcher.readline(line, current_time - 6) self.assertEqual('', actual) actual = matcher.readline(line, current_time) self.assertEqual(expected, actual) actual = line.readline() self.assertEqual('', actual)
def test_first_line_match_second_line_no_match(self): expected = "multiline string \\\nthat ends here\n" expected_next = "single line string\n" line = make_string(expected + expected_next) matcher = ContinuePast(self.start_pattern, self.continuation_pattern) current_time = time.time() actual = matcher.readline(line, current_time) self.assertEqual(expected, actual) actual = matcher.readline(line, current_time) self.assertEqual('', actual) actual = line.readline() self.assertEqual(expected_next, actual)
def test_first_line_match_second_line_no_match( self ): expected = "multiline string \\\nthat ends here\n" expected_next = "single line string\n" line = make_string( expected + expected_next ) matcher = ContinuePast( self.start_pattern, self.continuation_pattern ) current_time = time.time() actual = matcher.readline( line, current_time ) self.assertEqual( expected, actual ) actual = matcher.readline( line, current_time ) self.assertEqual( '', actual ) actual = line.readline() self.assertEqual( expected_next, actual )
def test_partial_multiline_match(self): expected = "start of a multiline line\\\ncontinuation of a multiline line\\\nstill continuing\\\n" expected_last = "Another line\n" line = make_string(expected) matcher = ContinuePast(self.start_pattern, self.continuation_pattern) current_time = time.time() actual = matcher.readline(line, current_time) self.assertEqual('', actual) line = append_string(line, expected_last) actual = matcher.readline(line, current_time) self.assertEqual(expected + expected_last, actual) actual = line.readline() self.assertEqual('', actual)
def test_partial_multiline_match( self ): expected = "start of a multiline line\\\ncontinuation of a multiline line\\\nstill continuing\\\n" expected_last = "Another line\n" line = make_string( expected ) matcher = ContinuePast( self.start_pattern, self.continuation_pattern ) current_time = time.time() actual = matcher.readline( line, current_time ) self.assertEqual( '', actual ) line = append_string( line, expected_last ) actual = matcher.readline( line, current_time ) self.assertEqual( expected + expected_last, actual ) actual = line.readline() self.assertEqual( '', actual )
def test_partial_first_line_match(self): expected = b"start of a multiline\\\n" expected_next = b"last line\n" expected_last = b"Another line\n" line = make_string(expected) matcher = ContinuePast(self.start_pattern, self.continuation_pattern) current_time = time.time() actual = matcher.readline(line, current_time) self.assertEqual(b"", actual) line = append_string(line, expected_next + expected_last) actual = matcher.readline(line, current_time) self.assertEqual(expected + expected_next, actual) actual = line.readline() self.assertEqual(expected_last, actual)
def continue_past(self, start=r"\\$", cont=r"\\$", length=1024, timeout=60): return ContinuePast(start, cont, length, timeout)