mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 06:21:40 +00:00
core tests - more readable errors
E.g. it shows now: AttributeError: Interface 'bonsai.core.tool.Drawing' has no attribute 'weird_method'. Instead of: Prophecy <class 'abc.Drawing'> has no attribute weird_method
This commit is contained in:
@@ -28,7 +28,9 @@ from typing import Optional
|
|||||||
class Interface(abc.ABC): pass
|
class Interface(abc.ABC): pass
|
||||||
def interface(cls):
|
def interface(cls):
|
||||||
attrs = {n: classmethod(abc.abstractmethod(f)) for n, f in inspect.getmembers(cls, predicate=inspect.isfunction)}
|
attrs = {n: classmethod(abc.abstractmethod(f)) for n, f in inspect.getmembers(cls, predicate=inspect.isfunction)}
|
||||||
return type(cls.__name__, (Interface, cls), attrs)
|
new_cls = type(cls.__name__, (Interface, cls), attrs)
|
||||||
|
new_cls.__original_qualname__ = cls.__module__ + "." + cls.__qualname__
|
||||||
|
return new_cls
|
||||||
|
|
||||||
|
|
||||||
# ############################################################################ #
|
# ############################################################################ #
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ class Prophecy:
|
|||||||
|
|
||||||
def __getattr__(self, attr: str):
|
def __getattr__(self, attr: str):
|
||||||
if not hasattr(self.subject, attr):
|
if not hasattr(self.subject, attr):
|
||||||
raise AttributeError(f"Prophecy {self.subject} has no attribute {attr}")
|
raise AttributeError(f"Interface '{self.subject.__original_qualname__}' has no attribute '{attr}'.")
|
||||||
|
|
||||||
# It also returns `Any` but it only happens during `subject.xxx` call.
|
# It also returns `Any` but it only happens during `subject.xxx` call.
|
||||||
def decorate(*args: Any, **kwargs: Any) -> Self:
|
def decorate(*args: Any, **kwargs: Any) -> Self:
|
||||||
@@ -317,7 +317,7 @@ class Prophecy:
|
|||||||
raise Exception(f"Called {count}: {prediction}")
|
raise Exception(f"Called {count}: {prediction}")
|
||||||
else:
|
else:
|
||||||
if prediction["call"] not in self.calls:
|
if prediction["call"] not in self.calls:
|
||||||
error_msg = f"{self.subject} was not called with {prediction['call']['name']}:\n - {prediction}"
|
error_msg = f"Interface '{self.subject.__original_qualname__}' was not called with {prediction['call']['name']}:\n - {prediction}"
|
||||||
|
|
||||||
# Print all unprocessed calls if pytest was started in verbose mode.
|
# Print all unprocessed calls if pytest was started in verbose mode.
|
||||||
if "-v" in sys.argv or "-vv" in sys.argv:
|
if "-v" in sys.argv or "-vv" in sys.argv:
|
||||||
|
|||||||
Reference in New Issue
Block a user