コード例 #1
0
    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 )
コード例 #2
0
    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)
コード例 #3
0
    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 )
コード例 #4
0
    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 )
コード例 #5
0
    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 )
コード例 #6
0
    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 )
コード例 #7
0
    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)
コード例 #8
0
    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)
コード例 #9
0
    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 )
コード例 #10
0
    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)
コード例 #11
0
    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)
コード例 #12
0
    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)
コード例 #13
0
    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)
コード例 #14
0
    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 )
コード例 #15
0
    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 )
コード例 #16
0
    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)
コード例 #17
0
 def halt_with(self,
               start="^--start",
               cont="^--end",
               length=1024,
               timeout=60):
     return HaltWith(start, cont, length, timeout)