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

Commit

Permalink
Merge pull request #63 from darrenburns/dots
Browse files Browse the repository at this point in the history
Dots
  • Loading branch information
darrenburns authored Dec 14, 2019
2 parents 122103b + fbd9a21 commit 49eae09
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 150 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup

version = "0.19.0a0"
version = "0.20.0a0"
description = "A modern Python 3 test framework for finding and fixing flaws faster."
with open("README.md", "r") as fh:
if platform.system() != "Windows":
Expand Down
54 changes: 11 additions & 43 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,14 @@ def t(f1=f1, f2=f2, f3=f3, f4=f4):


@fixture
def cache(
t=my_test
):
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,
):
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]
Expand All @@ -98,10 +92,7 @@ def _(


@test("FixtureCache.get_fixtures_at_scope correct for Scope.Module")
def _(
cache: FixtureCache = cache,
module_fixture=module_fixture,
):
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]
Expand All @@ -111,10 +102,7 @@ def _(


@test("FixtureCache.get_fixtures_at_scope correct for Scope.Global")
def _(
cache: FixtureCache = cache,
global_fixture=global_fixture,
):
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]
Expand All @@ -124,10 +112,7 @@ def _(


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

fixtures_at_scope = cache.get_fixtures_at_scope(Scope.Test, t.id)
Expand All @@ -136,20 +121,14 @@ def _(


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

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


@test("FixtureCache.teardown_fixtures_for_scope removes Module fixtures from cache")
def _(
cache: FixtureCache = 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)
Expand All @@ -158,19 +137,14 @@ def _(


@test("FixtureCache.teardown_fixtures_for_scope runs teardown for Module fixtures")
def _(
cache: FixtureCache = cache,
events: List = recorded_events,
):
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,
):
def _(cache: FixtureCache = cache,):
cache.teardown_global_fixtures()

fixtures_at_scope = cache.get_fixtures_at_scope(Scope.Global, Scope.Global)
Expand All @@ -179,10 +153,7 @@ def _(


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

expect(events).equals(["teardown g"])
Expand All @@ -195,10 +166,7 @@ def fixture_a():
pass

@testable_test
@using(
a=fixture_a,
b="val",
)
@using(a=fixture_a, b="val")
def t(a, b):
pass

Expand Down
3 changes: 2 additions & 1 deletion tests/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ def testable_test(func):
return test(
"testable test description",
_force_path=FORCE_TEST_PATH,
_collect_into=defaultdict(list)
_collect_into=defaultdict(list),
)(func)


testable_test.path = FORCE_TEST_PATH


Expand Down
10 changes: 3 additions & 7 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
@test(
"get_exit_code returns ExitCode.SUCCESS when PASS, SKIP and XFAIL in test results"
)
@using(
example=example_test,
)
def _(example=example_test):
@using(example=example_test)
def _(example):
test_results = [
TestResult(test=example, outcome=TestOutcome.PASS),
TestResult(test=example, outcome=TestOutcome.SKIP),
Expand Down Expand Up @@ -46,9 +44,7 @@ def s():

@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..."),
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)
15 changes: 8 additions & 7 deletions ward/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ class FixtureCache:
The final lookup lets us retrieve the actual fixture given a fixture key.
"""

_scope_cache: ScopeCache = field(default_factory=_scope_cache_factory)

def _get_subcache(self, scope: Scope) -> Dict[str, Any]:
return self._scope_cache[scope]

def get_fixtures_at_scope(self, scope: Scope, scope_key: ScopeKey) -> Dict[FixtureKey, Fixture]:
def get_fixtures_at_scope(
self, scope: Scope, scope_key: ScopeKey
) -> Dict[FixtureKey, Fixture]:
subcache = self._get_subcache(scope)
if scope_key not in subcache:
subcache[scope_key] = {}
Expand Down Expand Up @@ -109,7 +112,9 @@ def contains(self, fixture: Fixture, scope: Scope, scope_key: ScopeKey) -> bool:
fixtures = self.get_fixtures_at_scope(scope, scope_key)
return fixture.key in fixtures

def get(self, fixture_key: FixtureKey, scope: Scope, scope_key: ScopeKey) -> Fixture:
def get(
self, fixture_key: FixtureKey, scope: Scope, scope_key: ScopeKey
) -> Fixture:
fixtures = self.get_fixtures_at_scope(scope, scope_key)
return fixtures.get(fixture_key)

Expand All @@ -129,11 +134,7 @@ def fixture(func=None, *, scope: Optional[Union[Scope, str]] = Scope.Test):
func.ward_meta.is_fixture = True
func.ward_meta.path = path
else:
func.ward_meta = WardMeta(
is_fixture=True,
scope=scope,
path=path,
)
func.ward_meta = WardMeta(is_fixture=True, scope=scope, path=path)

@wraps(func)
def wrapper(*args, **kwargs):
Expand Down
13 changes: 9 additions & 4 deletions ward/run.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import sys
from timeit import default_timer

import click
import sys
from colorama import init

from ward.collect import (
get_info_for_modules,
get_tests_in_modules,
Expand Down Expand Up @@ -32,7 +31,13 @@
type=int,
help="The maximum number of failures that are allowed to occur in a run before it is automatically cancelled.",
)
def run(path, search, fail_limit):
@click.option(
"--test-output-style",
type=click.Choice(
["test-per-line", "dots-global", "dots-module"], case_sensitive=False
),
)
def run(path, search, fail_limit, test_output_style):
start_run = default_timer()

mod_infos = get_info_for_modules(path)
Expand All @@ -44,7 +49,7 @@ def run(path, search, fail_limit):
suite = Suite(tests=list(tests))
test_results = suite.generate_test_runs()

writer = SimpleTestResultWrite(suite=suite)
writer = SimpleTestResultWrite(suite=suite, test_output_style=test_output_style)
results = writer.output_all_test_results(
test_results, time_to_collect=time_to_collect, fail_limit=fail_limit
)
Expand Down
6 changes: 2 additions & 4 deletions ward/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ def generate_test_runs(self) -> Generator[TestResult, None, None]:
yield generated_test.get_result(outcome, e)
finally:
self.cache.teardown_fixtures_for_scope(
Scope.Test,
scope_key=generated_test.id,
Scope.Test, scope_key=generated_test.id
)
if num_tests_per_module[generated_test.path] == 0:
self.cache.teardown_fixtures_for_scope(
Scope.Module,
scope_key=generated_test.path,
Scope.Module, scope_key=generated_test.path
)

self.cache.teardown_global_fixtures()
Loading

0 comments on commit 49eae09

Please sign in to comment.