How to use the ward.test 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_collect.py View on Github external
@test("search_generally query='fox' returns tests with 'fox' in the body")
def _(tests=tests_to_search, named=named_test):
    results = search_generally(tests, query="fox")
    expect(list(results)).equals([named])
github darrenburns / ward / tests / test_expect.py View on Github external
@test(
    "expect.called records history and raises ExpectationFailed when mock was not called"
)
def _(mock):
    e = expect(mock)
    with raises(ExpectationFailed):
        e.called()

    hist = [
        Expected(mock, op="called", that=None, op_args=(), op_kwargs={}, success=False)
    ]
    expect(e.history).equals(hist)
github darrenburns / ward / tests / test_util.py View on Github external
@test("truncate('{input}', num_chars={num_chars}) returns '{expected}'")
def _(
    input=s,
    num_chars=each(20, 11, 10, 5),
    expected=each(s, s, "hello w...", "he..."),
):
    result = truncate(input, num_chars)
    expect(result).equals(expected)
github darrenburns / ward / tests / test_expect.py View on Github external
@test("has_calls raises when the expected calls were made in the wrong order")
def _(mock):
    mock(1, 2)
    mock(key="value")

    e = expect(mock)
    with raises(ExpectationFailed):
        e.has_calls([call(key="value"), call(1, 2)])
github darrenburns / ward / tests / test_expect.py View on Github external
@test("expect.not_called records history, even when the mock wasn't called")
def _(mock):
    e = expect(mock).not_called()

    hist = [
        Expected(
            mock, op="not_called", that=None, op_args=(), op_kwargs={}, success=True
        )
    ]
    expect(e.history).equals(hist)
github darrenburns / ward / tests / test_collect.py View on Github external
@test("is_test_module returns True when module name begins with 'test_'")
def _():
    module = ModuleInfo(ModuleFinder(), "test_apples", False)
    expect(is_test_module(module)).equals(True)
github darrenburns / ward / tests / test_util.py View on Github external
@test("get_exit_code returns ExitCode.FAILED when XPASS in test results")
def _(example=example_test):
    test_results = [
        TestResult(test=example, outcome=TestOutcome.XPASS),
        TestResult(test=example, outcome=TestOutcome.PASS),
    ]
    exit_code = get_exit_code(test_results)

    expect(exit_code).equals(ExitCode.FAILED)
github darrenburns / ward / tests / test_expect.py View on Github external
@test("has_calls records history when all expected calls were made")
def _(mock):
    mock(1, 2)
    mock(key="value")

    e = expect(mock).has_calls([call(1, 2), call(key="value")])
    expect(e.history[0].success).equals(True)
github darrenburns / ward / tests / test_expect.py View on Github external
@test(
    "called_once_with records history and raises when the expected call is made more than once"
)
def _(mock):
    args = (1, 2, 3)
    kwargs = {"hello": "world"}

    mock(*args, **kwargs)
    mock(*args, **kwargs)

    e = expect(mock)
    with raises(ExpectationFailed):
        e.called_once_with(*args, **kwargs)

    hist = [
        Expected(
            mock,
github darrenburns / ward / tests / test_expect.py View on Github external
@test("approx records history and raises when args aren't within abs_tol")
def _():
    this, that, eps = 1.0, 1.01, 0.001

    e = expect(this)
    with raises(ExpectationFailed):
        e.approx(that, eps)

    hist = [
        Expected(
            this=this,
            op="approx",
            that=that,
            op_args=(),
            op_kwargs={"rel_tol": 0.001, "abs_tol": 0.0},
            success=False,
        )