Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _(mock):
args = (1, 2, 3)
kwargs = {"hello": "world"}
mock(1, 2, **kwargs) # 3 is missing intentionally
e = expect(mock)
with raises(ExpectationFailed):
e.called_once_with(*args, **kwargs)
hist = [
Expected(
mock,
op="called_once_with",
that=None,
op_args=args,
op_kwargs=kwargs,
success=False,
)
]
expect(e.history).equals(hist)
def _():
this, that = "hello", "goodbye"
e = expect(this)
with raises(ExpectationFailed):
e.equals(that)
hist = [
Expected(
this=this, op="equals", that=that, op_args=(), op_kwargs={}, success=False
)
]
expect(e.history).equals(hist)
def _fail_if_false(self, val: bool) -> bool:
if val:
return True
raise ExpectationFailed("expectation failed", self.history)
def _fail_if_false(self, val: bool) -> bool:
if val:
return True
raise ExpectationFailed("expectation failed", self.history)
def output_why_test_failed(self, test_result: TestResult):
err = test_result.error
if isinstance(err, ExpectationFailed):
print(
f" Given {truncate(repr(err.history[0].this), num_chars=self.terminal_size.width - 24)}\n"
)
for expect in err.history:
self.print_expect_chain_item(expect)
last_check = err.history[-1].op # the check that failed
if last_check == "equals":
self.print_failure_equals(err)
else:
self.print_traceback(err)
print(Style.RESET_ALL)