Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-model
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nicolas Dandrimont
swh-model
Commits
e9a4c751
Verified
Commit
e9a4c751
authored
5 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
model: Add new OriginVisitUpdate model object + test strategy
(pairing with
@vlorentz
) Related to T2310
parent
accca603
No related branches found
Branches containing commit
Tags
v0.0.63
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
swh/model/hypothesis_strategies.py
+21
-6
21 additions, 6 deletions
swh/model/hypothesis_strategies.py
swh/model/model.py
+17
-0
17 additions, 0 deletions
swh/model/model.py
swh/model/tests/test_model.py
+11
-2
11 additions, 2 deletions
swh/model/tests/test_model.py
with
49 additions
and
8 deletions
swh/model/hypothesis_strategies.py
+
21
−
6
View file @
e9a4c751
# Copyright (C) 2019 The Software Heritage developers
# Copyright (C) 2019
-2020
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
...
@@ -15,8 +15,8 @@ from hypothesis.strategies import (
...
@@ -15,8 +15,8 @@ from hypothesis.strategies import (
from
.from_disk
import
DentryPerms
from
.from_disk
import
DentryPerms
from
.model
import
(
from
.model
import
(
Person
,
Timestamp
,
TimestampWithTimezone
,
Origin
,
OriginVisit
,
Person
,
Timestamp
,
TimestampWithTimezone
,
Origin
,
OriginVisit
,
Snapshot
,
SnapshotBranch
,
TargetType
,
Release
,
Revision
,
OriginVisitUpdate
,
Snapshot
,
SnapshotBranch
,
TargetType
,
Release
,
Directory
,
DirectoryEntry
,
Content
,
SkippedContent
Revision
,
Directory
,
DirectoryEntry
,
Content
,
SkippedContent
)
)
from
.identifiers
import
snapshot_identifier
,
identifier_to_bytes
from
.identifiers
import
snapshot_identifier
,
identifier_to_bytes
...
@@ -85,7 +85,22 @@ def origin_visits():
...
@@ -85,7 +85,22 @@ def origin_visits():
origin
=
urls
(),
origin
=
urls
(),
status
=
sampled_from
([
'
ongoing
'
,
'
full
'
,
'
partial
'
]),
status
=
sampled_from
([
'
ongoing
'
,
'
full
'
,
'
partial
'
]),
type
=
pgsql_text
(),
type
=
pgsql_text
(),
snapshot
=
optional
(
sha1_git
()))
snapshot
=
optional
(
sha1_git
()),
)
def
metadata_dicts
():
return
dictionaries
(
pgsql_text
(),
pgsql_text
())
def
origin_visit_updates
():
return
builds
(
OriginVisitUpdate
,
visit
=
integers
(
0
,
1000
),
origin
=
urls
(),
status
=
sampled_from
([
'
ongoing
'
,
'
full
'
,
'
partial
'
]),
snapshot
=
optional
(
sha1_git
()),
metadata
=
one_of
(
none
(),
metadata_dicts
()))
@composite
@composite
...
@@ -104,8 +119,7 @@ def releases(draw):
...
@@ -104,8 +119,7 @@ def releases(draw):
author
=
author
)
author
=
author
)
def
revision_metadata
():
revision_metadata
=
metadata_dicts
return
dictionaries
(
pgsql_text
(),
pgsql_text
())
def
revisions
():
def
revisions
():
...
@@ -238,6 +252,7 @@ def objects():
...
@@ -238,6 +252,7 @@ def objects():
return
one_of
(
return
one_of
(
origins
().
map
(
lambda
x
:
(
'
origin
'
,
x
)),
origins
().
map
(
lambda
x
:
(
'
origin
'
,
x
)),
origin_visits
().
map
(
lambda
x
:
(
'
origin_visit
'
,
x
)),
origin_visits
().
map
(
lambda
x
:
(
'
origin_visit
'
,
x
)),
origin_visit_updates
().
map
(
lambda
x
:
(
'
origin_visit_update
'
,
x
)),
snapshots
().
map
(
lambda
x
:
(
'
snapshot
'
,
x
)),
snapshots
().
map
(
lambda
x
:
(
'
snapshot
'
,
x
)),
releases
().
map
(
lambda
x
:
(
'
release
'
,
x
)),
releases
().
map
(
lambda
x
:
(
'
release
'
,
x
)),
revisions
().
map
(
lambda
x
:
(
'
revision
'
,
x
)),
revisions
().
map
(
lambda
x
:
(
'
revision
'
,
x
)),
...
...
This diff is collapsed.
Click to expand it.
swh/model/model.py
+
17
−
0
View file @
e9a4c751
...
@@ -234,6 +234,23 @@ class OriginVisit(BaseModel):
...
@@ -234,6 +234,23 @@ class OriginVisit(BaseModel):
**
d
)
**
d
)
@attr.s
(
frozen
=
True
)
class
OriginVisitUpdate
(
BaseModel
):
"""
Represents a visit update of an origin at a given point in time.
"""
origin
=
attr
.
ib
(
type
=
str
)
visit
=
attr
.
ib
(
type
=
int
)
date
=
attr
.
ib
(
type
=
datetime
.
datetime
)
status
=
attr
.
ib
(
type
=
str
,
validator
=
attr
.
validators
.
in_
([
'
ongoing
'
,
'
full
'
,
'
partial
'
]))
snapshot
=
attr
.
ib
(
type
=
Optional
[
Sha1Git
])
metadata
=
attr
.
ib
(
type
=
Optional
[
Dict
[
str
,
object
]],
default
=
None
)
class
TargetType
(
Enum
):
class
TargetType
(
Enum
):
"""
The type of content pointed to by a snapshot branch. Usually a
"""
The type of content pointed to by a snapshot branch. Usually a
revision or an alias.
"""
revision or an alias.
"""
...
...
This diff is collapsed.
Click to expand it.
swh/model/tests/test_model.py
+
11
−
2
View file @
e9a4c751
# Copyright (C) 2019 The Software Heritage developers
# Copyright (C) 2019
-2020
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
...
@@ -16,7 +16,9 @@ from swh.model.model import (
...
@@ -16,7 +16,9 @@ from swh.model.model import (
MissingData
,
Person
MissingData
,
Person
)
)
from
swh.model.hashutil
import
hash_to_bytes
,
MultiHash
from
swh.model.hashutil
import
hash_to_bytes
,
MultiHash
from
swh.model.hypothesis_strategies
import
objects
,
origins
,
origin_visits
from
swh.model.hypothesis_strategies
import
(
objects
,
origins
,
origin_visits
,
origin_visit_updates
)
from
swh.model.identifiers
import
(
from
swh.model.identifiers
import
(
directory_identifier
,
revision_identifier
,
release_identifier
,
directory_identifier
,
revision_identifier
,
release_identifier
,
snapshot_identifier
snapshot_identifier
...
@@ -61,6 +63,13 @@ def test_todict_origin_visits(origin_visit):
...
@@ -61,6 +63,13 @@ def test_todict_origin_visits(origin_visit):
assert
origin_visit
==
type
(
origin_visit
).
from_dict
(
obj
)
assert
origin_visit
==
type
(
origin_visit
).
from_dict
(
obj
)
@given
(
origin_visit_updates
())
def
test_todict_origin_visit_updates
(
origin_visit_update
):
obj
=
origin_visit_update
.
to_dict
()
assert
origin_visit_update
==
type
(
origin_visit_update
).
from_dict
(
obj
)
def
test_timestampwithtimezone_from_datetime
():
def
test_timestampwithtimezone_from_datetime
():
tz
=
datetime
.
timezone
(
datetime
.
timedelta
(
minutes
=+
60
))
tz
=
datetime
.
timezone
(
datetime
.
timedelta
(
minutes
=+
60
))
date
=
datetime
.
datetime
(
date
=
datetime
.
datetime
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment