Skip to content

Commit

Permalink
#5: Added tests for rightshift.chains.flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
OOPMan committed Feb 29, 2016
1 parent 93628f7 commit ad81e6f
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion rightshift/tests/test_chains.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from math import isnan

from rightshift import Transformer, TransformationException
from rightshift.chains import flags, default
from hypothesis import given
from hypothesis import given, assume
from hypothesis.strategies import text, integers, floats


Expand All @@ -10,6 +12,12 @@ def __call__(self, value, **flags):
raises_transformation_exception = DefaultTestTransform()


class FlagsTestTransform(Transformer):
def __call__(self, value, **flags):
return flags.get('override', value)
returns_override_value_from_flags = FlagsTestTransform()


def __common_default_tests(a, b):
assert (raises_transformation_exception >> default(a))(b) == a
assert (raises_transformation_exception >> default(b))(a) == b
Expand All @@ -27,5 +35,28 @@ def test_default_with_integers(a, b):

@given(floats(), floats())
def test_default_with_floats(a, b):
assume(not isnan(a))
assume(not isnan(b))
__common_default_tests(a, b)


def __common_flag_tests(a, b):
assert (returns_override_value_from_flags >> flags(override=a))(b) == a
assert (returns_override_value_from_flags >> flags(override=b))(a) == b


@given(text(), text())
def test_flags_with_text(a, b):
__common_flag_tests(a, b)


@given(integers(), integers())
def test_flags_with_integers(a, b):
__common_flag_tests(a, b)


@given(floats(), floats())
def test_flags_with_floats(a, b):
assume(not isnan(a))
assume(not isnan(b))
__common_flag_tests(a, b)

0 comments on commit ad81e6f

Please sign in to comment.