Skip to content

Commit

Permalink
FEAT: Add DontCare for Easy Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Zaccardi committed Apr 26, 2017
2 parents e1d6093 + 9af0f1f commit 28643d6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions keg_elements/testing.py
Expand Up @@ -11,6 +11,23 @@
ColumnCheck.__new__.__defaults__ = (True, None, None, None)


class DontCare(object): # pragma: no cover
"""A placeholder object that can conform to almost anything and is always
equal to anything it is compared against.
Examples:
assert [1, 2, 3] == [1, DontCare(), 3]
"""
__eq__ = lambda *_: True
__ne__ = lambda *_: False
__repr__ = lambda *_: '_'

__getattr__ = lambda *_: DontCare()
__getitem__ = lambda *_: DontCare()
__call__ = lambda *a, **kw: DontCare()


class EntityBase(object):
entity_cls = None
column_checks = None
Expand Down
12 changes: 12 additions & 0 deletions keg_elements/tests/test_testing.py
@@ -0,0 +1,12 @@
import keg_elements.testing as testing


def test_dont_care():
assert testing.DontCare() == True # noqa
assert (testing.DontCare() == True) is True # noqa
assert (testing.DontCare() == False) is True # noqa
assert (testing.DontCare() == object) is True # noqa
assert (testing.DontCare() != object) is False # noqa
assert (testing.DontCare()() == object) is True # noqa
assert (testing.DontCare()['thing'] == object) is True # noqa
assert (testing.DontCare()[1] == object) is True # noqa

0 comments on commit 28643d6

Please sign in to comment.