From 70a52d6a1324dc79f075d6c2579baebe7669c601 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Wed, 1 Jun 2022 01:26:54 +0200 Subject: [PATCH] 100% Coverage --- src/bootstraparse/modules/error_mngr.py | 6 +++++- src/bootstraparse/modules/export.py | 4 +--- tests/modules/test_error_mngr.py | 13 +++++++++++++ tests/modules/test_export.py | 7 ++++++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/bootstraparse/modules/error_mngr.py b/src/bootstraparse/modules/error_mngr.py index 1a2da05..20c4a28 100644 --- a/src/bootstraparse/modules/error_mngr.py +++ b/src/bootstraparse/modules/error_mngr.py @@ -158,9 +158,11 @@ class MismatchedContainerError(BootstraparseError): self.token = token if token: self.line = token.line_number + self.label = token.label else: self.line = None - super().__init__(f"Could not process {token.label} at line {self.line}.") + self.label = None + super().__init__(f"Could not process {self.label} at line {self.line}.") class LonelyOptionalError(BootstraparseError): @@ -171,8 +173,10 @@ class LonelyOptionalError(BootstraparseError): self.token = token if token: self.line = token.line_number + self.label = token.label else: self.line = None + self.label = None if last_in_pile: super().__init__(f"Could not match token {token} at line {self.line} with " f"last element in pile {last_in_pile} at line {last_in_pile.line_number} (not a container).") diff --git a/src/bootstraparse/modules/export.py b/src/bootstraparse/modules/export.py index aa06b76..1903169 100644 --- a/src/bootstraparse/modules/export.py +++ b/src/bootstraparse/modules/export.py @@ -238,9 +238,7 @@ class ContextConverter: print(self) def __eq__(self, other): - if hasattr(other, "__str__"): - return str(self) == str(other) - return False + return str(self) == str(other) if __name__ == '__main__': # pragma: no cover diff --git a/tests/modules/test_error_mngr.py b/tests/modules/test_error_mngr.py index 61f4e5a..d70baa1 100644 --- a/tests/modules/test_error_mngr.py +++ b/tests/modules/test_error_mngr.py @@ -102,5 +102,18 @@ def test_dict_str(): assert error_mngr.str_dict_check({"test": {"test3": "test5"}}, "test", "test3") == "test: True\ntest3: True" +def test_weird_exception_cases(): + with pytest.raises(error_mngr.MismatchedContainerError): + raise(error_mngr.MismatchedContainerError(None)) + + with pytest.raises(error_mngr.LonelyOptionalError): + raise(error_mngr.LonelyOptionalError(None, None)) + + from typing import NamedTuple + tk = NamedTuple("falsetoken", [("line_number", int), ("label", str)])(1, "test") + with pytest.raises(error_mngr.LonelyOptionalError): + raise(error_mngr.LonelyOptionalError(tk, None)) + + if __name__ == '__main__': TestLogging().test_init_logging() diff --git a/tests/modules/test_export.py b/tests/modules/test_export.py index 18e8f7e..a53b379 100644 --- a/tests/modules/test_export.py +++ b/tests/modules/test_export.py @@ -172,4 +172,9 @@ def test_context_cov(): convr.readlines() convr.__str__() convr.print_all() - _ = convr == convr + + class A: + pass + + assert convr == convr + assert convr != A()