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

Updated version 0.0.42 from 'debian/upstream/0.0.42'

with Debian dir 2e23d1f94249265cf074e48e4d9f41f9aa7574e8
parents 32398341 7d9d5147
No related branches found
No related tags found
No related merge requests found
Metadata-Version: 2.1
Name: swh.model
Version: 0.0.41
Version: 0.0.42
Summary: Software Heritage data model
Home-page: https://forge.softwareheritage.org/diffusion/DMOD/
Author: Software Heritage developers
Author-email: swh-devel@inria.fr
License: UNKNOWN
Project-URL: Bug Reports, https://forge.softwareheritage.org/maniphest
Project-URL: Source, https://forge.softwareheritage.org/source/swh-model
Project-URL: Funding, https://www.softwareheritage.org/donate
Project-URL: Source, https://forge.softwareheritage.org/source/swh-model
Description: swh-model
=========
......
Metadata-Version: 2.1
Name: swh.model
Version: 0.0.41
Version: 0.0.42
Summary: Software Heritage data model
Home-page: https://forge.softwareheritage.org/diffusion/DMOD/
Author: Software Heritage developers
Author-email: swh-devel@inria.fr
License: UNKNOWN
Project-URL: Bug Reports, https://forge.softwareheritage.org/maniphest
Project-URL: Source, https://forge.softwareheritage.org/source/swh-model
Project-URL: Funding, https://www.softwareheritage.org/donate
Project-URL: Source, https://forge.softwareheritage.org/source/swh-model
Description: swh-model
=========
......
......@@ -78,7 +78,9 @@ def origin_visits():
return builds(
OriginVisit,
visit=integers(0, 1000),
origin=origins())
origin=origins(),
status=sampled_from(['ongoing', 'full', 'partial']),
type=pgsql_text())
@composite
......@@ -178,7 +180,10 @@ def branch_targets(*, only_objects=False):
def snapshots(draw, *, min_size=0, max_size=100, only_objects=False):
branches = draw(dictionaries(
keys=branch_names(),
values=branch_targets(only_objects=only_objects),
values=one_of(
none(),
branch_targets(only_objects=only_objects)
),
min_size=min_size,
max_size=max_size,
))
......@@ -200,7 +205,7 @@ def snapshots(draw, *, min_size=0, max_size=100, only_objects=False):
try:
id_ = snapshot_identifier({
'branches': {
name: branch.to_dict()
name: branch.to_dict() if branch else None
for (name, branch) in branches.items()}})
except ValueError as e:
for (source, target) in e.args[1]:
......
......@@ -104,15 +104,22 @@ class OriginVisit(BaseModel):
SWH loader."""
origin = attr.ib(type=Origin)
date = attr.ib(type=datetime.datetime)
status = attr.ib(
type=str,
validator=attr.validators.in_(['ongoing', 'full', 'partial']))
type = attr.ib(type=str)
snapshot = attr.ib(type=Sha1Git)
metadata = attr.ib(type=Optional[Dict[str, object]],
default=None)
visit = attr.ib(type=Optional[int],
validator=attr.validators.optional([]))
default=None)
"""Should not be set before calling 'origin_visit_add()'."""
def to_dict(self):
"""Serializes the date as a string and omits the visit id if it is
`None`."""
ov = super().to_dict()
ov['date'] = str(self.date)
if ov['visit'] is None:
del ov['visit']
return ov
......@@ -120,10 +127,14 @@ class OriginVisit(BaseModel):
@classmethod
def from_dict(cls, d):
"""Parses the date from a string, and accepts missing visit ids."""
d = d.copy()
date = d.pop('date')
return cls(
origin=Origin.from_dict(d['origin']),
date=dateutil.parser.parse(d['date']),
visit=d.get('visit'))
origin=Origin.from_dict(d.pop('origin')),
date=(date
if isinstance(date, datetime.datetime)
else dateutil.parser.parse(date)),
**d)
class TargetType(Enum):
......@@ -183,7 +194,7 @@ class Snapshot(BaseModel):
return {
'id': self.id,
'branches': {
name: branch.to_dict()
name: branch.to_dict() if branch else None
for (name, branch) in self.branches.items()
}
}
......@@ -193,7 +204,7 @@ class Snapshot(BaseModel):
return cls(
id=d['id'],
branches={
name: SnapshotBranch.from_dict(branch)
name: SnapshotBranch.from_dict(branch) if branch else None
for (name, branch) in d['branches'].items()
})
......@@ -227,6 +238,8 @@ class Release(BaseModel):
rel = attr.asdict(self)
rel['date'] = self.date.to_dict() if self.date is not None else None
rel['target_type'] = rel['target_type'].value
if rel['metadata'] is None:
del rel['metadata']
return rel
@classmethod
......
......@@ -3,6 +3,8 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import datetime
import attr
from hypothesis import given
......@@ -30,7 +32,8 @@ def assert_nested_dict(obj):
elif isinstance(obj, list):
for value in obj:
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
else:
assert False, obj
......@@ -56,4 +59,4 @@ def test_dicts_generation(obj_type_and_obj):
assert object_['target_type'] in target_types
elif obj_type == 'snapshot':
for branch in object_['branches'].values():
assert branch['target_type'] in target_types
assert branch is None or branch['target_type'] in target_types
v0.0.41-0-g01a5d4c
\ No newline at end of file
v0.0.42-0-g6df68b0
\ 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