From 498b8bd84c29a0d3b047c120b5540ab921d54575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pekka=20Kl=C3=A4rck?= Date: Wed, 5 Feb 2025 12:24:42 +0200 Subject: [PATCH] Fix handling FAIL log level if test passes Fixes #4. --- robotstatuschecker.py | 35 +++++++++++++++++++++++------------ test/status_and_message.robot | 5 +++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/robotstatuschecker.py b/robotstatuschecker.py index a8a289b..33bb73f 100755 --- a/robotstatuschecker.py +++ b/robotstatuschecker.py @@ -101,25 +101,36 @@ def visit_keyword(self, kw: Keyword): class Expected: def __init__(self, doc: str): - self.status = self._get_status(doc) - self.message = self._get_message(doc) - self.logs = self._get_logs(doc) - - def _get_status(self, doc: str) -> str: - if "FAIL" in doc: + status, logs = self._split_status_and_logs(doc) + self.status = self._get_status(status) + self.message = self._get_message(status) + self.logs = self._get_logs(logs) + + def _split_status_and_logs(self, doc: str) -> "tuple[str, str]": + if "LOG" not in doc: + return doc, "" + log_index = doc.find("LOG") + status_indices = [doc.find(status) for status in ("FAIL", "SKIP", "PASS") + if status in doc] + if not status_indices or log_index < min(status_indices): + return "", doc + return doc[:log_index], doc[log_index:] + + def _get_status(self, config: str) -> str: + if "FAIL" in config: return "FAIL" - if "SKIP" in doc: + if "SKIP" in config: return "SKIP" return "PASS" - def _get_message(self, doc: str) -> str: + def _get_message(self, config: str) -> str: for status in ["FAIL", "SKIP", "PASS"]: - if status in doc: - return doc.split(status, 1)[1].split("LOG", 1)[0].strip() + if status in config: + return config.split(status, 1)[1].strip() return "" - def _get_logs(self, doc: str) -> "list[ExpectedLog]": - return [ExpectedLog(item) for item in doc.split("LOG")[1:]] + def _get_logs(self, config: str) -> "list[ExpectedLog]": + return [ExpectedLog(item) for item in config.split("LOG")[1:]] class ExpectedLog: diff --git a/test/status_and_message.robot b/test/status_and_message.robot index 7847006..e140b6a 100644 --- a/test/status_and_message.robot +++ b/test/status_and_message.robot @@ -132,6 +132,11 @@ Status with log message Log Hello! Fail Expected +FAIL log level when test does not fail + [Documentation] LOG 2.1 FAIL This is caught! + Status PASS + Run Keyword And Ignore Error Fail This is caught! + *** Keywords *** Status