Skip to content
Snippets Groups Projects
Commit 6a638077 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

v2.2.16

parent 620264e2
No related branches found
Tags v2.2.16
No related merge requests found
# v2.2.16 # v2.2.16
* _TBA_ * `is_valid_schema` can be now passed in using kwargs
# v2.2.15 # v2.2.15
......
# coding=UTF-8 # coding=UTF-8
__version__ = '2.2.16a1' __version__ = '2.2.16'
...@@ -27,15 +27,20 @@ class DictObject(dict): ...@@ -27,15 +27,20 @@ class DictObject(dict):
except KeyError as e: except KeyError as e:
raise AttributeError(repr(e)) raise AttributeError(repr(e))
def is_valid_schema(self, schema: tp.Union[Descriptor, dict]) -> bool: def is_valid_schema(self, schema: tp.Optional[tp.Union[Descriptor, dict]]=None, **kwarg_schema) -> bool:
""" """
Check if this dictionary conforms to particular schema. Check if this dictionary conforms to particular schema.
Schema is either a Descriptor, or a JSON-based schema. See satella.configuration.schema for details. Schema is either a Descriptor, or a JSON-based schema. See satella.configuration.schema for details.
Schema can be passed as well using kwargs. It will be preferred to the one passed as schema.
:param schema: schema to verify against :param schema: schema to verify against
:return: whether is conformant :return: whether is conformant
""" """
if kwarg_schema:
schema = kwarg_schema
if isinstance(schema, Descriptor): if isinstance(schema, Descriptor):
descriptor = schema descriptor = schema
else: else:
......
...@@ -13,6 +13,8 @@ class TestTimeBasedHeap(unittest.TestCase): ...@@ -13,6 +13,8 @@ class TestTimeBasedHeap(unittest.TestCase):
def test_dict_object(self): def test_dict_object(self):
self.assertTrue(DictObject({'a': 5, 'b': 'test'}).is_valid_schema({'a': int, 'b': str})) self.assertTrue(DictObject({'a': 5, 'b': 'test'}).is_valid_schema({'a': int, 'b': str}))
self.assertFalse(DictObject({'a': 5, 'b': 'test'}).is_valid_schema({'a': int, 'b': int})) self.assertFalse(DictObject({'a': 5, 'b': 'test'}).is_valid_schema({'a': int, 'b': int}))
self.assertTrue(DictObject({'a': 5, 'b': 'test'}).is_valid_schema(a=int, b=str))
self.assertFalse(DictObject({'a': 5, 'b': 'test'}).is_valid_schema(a=int, b=int))
def test_omni(self): def test_omni(self):
class Omni(OmniHashableMixin): class Omni(OmniHashableMixin):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment