def test_too_long_after_matching_continue( self ): expected = "--begin\nmultiline\nthis line " remainder = "will be cut\n" line = make_string( expected + remainder ) matcher = HaltWith( self.start_pattern, self.continuation_pattern, max_line_length = 28 ) current_time = time.time() actual = matcher.readline( line, current_time ) self.assertEqual( expected, actual ) actual = line.readline() self.assertEqual( remainder, actual )
def test_first_line_match_second_line_no_match(self): expected = "--begin\n" expected_next = "--end\n" line = make_string(expected + expected_next) matcher = HaltWith(self.start_pattern, self.continuation_pattern) current_time = time.time() actual = matcher.readline(line, current_time) self.assertEqual(expected + expected_next, actual) actual = matcher.readline(line, current_time) self.assertEqual('', actual)
def test_too_long_matching_start( self ): expected = "--begin" line = make_string( expected + " multiline\n" ) matcher = HaltWith( self.start_pattern, self.continuation_pattern, max_line_length = 7 ) current_time = time.time() actual = matcher.readline( line, current_time ) self.assertEqual( expected, actual ) actual = line.readline() self.assertEqual( " multiline\n", actual )
def test_first_line_match_second_line_no_match( self ): expected = "--begin\n" expected_next = "--end\n" line = make_string( expected + expected_next ) matcher = HaltWith( self.start_pattern, self.continuation_pattern ) current_time = time.time() actual = matcher.readline( line, current_time ) self.assertEqual( expected + expected_next, actual ) actual = matcher.readline( line, current_time ) self.assertEqual( '', actual )
def test_timeout_after_matching_continue( self ): expected = "--begin\nMultiline\n" line = make_string( expected ) matcher = HaltWith( 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 = HaltWith( 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_no_match(self): line1 = "single line\n" line2 = "another single line\n" line = make_string(line1 + line2) matcher = HaltWith(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_halt_before(self): expected = "--begin\nThis is a multiline message\nThat will end when the\nnext one starts\n--end\n" expected_next = "next line\n" line = make_string(expected + expected_next) matcher = HaltWith(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_halt_before( self ): expected = "--begin\nThis is a multiline message\nThat will end when the\nnext one starts\n--end\n" expected_next = "next line\n" line = make_string( expected + expected_next ) matcher = HaltWith( 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_too_long_matching_start(self): expected = "--begin" line = make_string(expected + " multiline\n") matcher = HaltWith(self.start_pattern, self.continuation_pattern, max_line_length=7) 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 = "--begin\nmultiline\nthis line " remainder = "will be cut\n" line = make_string(expected + remainder) matcher = HaltWith(self.start_pattern, self.continuation_pattern, max_line_length=28) current_time = time.time() actual = matcher.readline(line, current_time) self.assertEqual(expected, actual) actual = line.readline() self.assertEqual(remainder, actual)
def test_timeout_after_matching_continue(self): expected = "--begin\nMultiline\n" line = make_string(expected) matcher = HaltWith(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_partial_multiline_match(self): expected = "--begin\ncontinuation of a multiline line\nstill continuing\n" expected_end = "--end\n" line = make_string(expected) matcher = HaltWith(self.start_pattern, self.continuation_pattern) current_time = time.time() actual = matcher.readline(line, current_time) self.assertEqual('', actual) line = append_string(line, expected_end) actual = matcher.readline(line, current_time) self.assertEqual(expected + expected_end, actual) actual = line.readline() self.assertEqual('', actual)
def test_partial_multiline_match( self ): expected = "--begin\ncontinuation of a multiline line\nstill continuing\n" expected_end = "--end\n" line = make_string( expected ) matcher = HaltWith( self.start_pattern, self.continuation_pattern ) current_time = time.time() actual = matcher.readline( line, current_time ) self.assertEqual( '', actual ) line = append_string( line, expected_end ) actual = matcher.readline( line, current_time ) self.assertEqual( expected + expected_end, actual ) actual = line.readline() self.assertEqual( '', actual )
def test_partial_first_line_match( self ): expected = "--begin\n" expected_next = "--end\n" expected_last = "next line\n" line = make_string( expected ) matcher = HaltWith( self.start_pattern, self.continuation_pattern ) current_time = time.time() actual = matcher.readline( line, current_time ) self.assertEqual( '', 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 test_partial_first_line_match(self): expected = "--begin\n" expected_next = "--end\n" expected_last = "next line\n" line = make_string(expected) matcher = HaltWith(self.start_pattern, self.continuation_pattern) current_time = time.time() actual = matcher.readline(line, current_time) self.assertEqual('', 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 halt_with(self, start="^--start", cont="^--end", length=1024, timeout=60): return HaltWith(start, cont, length, timeout)