How to use the ward.expect.ExpectationFailed function in ward

To help you get started, we’ve selected a few ward examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github darrenburns / ward / tests / test_expect.py View on Github external
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)
github darrenburns / ward / tests / test_expect.py View on Github external
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)
github darrenburns / ward / ward / expect.py View on Github external
def _fail_if_false(self, val: bool) -> bool:
        if val:
            return True
        raise ExpectationFailed("expectation failed", self.history)
github darrenburns / ward / ward / expect.py View on Github external
def _fail_if_false(self, val: bool) -> bool:
        if val:
            return True
        raise ExpectationFailed("expectation failed", self.history)
github darrenburns / ward / ward / terminal.py View on Github external
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)