Esempio n. 1
0
 def test_not_match_between(self, basic_logfile):
     """
     Does the LogMatcher return True when match is found
     between the given marks.
     """
     matcher = LogMatcher(log_path=basic_logfile)
     matcher.match(regex=re.compile(r"second"), timeout=0.5)
     matcher.mark("start")
     matcher.match(regex=re.compile(r"fourth"), timeout=0.5)
     matcher.mark("end")
     assert matcher.not_match_between(r"fifth", "start", "end")
     assert not matcher.not_match_between(r"third", "start", "end")
Esempio n. 2
0
 def test_get_between(self, basic_logfile):
     """Does the LogMatcher return the required content between marks."""
     matcher = LogMatcher(log_path=basic_logfile)
     matcher.match(regex=re.compile(r"second"), timeout=0.5)
     matcher.mark("start")
     matcher.match(regex=re.compile(r"fourth"), timeout=0.5)
     matcher.mark("end")
     content = matcher.get_between()
     assert content == "first\nsecond\nthird\nfourth\nfifth\n"
     content = matcher.get_between(None, "end")
     assert content == "first\nsecond\nthird\nfourth\n"
     content = matcher.get_between("start", None)
     assert content == "third\nfourth\nfifth\n"
     content = matcher.get_between("start", "end")
     assert content == "third\nfourth\n"
Esempio n. 3
0
    def test_binary_match_found(self, basic_logfile):
        matcher = LogMatcher(log_path=basic_logfile)
        regex_exp = re.compile(b"second")
        match = matcher.match(regex=regex_exp)

        assert match is not None
        assert match.group(0) == b"second"
Esempio n. 4
0
    def test_match_between(self, basic_logfile):
        """
        Does the LogMatcher match between the given marks.
        """
        matcher = LogMatcher(log_path=basic_logfile)
        matcher.match(regex=re.compile(r"second"), timeout=0.5)
        matcher.mark("start")
        matcher.match(regex=re.compile(r"fourth"), timeout=0.5)
        matcher.mark("end")

        match = matcher.match_between(r"third", "start", "end")
        assert match.group(0) == "third"
        match = matcher.match_between(r"fourth", "start", "end")
        assert match.group(0) == "fourth"
        assert matcher.match_between(r"second", "start", "end") is None
        assert matcher.match_between(r"fifth", "start", "end") is None
Esempio n. 5
0
    def test_match_found(self, basic_logfile):
        """Can the LogMatcher find the correct line in the log file."""
        matcher = LogMatcher(log_path=basic_logfile)
        regex_exp = re.compile(r"second")
        match = matcher.match(regex=regex_exp)

        assert match is not None
        assert match.group(0) == "second"
Esempio n. 6
0
    def test_match_only_searches_after_position(self, basic_logfile):
        """
        LogMatcher should only search the text after the position, therefore it
        shouldn't find any successful matches for strings that appear before
        position x.
        """
        matcher = LogMatcher(log_path=basic_logfile)
        second_string = re.compile(r"second")
        match = matcher.match(regex=second_string)

        # It should find this string.
        assert match is not None
        assert match.group(0) == "second"

        # It shouldn't find this string as it has moved past this position.
        first_string = re.compile(r"first")
        with pytest.raises(timing.TimeoutException):
            matcher.match(regex=first_string, timeout=0.5)
Esempio n. 7
0
    def manual_start_using_context_manager(self, env, result):
        result.equal(env.cat_app.proc, None, description="App is not running.")

        with env.cat_app:
            matcher = LogMatcher(log_path=env.cat_app.logpath)
            env.cat_app.proc.stdin.write(b"testplan\n")
            matched = matcher.match(re.compile(r"testplan"))
            result.true(matched, description="testplan in stdin")
            result.not_equal(env.cat_app.proc,
                             None,
                             description="App is running.")

        result.equal(env.cat_app.proc, None, description="App is not running.")
Esempio n. 8
0
    def test_match_large_file(self, large_logfile):
        """
        Test matching the last entry in a large logfile, as a more realistic
        test. The LogMatcher should quickly iterate through lines in the
        logfile and return the match without timing out.
        """
        matcher = LogMatcher(log_path=large_logfile)

        # Check that the LogMatcher can find the last 'Match me!' line in a
        # reasonable length of time. 10s is a very generous timeout, most
        # of the time it should complete in <1s.
        match = matcher.match(regex=r"^Match me!$", timeout=10)

        assert match is not None
        assert match.group(0) == "Match me!"
Esempio n. 9
0
    def manual_start(self, env, result):
        result.equal(env.cat_app.proc, None, description="App is not running.")

        env.cat_app.start()
        env.cat_app.wait(env.cat_app.status.STARTED)

        matcher = LogMatcher(log_path=env.cat_app.logpath)
        env.cat_app.proc.stdin.write(b"testplan\n")
        matched = matcher.match(re.compile(r"testplan"))
        result.true(matched, description="testplan in stdin")
        result.not_equal(env.cat_app.proc, None, description="App is running.")

        env.cat_app.stop()
        env.cat_app.wait(env.cat_app.status.STOPPED)

        result.equal(env.cat_app.proc, None, description="App is not running.")
Esempio n. 10
0
 def test_binary_match_not_found(self, basic_logfile):
     """Does the LogMatcher raise an exception when no match is found."""
     matcher = LogMatcher(log_path=basic_logfile)
     regex_exp = re.compile(b"bob")
     with pytest.raises(timing.TimeoutException):
         matcher.match(regex=regex_exp, timeout=0.5)
Esempio n. 11
0
 def my_testcase(self, env, result):
     matcher = LogMatcher(log_path=env.echo.outpath)
     matched = matcher.match(re.compile(r"testplan"))
     result.true(matched, description="testplan in stdout")