How to use the ward.expect.Expected 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 _():
    this, that = 1, 1

    e = expect(this)
    with raises(ExpectationFailed):
        e.not_equals(that)

    hist = [
        Expected(
            this, op="not_equals", that=that, op_args=(), op_kwargs={}, success=False
        )
    ]
    expect(e.history).equals(hist)
github darrenburns / ward / tests / test_expect.py View on Github external
def _(mock):
    args = (1, 2, 3)
    kwargs = {"hello": "world"}

    mock(1)
    mock(*args, **kwargs)
    mock(2)

    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 = "olleh"
    predicate = lambda e: this[::-1] == "hello"
    e = expect(this).satisfies(predicate)

    hist = [
        Expected(
            this=this,
            op="satisfies",
            that=predicate,
            op_args=(),
            op_kwargs={},
            success=True,
        )
    ]

    expect(e.history).equals(hist)
github darrenburns / ward / ward / expect.py View on Github external
def _store_in_history(
        self,
        result: bool,
        called_with_args: Tuple[Any],
        called_with_kwargs: Dict[str, Any],
        that=None,
    ) -> bool:
        self.history.append(
            Expected(
                this=self.this,
                op=inspect.stack()[2].function,  # :)
                that=that,
                success=result,
                op_args=called_with_args,
                op_kwargs=called_with_kwargs,
            )
        )
        return result
github darrenburns / ward / ward / expect.py View on Github external
def _store_in_history(
        self,
        result: bool,
        called_with_args: Tuple[Any],
        called_with_kwargs: Dict[str, Any],
        that: Any = None,
    ) -> bool:
        self.history.append(
            Expected(
                this=self.this,
                op=inspect.stack()[2].function,  # :)
                that=that,
                success=result,
                op_args=called_with_args,
                op_kwargs=called_with_kwargs,
            )
        )
        return result
github darrenburns / ward / ward / expect.py View on Github external
def __init__(self, this: Any):
        self.this = this
        self.history: List[Expected] = []
github darrenburns / ward / ward / expect.py View on Github external
def __init__(self, this: Any):
        self.this = this
        self.history: List[Expected] = []