def test_too_long_matching_start(self):
        expected = "java.lang."
        line = make_string(expected + "Exception\n")

        matcher = ContinueThrough(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("Exception\n", actual)
    def test_first_line_match_second_line_no_match(self):
        expected = "java.lang.Exception\n"
        expected_next = "haha Not a java.lang.Exception\n"

        line = make_string(expected + expected_next)
        matcher = ContinueThrough(self.start_pattern,
                                  self.continuation_pattern)
        current_time = time.time()

        actual = matcher.readline(line, current_time)
        self.assertEqual('', actual)

        actual = line.readline()
        self.assertEqual(expected, actual)
    def test_too_long_after_matching_continue(self):
        expected = "java.lang.Exception\n    at com"
        remainder = ".foo.baz(baz.java:123)\n"
        line = make_string(expected + remainder)

        matcher = ContinueThrough(self.start_pattern,
                                  self.continuation_pattern,
                                  max_line_length=30)
        current_time = time.time()

        actual = matcher.readline(line, current_time)
        self.assertEqual(expected, actual)

        actual = line.readline()
        self.assertEqual(remainder, actual)
    def test_no_match(self):
        line1 = "   starts with a space\n"
        line2 = "   also starts with a space\n"
        line = make_string(line1 + line2)
        matcher = ContinueThrough(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_continue_through(self):
        expected = "java.lang.Exception\n    at com.foo.bar(bar.java:123)\n    at com.foo.baz(baz.java:123)\n"
        expected_next = "next line\n"
        line = make_string(expected + expected_next)

        matcher = ContinueThrough(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 = "java.lang.Exception\n    at com.foo.bar(bar.java:123)\n    at com.foo.baz(baz.java:456)\n"
        expected_last = "Another line\n"

        line = make_string(expected)
        matcher = ContinueThrough(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, actual)

        actual = line.readline()
        self.assertEqual(expected_last, actual)
    def test_timeout_after_matching_continue(self):
        expected = "java.lang.Exception\n    at com.foo.bar(bar.java:123)\n"
        line = make_string(expected)

        matcher = ContinueThrough(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)

        expected_next = "  starts with a space\n"
        line = append_string(line, expected_next)
        actual = matcher.readline(line, current_time)
        self.assertEqual('', actual)

        actual = line.readline()
        self.assertEqual(expected_next, actual)
 def continue_through(self,
                      start="^--multi",
                      cont="^--",
                      length=1024,
                      timeout=60):
     return ContinueThrough(start, cont, length, timeout)