Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_hypothesis_strategies.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import datetime | |||||
import attr | import attr | ||||
from hypothesis import given | from hypothesis import given | ||||
from swh.model.hashutil import DEFAULT_ALGORITHMS | from swh.model.hashutil import DEFAULT_ALGORITHMS | ||||
from swh.model.hypothesis_strategies import objects, object_dicts | from swh.model.hypothesis_strategies import objects, object_dicts | ||||
target_types = ( | target_types = ( | ||||
Show All 11 Lines | def assert_nested_dict(obj): | ||||
from swh.model.model.""" | from swh.model.model.""" | ||||
if isinstance(obj, dict): | if isinstance(obj, dict): | ||||
for (key, value) in obj.items(): | for (key, value) in obj.items(): | ||||
assert isinstance(key, (str, bytes)), key | assert isinstance(key, (str, bytes)), key | ||||
assert_nested_dict(value) | assert_nested_dict(value) | ||||
elif isinstance(obj, list): | elif isinstance(obj, list): | ||||
for value in obj: | for value in obj: | ||||
assert_nested_dict(value) | assert_nested_dict(value) | ||||
elif isinstance(obj, (int, float, str, bytes, bool, type(None))): | elif isinstance(obj, (int, float, str, bytes, bool, type(None), | ||||
datetime.datetime)): | |||||
pass | pass | ||||
else: | else: | ||||
assert False, obj | assert False, obj | ||||
@given(object_dicts()) | @given(object_dicts()) | ||||
def test_dicts_generation(obj_type_and_obj): | def test_dicts_generation(obj_type_and_obj): | ||||
(obj_type, object_) = obj_type_and_obj | (obj_type, object_) = obj_type_and_obj | ||||
Show All 18 Lines |