def check_patterns(self, event, test_connection): """ Defines the base set of pattern responses. Stores the results of testcases inside the TestAction Call from subclasses before checking subclass-specific events. """ ret_val = False if event == "eof": self.logger.warning( "err: lava test monitoring reached end of file") self.errors = "lava test monitoring reached end of file" self.results.update({"status": "failed"}) raise ConnectionClosedError("Connection closed") elif event == "timeout": self.logger.warning("err: lava test monitoring has timed out") self.errors = "lava test monitoring has timed out" self.results.update({"status": "failed"}) elif event == "end": self.logger.info( "ok: end string found, lava test monitoring stopped") self.results.update({"status": "passed"}) elif event == "test_result": self.logger.info("ok: test case found") match = test_connection.match.groupdict() if "result" in match: if self.fixupdict: if match["result"] in self.fixupdict: match["result"] = self.fixupdict[match["result"]] if match["result"] not in ("pass", "fail", "skip", "unknown"): self.logger.error("error: bad test results: %s", match["result"]) else: if "test_case_id" in match: case_id = match["test_case_id"].strip().lower() # remove special characters to form a valid test case id case_id = re.sub(r"\W+", "_", case_id) self.logger.debug("test_case_id: %s", case_id) results = { "definition": self.test_suite_name.replace(" ", "-").lower(), "case": case_id, "level": self.level, "result": match["result"], "extra": { "test_case_id": match["test_case_id"].strip() }, } if "measurement" in match: results.update( {"measurement": match["measurement"]}) if "units" in match: results.update({"units": match["units"]}) self.logger.results(results) else: if all(x in match for x in ["test_case_id", "measurement"]): if match["measurement"] and match["test_case_id"]: case_id = match["test_case_id"].strip().lower() # remove special characters to form a valid test case id case_id = re.sub(r"\W+", "_", case_id) self.logger.debug("test_case_id: %s", case_id) results = { "definition": self.test_suite_name.replace(" ", "-").lower(), "case": case_id, "level": self.level, "result": "pass", "measurement": float(match["measurement"]), "extra": { "test_case_id": match["test_case_id"].strip() }, } if "units" in match: results.update({"units": match["units"]}) self.logger.results(results) ret_val = True return ret_val