-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 changed file
with
62 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"""Tests the decorators.""" | ||
|
||
try: | ||
import unittest2 as unittest | ||
except ImportError: | ||
import unittest | ||
|
||
from sequential import before, after, during | ||
|
||
|
||
__all__ = ['TestSequential'] | ||
|
||
|
||
class TestSequential(unittest.TestCase): | ||
def test_before_chain(self): | ||
"""Tests @before chained to another function.""" | ||
def add_b(word=''): | ||
return word + 'b' | ||
|
||
@before(add_b, chain=True) | ||
def add_a(word=''): | ||
return word + 'a' | ||
|
||
assert add_a() == 'ba' | ||
|
||
def test_before_no_chain(self): | ||
"""Tests @before not chained to another function.""" | ||
def switch_a(d): | ||
d['a'] = True | ||
|
||
@before(switch_a) | ||
def check_a(d): | ||
assert d['a'] | ||
|
||
check_a({'a': False}) | ||
|
||
def test_after_chain(self): | ||
"""Tests @after chained to another function.""" | ||
def add_a(word=''): | ||
return word + 'a' | ||
|
||
@after(add_a, chain=True) | ||
def add_b(word=''): | ||
return word + 'b' | ||
|
||
assert add_b() == 'ba' | ||
|
||
def test_after_no_chain(self): | ||
"""Tests @after not chained to another function.""" | ||
def check_a(d): | ||
assert d['a'] | ||
d['b'] = True | ||
|
||
@after(check_a) | ||
def switch_a(d): | ||
d['a'] = True | ||
|
||
d = {'a': False, 'b': False} | ||
switch_a(d) | ||
assert d['b'] | ||
|
||
# TODO Come up with a good way of testing @during. |