Skip to content
Snippets Groups Projects
Commit 968a989d authored by Jenkins for Software Heritage's avatar Jenkins for Software Heritage
Browse files

New upstream version 0.0.68

parents 02464c67 1037e88d
No related branches found
Tags debian/upstream/0.0.68
No related merge requests found
Metadata-Version: 2.1
Name: swh.model
Version: 0.0.67
Version: 0.0.68
Summary: Software Heritage data model
Home-page: https://forge.softwareheritage.org/diffusion/DMOD/
Author: Software Heritage developers
......@@ -34,6 +34,7 @@ Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 5 - Production/Stable
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Provides-Extra: cli
Provides-Extra: testing
#!/usr/bin/env python3
# Copyright (C) 2015-2018 The Software Heritage developers
# Copyright (C) 2015-2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
......@@ -42,6 +42,7 @@ setup(
description="Software Heritage data model",
long_description=long_description,
long_description_content_type="text/markdown",
python_requires=">=3.7",
author="Software Heritage developers",
author_email="swh-devel@inria.fr",
url="https://forge.softwareheritage.org/diffusion/DMOD/",
......
Metadata-Version: 2.1
Name: swh.model
Version: 0.0.67
Version: 0.0.68
Summary: Software Heritage data model
Home-page: https://forge.softwareheritage.org/diffusion/DMOD/
Author: Software Heritage developers
......@@ -34,6 +34,7 @@ Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 5 - Production/Stable
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Provides-Extra: cli
Provides-Extra: testing
......@@ -380,30 +380,66 @@ def snapshots(*, min_size=0, max_size=100, only_objects=False):
).map(Snapshot.from_dict)
def objects():
return one_of(
origins().map(lambda x: ("origin", x)),
origin_visits().map(lambda x: ("origin_visit", x)),
origin_visit_statuses().map(lambda x: ("origin_visit_update", x)),
snapshots().map(lambda x: ("snapshot", x)),
releases().map(lambda x: ("release", x)),
revisions().map(lambda x: ("revision", x)),
directories().map(lambda x: ("directory", x)),
contents().map(lambda x: ("content", x)),
)
def objects(blacklist_types=("origin_visit_status",), split_content=False):
"""generates a random couple (type, obj)
which obj is an instance of the Model class corresponding to obj_type.
`blacklist_types` is a list of obj_type to exclude from the strategy.
If `split_content` is True, generates Content and SkippedContent under different
obj_type, resp. "content" and "skipped_content".
"""
strategies = [
("origin", origins),
("origin_visit", origin_visits),
("origin_visit_status", origin_visit_statuses),
("snapshot", snapshots),
("release", releases),
("revision", revisions),
("directory", directories),
]
if split_content:
strategies.append(("content", present_contents))
strategies.append(("skipped_content", skipped_contents))
else:
strategies.append(("content", contents))
args = [
obj_gen().map(lambda x, obj_type=obj_type: (obj_type, x))
for (obj_type, obj_gen) in strategies
if obj_type not in blacklist_types
]
return one_of(*args)
def object_dicts():
def object_dicts(blacklist_types=("origin_visit_status",), split_content=False):
"""generates a random couple (type, dict)
which dict is suitable for <ModelForType>.from_dict() factory methods.
`blacklist_types` is a list of obj_type to exclude from the strategy.
If `split_content` is True, generates Content and SkippedContent under different
obj_type, resp. "content" and "skipped_content".
"""
return one_of(
origins_d().map(lambda x: ("origin", x)),
origin_visits_d().map(lambda x: ("origin_visit", x)),
snapshots_d().map(lambda x: ("snapshot", x)),
releases_d().map(lambda x: ("release", x)),
revisions_d().map(lambda x: ("revision", x)),
directories_d().map(lambda x: ("directory", x)),
contents_d().map(lambda x: ("content", x)),
)
strategies = [
("origin", origins_d),
("origin_visit", origin_visits_d),
("origin_visit_status", origin_visit_statuses_d),
("snapshot", snapshots_d),
("release", releases_d),
("revision", revisions_d),
("directory", directories_d),
]
if split_content:
strategies.append(("content", present_contents_d))
strategies.append(("skipped_content", skipped_contents_d))
else:
strategies.append(("content", contents_d))
args = [
obj_gen().map(lambda x, obj_type=obj_type: (obj_type, x))
for (obj_type, obj_gen) in strategies
if obj_type not in blacklist_types
]
return one_of(*args)
......@@ -14,14 +14,41 @@ from swh.model.model import TargetType
target_types = ("content", "directory", "revision", "release", "snapshot", "alias")
@given(objects())
all_but_skipped_content = (
"origin",
"origin_visit",
"origin_visit_status",
"snapshot",
"release",
"revision",
"directory",
"content",
)
@given(objects(blacklist_types=()))
def test_generation(obj_type_and_obj):
(obj_type, object_) = obj_type_and_obj
attr.validate(object_)
@given(objects(split_content=False))
def test_generation_merged_content(obj_type_and_obj):
# we should never generate a "skipped_content" here
assert obj_type_and_obj[0] != "skipped_content"
@given(objects(split_content=True, blacklist_types=all_but_skipped_content))
def test_generation_split_content(obj_type_and_obj):
# we should only generate "skipped_content"
assert obj_type_and_obj[0] == "skipped_content"
@given(objects(blacklist_types=("origin_visit", "directory")))
def test_generation_blacklist(obj_type_and_obj):
assert obj_type_and_obj[0] not in ("origin_visit", "directory")
def assert_nested_dict(obj):
"""Tests the object is a nested dict and contains no more class
from swh.model.model."""
......@@ -38,7 +65,7 @@ def assert_nested_dict(obj):
assert False, obj
@given(object_dicts())
@given(object_dicts(blacklist_types=()))
def test_dicts_generation(obj_type_and_obj):
(obj_type, object_) = obj_type_and_obj
assert_nested_dict(object_)
......@@ -59,6 +86,23 @@ def test_dicts_generation(obj_type_and_obj):
assert branch is None or branch["target_type"] in target_types
@given(object_dicts(split_content=False))
def test_dicts_generation_merged_content(obj_type_and_obj):
# we should never generate a "skipped_content" here
assert obj_type_and_obj[0] != "skipped_content"
@given(object_dicts(split_content=True, blacklist_types=all_but_skipped_content))
def test_dicts_generation_split_content(obj_type_and_obj):
# we should only generate "skipped_content"
assert obj_type_and_obj[0] == "skipped_content"
@given(object_dicts(blacklist_types=("release", "content")))
def test_dicts_generation_blacklist(obj_type_and_obj):
assert obj_type_and_obj[0] not in ("release", "content")
@given(objects())
def test_model_to_dicts(obj_type_and_obj):
(obj_type, object_) = obj_type_and_obj
......
v0.0.67-0-gd52549f
\ No newline at end of file
v0.0.68-0-g1037e88
\ No newline at end of file
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