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

Commit

Permalink
Running black formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Darren Burns committed Nov 8, 2019
1 parent 086bf05 commit ff0a9a0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 37 deletions.
35 changes: 20 additions & 15 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ def _():

@test("Test.is_parameterised should return True for parameterised test")
def _():
def parameterised_test(
a=each(1, 2, 3),
b="a value",
):
def parameterised_test(a=each(1, 2, 3), b="a value"):
pass

t = Test(fn=parameterised_test, module_name=mod)
Expand Down Expand Up @@ -113,27 +110,35 @@ def test():

@test("Test.get_parameterised_instances returns correct number of test instances")
def _():
def test(
a=each(1, 2),
b=each(3, 4),
):
def test(a=each(1, 2), b=each(3, 4)):
pass

t = Test(fn=test, module_name=mod)
expect(t.get_parameterised_instances()).equals(
[
Test(id=mock.ANY, fn=t.fn, module_name=t.module_name, param_meta=ParamMeta(0, 2), sout=mock.ANY, serr=mock.ANY),
Test(id=mock.ANY, fn=t.fn, module_name=t.module_name, param_meta=ParamMeta(1, 2), sout=mock.ANY, serr=mock.ANY),
],
Test(
id=mock.ANY,
fn=t.fn,
module_name=t.module_name,
param_meta=ParamMeta(0, 2),
sout=mock.ANY,
serr=mock.ANY,
),
Test(
id=mock.ANY,
fn=t.fn,
module_name=t.module_name,
param_meta=ParamMeta(1, 2),
sout=mock.ANY,
serr=mock.ANY,
),
]
)


@test("Test.get_parameterised_instances raises exception for arg count mismatch")
def _():
def invalid_test(
a=each(1, 2),
b=each(3, 4, 5),
):
def invalid_test(a=each(1, 2), b=each(3, 4, 5)):
pass

t = Test(fn=invalid_test, module_name=mod)
Expand Down
3 changes: 2 additions & 1 deletion ward/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class FixtureError(Exception):
pass


class ParameterisationError(Exception):
pass
pass
8 changes: 6 additions & 2 deletions ward/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def generate_test_runs(self) -> Generator[TestResult, None, None]:
generated_test(**resolved_vals)

# The test has completed without exception and therefore passed
outcome = TestOutcome.XPASS if marker == "XFAIL" else TestOutcome.PASS
outcome = (
TestOutcome.XPASS if marker == "XFAIL" else TestOutcome.PASS
)
yield generated_test.get_result(outcome)

except FixtureError as e:
Expand All @@ -56,7 +58,9 @@ def generate_test_runs(self) -> Generator[TestResult, None, None]:

except Exception as e:
# TODO: Differentiate between ExpectationFailed and other Exceptions.
outcome = TestOutcome.XFAIL if marker == "XFAIL" else TestOutcome.FAIL
outcome = (
TestOutcome.XFAIL if marker == "XFAIL" else TestOutcome.FAIL
)
yield generated_test.get_result(outcome, e)

self._teardown_fixtures_scoped_to_test(generated_test)
Expand Down
35 changes: 16 additions & 19 deletions ward/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class Test:
"""
A representation of a single Ward test.
"""

fn: Callable
module_name: str
id: str = field(default_factory=generate_id)
Expand Down Expand Up @@ -124,8 +125,7 @@ def is_parameterised(self) -> bool:
have a value that is an instance of `Each`.
"""
default_args = self._get_default_args()
return any(isinstance(arg, Each)
for arg in default_args.values())
return any(isinstance(arg, Each) for arg in default_args.values())

def get_parameterised_instances(self) -> List["Test"]:
"""
Expand All @@ -143,16 +143,17 @@ def get_parameterised_instances(self) -> List["Test"]:

generated_tests = []
for instance_index in range(number_of_instances):
generated_tests.append(Test(
fn=self.fn,
module_name=self.module_name,
marker=self.marker,
description=self.description,
param_meta=ParamMeta(
instance_index=instance_index,
group_size=number_of_instances,
),
))
generated_tests.append(
Test(
fn=self.fn,
module_name=self.module_name,
marker=self.marker,
description=self.description,
param_meta=ParamMeta(
instance_index=instance_index, group_size=number_of_instances
),
)
)
return generated_tests

def deps(self) -> MappingProxyType:
Expand Down Expand Up @@ -194,7 +195,7 @@ def get_result(self, outcome, exception=None):
outcome,
exception,
captured_stdout=self.sout.getvalue(),
captured_stderr=self.serr.getvalue()
captured_stderr=self.serr.getvalue(),
)
return result

Expand Down Expand Up @@ -274,9 +275,7 @@ def _resolve_single_arg(
children_resolved[name] = child_resolved
try:
if is_generator:
fixture.gen = arg(
**self._resolve_fixture_values(children_resolved)
)
fixture.gen = arg(**self._resolve_fixture_values(children_resolved))
fixture.resolved_val = next(fixture.gen)
else:
fixture.resolved_val = arg(
Expand All @@ -287,9 +286,7 @@ def _resolve_single_arg(
cache.cache_fixture(fixture)
return fixture

def _resolve_fixture_values(
self, fixture_dict: Dict[str, Any]
) -> Dict[str, Any]:
def _resolve_fixture_values(self, fixture_dict: Dict[str, Any]) -> Dict[str, Any]:
resolved_vals = {}
for (k, arg) in fixture_dict.items():
if isinstance(arg, Fixture):
Expand Down

0 comments on commit ff0a9a0

Please sign in to comment.