Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
astex committed Nov 21, 2014
1 parent e013129 commit 94794e6
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test_sequential.py
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.

0 comments on commit 94794e6

Please sign in to comment.