How to use the ward.expect 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_testing.py View on Github external
def _(anonymous_test=anonymous_test):
    expect(anonymous_test.has_deps).equals(False)
github darrenburns / ward / tests / test_suite.py View on Github external
Test(fn=test3, module_name="module2"),
        ]
    )

    list(suite.generate_test_runs())

    expect(events).equals(
        [
            "resolve",  # Resolve at start of run only
            "test1",
            "test2",
            "test3",
            "teardown",  # Teardown only at end of run
        ]
    )
    expect(len(suite.cache)).equals(0)  # Teardown includes cache cleanup
github darrenburns / ward / tests / test_suite.py View on Github external
def _(suite=suite):
    results = list(suite.generate_test_runs())
    expected = [
        TestResult(test=test, outcome=TestOutcome.PASS, error=None, message="")
        for test in suite.tests
    ]
    expect(results).equals(expected)
github darrenburns / ward / tests / test_expect.py View on Github external
def _(mock):
    mock(2)
    mock(1)
    e = expect(mock)
    with raises(ExpectationFailed):
        e.called_with(2)
    expect(e.history[0].success).equals(False)
github darrenburns / ward / tests / test_testing.py View on Github external
def _(dependent_test=dependent_test):
    deps = dependent_test.deps()
    expect(deps).contains("a")
github darrenburns / ward / tests / test_expect.py View on Github external
def _(isclose):
    this, that = 1.0, 1.2
    abs_tol = 0.01

    with raises(ExpectationFailed):
        expect(this).not_approx(that, abs_tol=abs_tol)

    expect(isclose).called_once_with(this, that, abs_tol=abs_tol, rel_tol=1e-9)
github darrenburns / ward / tests / test_suite.py View on Github external
def _(skipped=skipped_test, example=example_test):
    suite = Suite(tests=[example, skipped])

    test_runs = list(suite.generate_test_runs())
    expected_runs = [
        TestResult(example, TestOutcome.PASS, None, ""),
        TestResult(skipped, TestOutcome.SKIP, None, ""),
    ]

    expect(test_runs).equals(expected_runs)
github darrenburns / ward / tests / test_fixtures.py View on Github external
def _(cache: FixtureCache = cache, events: List = recorded_events):
    cache.teardown_fixtures_for_scope(Scope.Module, testable_test.path)

    expect(events).equals(["teardown m"])
github darrenburns / ward / tests / test_expect.py View on Github external
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,
            op="called_once_with",
            that=None,
            op_args=args,
            op_kwargs=kwargs,
            success=False,
        )
    ]
    expect(e.history).equals(hist)