Skip to content

Commit a3a5a7e

Browse files
committed
Moved Is class to upper "classes" module
1 parent f97b879 commit a3a5a7e

File tree

12 files changed

+57
-61
lines changed

12 files changed

+57
-61
lines changed

fluentcheck/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
from .classes import Check
2-
from .is_cls import Is
1+
from .classes import Check, Is

fluentcheck/assertions_is/booleans.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..is_cls import Is
1+
from .. import Is
22
from ..classes import Check
33

44

fluentcheck/assertions_is/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..is_cls import Is
1+
from .. import Is
22
from ..classes import Check
33
from typing import Any, Set
44

fluentcheck/assertions_is/dicts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..is_cls import Is
1+
from .. import Is
22
from ..classes import Check
33

44

fluentcheck/assertions_is/geo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..is_cls import Is
1+
from .. import Is
22
from ..classes import Check
33

44

fluentcheck/assertions_is/numbers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..is_cls import Is
1+
from .. import Is
22
from ..classes import Check
33

44

fluentcheck/assertions_is/sequences.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..is_cls import Is
1+
from .. import Is
22
from ..classes import Check
33

44

fluentcheck/assertions_is/strings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..is_cls import Is
1+
from .. import Is
22
from ..classes import Check
33

44

fluentcheck/assertions_is/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..is_cls import Is
1+
from .. import Is
22
from ..classes import Check
33

44

fluentcheck/assertions_is/uuids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..is_cls import Is
1+
from .. import Is
22
from ..classes import Check
33

44

fluentcheck/classes.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import importlib
22
import inspect
33
import pkgutil
4+
from inspect import signature
5+
from typing import Any
6+
47
from .exceptions import CheckError
58

69

@@ -51,3 +54,47 @@ def is_not_none(self):
5154
return self
5255
except AssertionError:
5356
raise CheckError('{} is None'.format(self._val))
57+
58+
59+
class Is:
60+
61+
ASSERTIONS_PACKAGE = 'fluentcheck.assertions_is'
62+
63+
def _import_assertion_modules(self):
64+
ass = importlib.import_module(Is.ASSERTIONS_PACKAGE)
65+
assertion_modules = list()
66+
for _1, module_name, _2 in pkgutil.iter_modules(ass.__path__):
67+
assertion_modules.append(importlib.import_module(ass.__name__ + '.' + module_name))
68+
return assertion_modules
69+
70+
def __new__(cls, *args, **kwargs):
71+
# retrieve all modules in assertion package
72+
assertion_modules = cls._import_assertion_modules(cls)
73+
# bind Is object instance with assertion functions from assertion modules
74+
instance = super(Is, cls).__new__(cls)
75+
for module in assertion_modules:
76+
for item in inspect.getmembers(module, inspect.isfunction):
77+
func_name = item[0]
78+
func = item[1]
79+
if len(signature(func).parameters) == 1: # should be attached as a property
80+
setattr(Is, func_name, property(func, None, None, None))
81+
else: # should be attached as a bound method
82+
bound_method = func.__get__(instance, instance.__class__)
83+
setattr(instance, func_name, bound_method)
84+
return instance
85+
86+
def __init__(self, object_under_test: Any):
87+
self.object = object_under_test
88+
89+
def __call__(self, *args, **kwargs):
90+
return self
91+
92+
@property
93+
def none(self) -> "Is":
94+
Check(self.object).is_none()
95+
return self
96+
97+
@property
98+
def not_none(self) -> "Is":
99+
Check(self.object).is_not_none()
100+
return self

fluentcheck/is_cls.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)