-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
315 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ build-backend = "setuptools.build_meta" | |
|
||
[project] | ||
name = "unittest-extensions" | ||
version = "0.2.5" | ||
version = "0.3.0" | ||
authors = [ | ||
{ name="Maximos Nikiforakis", email="[email protected]" }, | ||
] | ||
|
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,10 +1,43 @@ | ||
def args(kwargs): | ||
import functools | ||
|
||
|
||
def args(*args, **kwargs): | ||
""" | ||
Decorate test methods to define arguments for your subject. | ||
Decorate test methods to define positional and/or keyword arguments for your | ||
`subject` method. | ||
Examples: | ||
>>> from unittest_extensions import TestCase, args | ||
>>> class MyClass: | ||
... def my_method(self, a, b): | ||
... return a + b | ||
>>> class TestMyMethod(TestCase): | ||
... def subject(self, a, b): | ||
... return MyClass().my_method(a, b) | ||
... @args(None, 2) | ||
... def test_none_plus_int(self): | ||
... self.assertResultRaises(TypeError) | ||
... @args(a=10, b=22.1) | ||
... def test_int_plus_float(self): | ||
... self.assertResult(32.1) | ||
... @args("1", b="2") | ||
... def test_str_plus_str(self): | ||
... self.assertResult("12") | ||
""" | ||
|
||
def wrapper(method): | ||
method._subjectKwargs = kwargs | ||
return method | ||
def args_decorator(test_method): | ||
test_method._subjectArgs = args | ||
test_method._subjectKwargs = kwargs | ||
|
||
@functools.wraps(test_method) | ||
def wrapped_test_method(*_args, **_kwargs): | ||
return test_method(*_args, **_kwargs) | ||
|
||
return wrapped_test_method | ||
|
||
return wrapper | ||
return args_decorator |
Oops, something went wrong.