This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from darrenburns/fixture-cleanup
Fixture cleanup
- Loading branch information
Showing
9 changed files
with
57 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,18 @@ | ||
from ward import expect, fixture, raises, test | ||
from ward.fixtures import Fixture, FixtureExecutionError, FixtureCache | ||
from ward import expect, fixture, test | ||
from ward.fixtures import Fixture, FixtureCache | ||
|
||
|
||
@fixture | ||
def exception_raising_fixture(): | ||
def i_raise_an_exception(): | ||
raise ZeroDivisionError() | ||
|
||
return Fixture(key="fix_a", fn=i_raise_an_exception) | ||
return Fixture(fn=i_raise_an_exception) | ||
|
||
|
||
@test("Fixture.resolve correctly recurses fixture tree, collecting dependencies") | ||
def _(): | ||
@fixture | ||
def grandchild_a(): | ||
return 1 | ||
|
||
@fixture | ||
def child_b(): | ||
return 1 | ||
|
||
@fixture | ||
def child_a(grandchild_a=grandchild_a): | ||
return grandchild_a + 1 | ||
|
||
@fixture | ||
def parent(child_a=child_a, child_b=child_b): | ||
return child_a + child_b + 1 | ||
|
||
grandchild_a_fix = Fixture(key="grandchild_a", fn=grandchild_a) | ||
child_a_fix = Fixture(key="child_a", fn=child_a) | ||
child_b_fix = Fixture(key="child_b", fn=child_b) | ||
parent_fix = Fixture(key="fix_a", fn=parent) | ||
|
||
cache = FixtureCache() | ||
cache.cache_fixtures((grandchild_a_fix, child_a_fix, child_b_fix, parent_fix)) | ||
|
||
resolved_parent = parent_fix.resolve(cache) | ||
|
||
# Each of the fixtures add 1, so the final value returned | ||
# by the tree should be 4, since there are 4 fixtures. | ||
expect(resolved_parent.resolved_val).equals(4) | ||
|
||
|
||
@test("FixtureRegistry.cache_fixture can store and retrieve a single fixture") | ||
@test("FixtureCache.cache_fixture can store and retrieve a single fixture") | ||
def _(f=exception_raising_fixture): | ||
cache = FixtureCache() | ||
cache.cache_fixture(f) | ||
|
||
expect(cache[f.key]).equals(f) | ||
|
||
|
||
@test( | ||
"FixtureRegistry.resolve raises FixtureExecutionError when fixture raises an exception" | ||
) | ||
def _(f=exception_raising_fixture): | ||
cache = FixtureCache() | ||
cache.cache_fixtures([f]) | ||
|
||
with raises(FixtureExecutionError): | ||
f.resolve(cache) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.