Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:darrenburns/ward
Browse files Browse the repository at this point in the history
  • Loading branch information
Darren Burns committed Nov 9, 2019
2 parents d652aa2 + 765112b commit 8d89d8c
Show file tree
Hide file tree
Showing 10 changed files with 411 additions and 165 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
name: Testing on Python ${{ matrix.python-version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 6
max-parallel: 9
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
python-version: [3.6, 3.7]
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
name: Testing on Python ${{ matrix.python-version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 6
max-parallel: 9
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
python-version: [3.6, 3.7]
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v1
Expand Down
178 changes: 174 additions & 4 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,188 @@
from ward import expect, fixture, test
from typing import List

from tests.test_suite import testable_test
from ward import expect, fixture, test, Scope
from ward.fixtures import Fixture, FixtureCache
from ward.testing import Test


@fixture
def exception_raising_fixture():
@fixture
def i_raise_an_exception():
raise ZeroDivisionError()

return Fixture(fn=i_raise_an_exception)


@test("FixtureCache.cache_fixture can store and retrieve a single fixture")
@test("FixtureCache.cache_fixture caches a single fixture")
def _(f=exception_raising_fixture):
cache = FixtureCache()
cache.cache_fixture(f)
cache.cache_fixture(f, "test_id")

expect(cache.get(f.key, Scope.Test, "test_id")).equals(f)


@fixture
def recorded_events():
return []


@fixture
def global_fixture(events=recorded_events):
@fixture(scope=Scope.Global)
def g():
yield "g"
events.append("teardown g")

return g


@fixture
def module_fixture(events=recorded_events):
@fixture(scope=Scope.Module)
def m():
yield "m"
events.append("teardown m")

return m


@fixture
def default_fixture(events=recorded_events):
@fixture
def t():
yield "t"
events.append("teardown t")

return t


@fixture
def my_test(
f1=exception_raising_fixture,
f2=global_fixture,
f3=module_fixture,
f4=default_fixture,
):
# Inject these fixtures into a test, and resolve them
# to ensure they're ready to be torn down.
@testable_test
def t(f1=f1, f2=f2, f3=f3, f4=f4):
pass

return Test(t, "")


@fixture
def cache(
t=my_test
):
c = FixtureCache()
t.resolve_args(c)
return c


@test("FixtureCache.get_fixtures_at_scope correct for Scope.Test")
def _(
cache: FixtureCache = cache,
t: Test = my_test,
default_fixture=default_fixture,
):
fixtures_at_scope = cache.get_fixtures_at_scope(Scope.Test, t.id)

fixture = list(fixtures_at_scope.values())[0]

expect(fixtures_at_scope).has_length(1)
expect(fixture.fn).equals(default_fixture)


@test("FixtureCache.get_fixtures_at_scope correct for Scope.Module")
def _(
cache: FixtureCache = cache,
module_fixture=module_fixture,
):
fixtures_at_scope = cache.get_fixtures_at_scope(Scope.Module, testable_test.path)

fixture = list(fixtures_at_scope.values())[0]

expect(fixtures_at_scope).has_length(1)
expect(fixture.fn).equals(module_fixture)


@test("FixtureCache.get_fixtures_at_scope correct for Scope.Global")
def _(
cache: FixtureCache = cache,
global_fixture=global_fixture,
):
fixtures_at_scope = cache.get_fixtures_at_scope(Scope.Global, Scope.Global)

fixture = list(fixtures_at_scope.values())[0]

expect(fixtures_at_scope).has_length(1)
expect(fixture.fn).equals(global_fixture)


@test("FixtureCache.teardown_fixtures_for_scope removes Test fixtures from cache")
def _(
cache: FixtureCache = cache,
test: Test = my_test,
):
cache.teardown_fixtures_for_scope(Scope.Test, test.id)

fixtures_at_scope = cache.get_fixtures_at_scope(Scope.Test, test.id)

expect(fixtures_at_scope).equals({})


@test("FixtureCache.teardown_fixtures_for_scope runs teardown for Test fixtures")
def _(
cache: FixtureCache = cache,
test: Test = my_test,
events: List = recorded_events,
):
cache.teardown_fixtures_for_scope(Scope.Test, test.id)

expect(events).equals(["teardown t"])


@test("FixtureCache.teardown_fixtures_for_scope removes Module fixtures from cache")
def _(
cache: FixtureCache = cache,
):
cache.teardown_fixtures_for_scope(Scope.Module, testable_test.path)

fixtures_at_scope = cache.get_fixtures_at_scope(Scope.Module, testable_test.path)

expect(fixtures_at_scope).equals({})


@test("FixtureCache.teardown_fixtures_for_scope runs teardown for Module fixtures")
def _(
cache: FixtureCache = cache,
events: List = recorded_events,
):
cache.teardown_fixtures_for_scope(Scope.Module, testable_test.path)

expect(events).equals(["teardown m"])


@test("FixtureCache.teardown_global_fixtures removes Global fixtures from cache")
def _(
cache: FixtureCache = cache,
):
cache.teardown_global_fixtures()

fixtures_at_scope = cache.get_fixtures_at_scope(Scope.Global, Scope.Global)

expect(fixtures_at_scope).equals({})


@test("FixtureCache.teardown_global_fixtures runs teardown of all Global fixtures")
def _(
cache: FixtureCache = cache,
events: List = recorded_events,
):
cache.teardown_global_fixtures()

expect(cache[f.key]).equals(f)
expect(events).equals(["teardown g"])
Loading

0 comments on commit 8d89d8c

Please sign in to comment.