Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-deposit
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
Model registry
Operate
Environments
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
Platform
Development
swh-deposit
Commits
a1d79323
Verified
Commit
a1d79323
authored
5 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
tests_utils: Migrate to pytest tests
parent
6ff940c8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!40
Migrate most deposit tests to pytest
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
swh/deposit/tests/test_utils.py
+97
-97
97 additions, 97 deletions
swh/deposit/tests/test_utils.py
with
97 additions
and
97 deletions
swh/deposit/tests/test_utils.py
+
97
−
97
View file @
a1d79323
...
...
@@ -48,127 +48,127 @@ def test_origin_url_from_ko():
utils
.
origin_url_from
(
deposit
)
class
UtilsTestCase
(
unittest
.
TestCase
):
"""
Utils library
def
test_merge
(
):
"""
Calling utils.merge on dicts should merge without losing information
"""
def
test_merge
(
self
):
"""
Calling utils.merge on dicts should merge without losing information
"""
d0
=
{
'
author
'
:
'
someone
'
,
'
license
'
:
[[
'
gpl2
'
]],
'
a
'
:
1
d0
=
{
'
author
'
:
'
someone
'
,
'
license
'
:
[[
'
gpl2
'
]],
'
a
'
:
1
}
d1
=
{
'
author
'
:
[
'
author0
'
,
{
'
name
'
:
'
author1
'
}],
'
license
'
:
[[
'
gpl3
'
]],
'
b
'
:
{
'
1
'
:
'
2
'
}
}
d1
=
{
'
author
'
:
[
'
author0
'
,
{
'
name
'
:
'
author1
'
}],
'
license
'
:
[[
'
gpl3
'
]],
'
b
'
:
{
'
1
'
:
'
2
'
}
d2
=
{
'
author
'
:
map
(
lambda
x
:
x
,
[
'
else
'
]),
'
license
'
:
'
mit
'
,
'
b
'
:
{
'
2
'
:
'
3
'
,
}
d2
=
{
'
author
'
:
map
(
lambda
x
:
x
,
[
'
else
'
]),
'
license
'
:
'
mit
'
,
'
b
'
:
{
'
2
'
:
'
3
'
,
}
}
d3
=
{
'
author
'
:
(
v
for
v
in
[
'
no one
'
]),
}
actual_merge
=
utils
.
merge
(
d0
,
d1
,
d2
,
d3
)
expected_merge
=
{
'
a
'
:
1
,
'
license
'
:
[[
'
gpl2
'
],
[
'
gpl3
'
],
'
mit
'
],
'
author
'
:
[
'
someone
'
,
'
author0
'
,
{
'
name
'
:
'
author1
'
},
'
else
'
,
'
no one
'
],
'
b
'
:
{
'
1
'
:
'
2
'
,
'
2
'
:
'
3
'
,
}
}
assert
actual_merge
==
expected_merge
d3
=
{
'
author
'
:
(
v
for
v
in
[
'
no one
'
]),
}
actual_merge
=
utils
.
merge
(
d0
,
d1
,
d2
,
d3
)
expected_merge
=
{
'
a
'
:
1
,
'
license
'
:
[[
'
gpl2
'
],
[
'
gpl3
'
],
'
mit
'
],
'
author
'
:
[
'
someone
'
,
'
author0
'
,
{
'
name
'
:
'
author1
'
},
'
else
'
,
'
no one
'
],
'
b
'
:
{
'
1
'
:
'
2
'
,
'
2
'
:
'
3
'
,
}
def
test_merge_2
():
d0
=
{
'
license
'
:
'
gpl2
'
,
'
runtime
'
:
{
'
os
'
:
'
unix derivative
'
}
self
.
assertEqual
(
actual_merge
,
expected_merge
)
}
def
test_merge_2
(
self
):
d0
=
{
'
license
'
:
'
gpl2
'
,
'
runtime
'
:
{
d1
=
{
'
license
'
:
'
gpl3
'
,
'
runtime
'
:
'
GNU/Linux
'
}
expected
=
{
'
license
'
:
[
'
gpl2
'
,
'
gpl3
'
],
'
runtime
'
:
[
{
'
os
'
:
'
unix derivative
'
}
}
},
'
GNU/Linux
'
],
}
d1
=
{
'
license
'
:
'
gpl3
'
,
'
runtime
'
:
'
GNU/Linux
'
}
actual
=
utils
.
merge
(
d0
,
d1
)
assert
actual
==
expected
expected
=
{
'
license
'
:
[
'
gpl2
'
,
'
gpl3
'
],
'
runtime
'
:
[
{
'
os
'
:
'
unix derivative
'
},
'
GNU/Linux
'
],
}
actual
=
utils
.
merge
(
d0
,
d1
)
self
.
assertEqual
(
actual
,
expected
)
def
test_merge_edge_cases
(
self
):
input_dict
=
{
'
license
'
:
[
'
gpl2
'
,
'
gpl3
'
],
'
runtime
'
:
[
{
'
os
'
:
'
unix derivative
'
},
'
GNU/Linux
'
],
}
# against empty dict
actual
=
utils
.
merge
(
input_dict
,
{})
self
.
assertEqual
(
actual
,
input_dict
)
def
test_merge_edge_cases
():
input_dict
=
{
'
license
'
:
[
'
gpl2
'
,
'
gpl3
'
],
'
runtime
'
:
[
{
'
os
'
:
'
unix derivative
'
},
'
GNU/Linux
'
],
}
# against empty dict
actual
=
utils
.
merge
(
input_dict
,
{})
assert
actual
==
input_dict
# against oneself
actual
=
utils
.
merge
(
input_dict
,
input_dict
,
input_dict
)
self
.
assertEqual
(
input_dict
,
input_dict
)
# against oneself
actual
=
utils
.
merge
(
input_dict
,
input_dict
,
input_dict
)
assert
actual
==
input_dict
def
test_merge_one_dict
(
self
):
"""
Merge one dict should result in the same dict value
"""
input_and_expected
=
{
'
anything
'
:
'
really
'
}
actual
=
utils
.
merge
(
input_and_expected
)
self
.
assertEqual
(
actual
,
input_and_expected
)
def
test_merge_one_dict
():
"""
Merge one dict should result in the same dict value
def
test_merge_raise
(
self
):
"""
Calling utils.merge with any no dict argument should raise
"""
input_and_expected
=
{
'
anything
'
:
'
really
'
}
actual
=
utils
.
merge
(
input_and_expected
)
assert
actual
==
input_and_expected
"""
d0
=
{
'
author
'
:
'
someone
'
,
'
a
'
:
1
}
d1
=
[
'
not a dict
'
]
def
test_merge_raise
():
"""
Calling utils.merge with any no dict argument should raise
"""
d0
=
{
'
author
'
:
'
someone
'
,
'
a
'
:
1
}
d1
=
[
'
not a dict
'
]
with
self
.
assertR
aises
(
ValueError
):
utils
.
merge
(
d0
,
d1
)
with
pytest
.
r
aises
(
ValueError
):
utils
.
merge
(
d0
,
d1
)
with
self
.
assertR
aises
(
ValueError
):
utils
.
merge
(
d1
,
d0
)
with
pytest
.
r
aises
(
ValueError
):
utils
.
merge
(
d1
,
d0
)
with
self
.
assertR
aises
(
ValueError
):
utils
.
merge
(
d1
)
with
pytest
.
r
aises
(
ValueError
):
utils
.
merge
(
d1
)
self
.
assertEqual
(
utils
.
merge
(
d0
)
,
d0
)
assert
utils
.
merge
(
d0
)
==
d0
@patch
(
'
swh.deposit.utils.normalize_timestamp
'
,
side_effect
=
lambda
x
:
x
)
...
...
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