예제 #1
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"
예제 #2
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"
예제 #3
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.")
예제 #4
0
 def test_not_match(self, basic_logfile):
     """Does the LogMatcher raise an exception when match is found."""
     matcher = LogMatcher(log_path=basic_logfile)
     matcher.not_match(regex=re.compile(r"bob"), timeout=0.5)
     matcher.seek()
     with pytest.raises(Exception):
         matcher.not_match(regex=re.compile(r"third"), timeout=0.5)
예제 #5
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!"
예제 #6
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.")
예제 #7
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)
예제 #8
0
    def log_matcher(self):
        """
        Create if not exist and return the LogMatcher object that reads the
        log / stdout of the driver.

        :return: LogMatcher instance
        :rtype: ``LogMatcher``
        """
        if not self._log_matcher:
            self._log_matcher = LogMatcher(self.logpath)
        return self._log_matcher
예제 #9
0
 def test_match_all(self, basic_logfile):
     """Can the LogMatcher find all the correct lines in the log file."""
     matcher = LogMatcher(log_path=basic_logfile)
     matches = matcher.match_all(regex=re.compile(r".+ir.+"), timeout=0.5)
     assert len(matches) == 2
     assert matches[0].group(0) == "first"
     assert matches[1].group(0) == "third"
     matcher.seek()
     matches = matcher.match_all(regex=re.compile(r".+th.*"), timeout=0.5)
     assert len(matches) == 2
     assert matches[0].group(0) == "fourth"
     assert matches[1].group(0) == "fifth"
예제 #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)
예제 #11
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"
예제 #12
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")
예제 #13
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
예제 #14
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")