Skip to content

Commit

Permalink
moved assertions for the "Is" syntax to a specific module so they can…
Browse files Browse the repository at this point in the history
… be dynamically added to the Is class
  • Loading branch information
csparpa committed Mar 13, 2020
1 parent fdfd136 commit 4e3e91d
Show file tree
Hide file tree
Showing 35 changed files with 847 additions and 624 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ is_not_runnable()
is_module()
is_not_module()


# Type hierarchy
is_subtype_of(_type)
is_not_subtype_of(_type)
Expand All @@ -238,10 +237,6 @@ is_not_subtype_of(_type)
is_of_type(_type)
is_not_of_type(_type)

# Any type
equals(expected)
not_equals(expected)

# Geographic coords
is_latitude()
is_longitude()
Expand Down Expand Up @@ -355,10 +350,6 @@ not_intersects(_set)
subtype_of(_type)
not_subtype_of(_type)

# Any type
equals(expected)
not_equals(expected)

# UUIDs
is_uuid1()
is_not_uuid1()
Expand Down
2 changes: 1 addition & 1 deletion fluentcheck/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .check import Check
from .classes import Check
from .is_cls import Is
2 changes: 1 addition & 1 deletion fluentcheck/assertions/geo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..check import Check
from ..classes import Check
from ..exceptions import CheckError


Expand Down
2 changes: 1 addition & 1 deletion fluentcheck/assertions/numbers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..check import Check
from ..classes import Check
from ..exceptions import CheckError


Expand Down
20 changes: 2 additions & 18 deletions fluentcheck/assertions/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,15 @@ def is_not_module(check_obj):

def is_runnable(check_obj):
try:
assert isinstance(check_obj._val, types.FunctionType)
assert isinstance(check_obj._val, t.FunctionType)
return check_obj
except AssertionError:
raise CheckError('{} is not runnable'.format(check_obj._val))


def is_not_runnable(check_obj):
try:
assert not isinstance(check_obj._val, types.FunctionType)
assert not isinstance(check_obj._val, t.FunctionType)
return check_obj
except AssertionError:
raise CheckError('{} is runnable'.format(check_obj._val))

# Any type

def equals(check_obj, expected):
try:
assert check_obj._val == expected
return check_obj
except AssertionError:
raise CheckError('{} does not equal {}'.format(check_obj._val, expected))

def not_equals(check_obj, expected):
try:
assert check_obj._val == expected
raise CheckError('{} equals {}'.format(check_obj._val, expected))
except AssertionError:
return check_obj
2 changes: 1 addition & 1 deletion fluentcheck/assertions/uuids.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..check import Check
from ..classes import Check
from ..exceptions import CheckError
from uuid import UUID

Expand Down
Empty file.
74 changes: 74 additions & 0 deletions fluentcheck/assertions_is/booleans.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from ..is_cls import Is
from ..classes import Check


def boolean(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_boolean()
return check_obj


def not_boolean(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_boolean()
return check_obj


def true(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_true()
return check_obj


def false(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_false()
return check_obj


def not_true(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_true()
return check_obj


def not_false(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_false()
return check_obj


def falsy(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_falsy()
return check_obj


def not_falsy(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_falsy()
return check_obj


def truthy(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_truthy()
return check_obj


def not_truthy(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_truthy()
return check_obj


def has_same_truth_of(check_obj, compare_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).has_same_truth_of(compare_obj)
return check_obj


def has_opposite_truth_of(check_obj, compare_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).has_opposite_truth_of(compare_obj)
return check_obj
51 changes: 51 additions & 0 deletions fluentcheck/assertions_is/collections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from ..is_cls import Is
from ..classes import Check
from typing import Any, Set


def set(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_set()
return check_obj


def not_set(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_set()
return check_obj


def subset_of(check_obj, full_set: Set[Any]) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_subset_of(full_set)
return check_obj


def not_subset_of(check_obj, full_set: Set[Any]) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_subset_of(full_set)
return check_obj


def superset_of(check_obj, full_set: Set[Any]) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_superset_of(full_set)
return check_obj


def not_superset_of(check_obj, subset: Set[Any]) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_superset_of(subset)
return check_obj


def intersects(check_obj, other_set: Set[Any]) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).intersects(other_set)
return check_obj


def not_intersects(check_obj, other_set: Set[Any]) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).not_intersects(other_set)
return check_obj
26 changes: 26 additions & 0 deletions fluentcheck/assertions_is/dicts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from ..is_cls import Is
from ..classes import Check


def dict(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_dict()
return check_obj


def not_dict(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_dict()
return check_obj


def has_keys(check_obj, *keys) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).has_keys(*keys)
return check_obj


def has_not_keys(check_obj, *keys) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).has_not_keys(*keys)
return check_obj
26 changes: 26 additions & 0 deletions fluentcheck/assertions_is/geo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from ..is_cls import Is
from ..classes import Check


def latitude(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_latitude()
return check_obj


def longitude(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_longitude()
return check_obj


def azimuth(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_azimuth()
return check_obj


def geopoint(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_geopoint()
return check_obj
122 changes: 122 additions & 0 deletions fluentcheck/assertions_is/numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
from ..is_cls import Is
from ..classes import Check


def number(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_number()
return check_obj


def not_number(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_number()
return check_obj


def integer(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_integer()
return check_obj


def not_integer(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_integer()
return check_obj


def float(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_float()
return check_obj


def not_float(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_float()
return check_obj


def real(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_real()
return check_obj


def not_real(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_real()
return check_obj


def complex(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_complex()
return check_obj


def not_complex(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_complex()
return check_obj


def positive(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_positive()
return check_obj


def not_positive(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_positive()
return check_obj


def negative(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_negative()
return check_obj


def not_negative(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_negative()
return check_obj


def zero(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_zero()
return check_obj


def nonzero(check_obj) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_zero()
return check_obj


def at_least(check_obj, number) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_at_least(number)
return check_obj


def at_most(check_obj, number) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_at_most(number)
return check_obj


def between(check_obj, lower_bound, upper_bound) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_between(lower_bound, upper_bound)
return check_obj


def not_between(check_obj, lower_bound, upper_bound) -> "Is":
# noinspection PyUnresolvedReferences
Check(check_obj.object).is_not_between(lower_bound, upper_bound)
return check_obj
Loading

0 comments on commit 4e3e91d

Please sign in to comment.