Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-indexer
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-indexer
Commits
40ced956
Unverified
Commit
40ced956
authored
5 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
tests: Migrate some tests to pytest
parent
28b03c5b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/indexer/tests/storage/test_converters.py
+155
-156
155 additions, 156 deletions
swh/indexer/tests/storage/test_converters.py
swh/indexer/tests/storage/test_storage.py
+34
-38
34 additions, 38 deletions
swh/indexer/tests/storage/test_storage.py
with
189 additions
and
194 deletions
swh/indexer/tests/storage/test_converters.py
+
155
−
156
View file @
40ced956
# Copyright (C) 2015-20
19
The Software Heritage developers
# Copyright (C) 2015-20
20
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
import
unittest
from
swh.indexer.storage
import
converters
class
TestConverters
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
maxDiff
=
None
def
test_ctags_to_db
(
self
):
input_ctag
=
{
'
id
'
:
b
'
some-id
'
,
'
indexer_configuration_id
'
:
100
,
'
ctags
'
:
[
{
'
name
'
:
'
some-name
'
,
'
kind
'
:
'
some-kind
'
,
'
line
'
:
10
,
'
lang
'
:
'
Yaml
'
,
},
{
'
name
'
:
'
main
'
,
'
kind
'
:
'
function
'
,
'
line
'
:
12
,
'
lang
'
:
'
Yaml
'
,
},
]
}
expected_ctags
=
[
def
test_ctags_to_db
():
input_ctag
=
{
'
id
'
:
b
'
some-id
'
,
'
indexer_configuration_id
'
:
100
,
'
ctags
'
:
[
{
'
id
'
:
b
'
some-id
'
,
'
name
'
:
'
some-name
'
,
'
kind
'
:
'
some-kind
'
,
'
line
'
:
10
,
'
lang
'
:
'
Yaml
'
,
'
indexer_configuration_id
'
:
100
,
},
{
'
id
'
:
b
'
some-id
'
,
'
name
'
:
'
main
'
,
'
kind
'
:
'
function
'
,
'
line
'
:
12
,
'
lang
'
:
'
Yaml
'
,
'
indexer_configuration_id
'
:
100
,
}]
},
]
}
# when
actual_ctags
=
list
(
converters
.
ctags_to_db
(
input_ctag
))
# then
self
.
assertEqual
(
actual_ctags
,
expected_ctags
)
def
test_db_to_ctags
(
self
):
input_ctags
=
{
expected_ctags
=
[
{
'
id
'
:
b
'
some-id
'
,
'
name
'
:
'
some-name
'
,
'
kind
'
:
'
some-kind
'
,
'
line
'
:
10
,
'
lang
'
:
'
Yaml
'
,
'
tool_id
'
:
200
,
'
tool_name
'
:
'
some-toolname
'
,
'
tool_version
'
:
'
some-toolversion
'
,
'
tool_configuration
'
:
{}
}
expected_ctags
=
{
'
indexer_configuration_id
'
:
100
,
},
{
'
id
'
:
b
'
some-id
'
,
'
name
'
:
'
some-name
'
,
'
kind
'
:
'
some-kind
'
,
'
line
'
:
1
0
,
'
name
'
:
'
main
'
,
'
kind
'
:
'
function
'
,
'
line
'
:
1
2
,
'
lang
'
:
'
Yaml
'
,
'
tool
'
:
{
'
id
'
:
200
,
'
name
'
:
'
some-toolname
'
,
'
version
'
:
'
some-toolversion
'
,
'
configuration
'
:
{},
}
}
# when
actual_ctags
=
converters
.
db_to_ctags
(
input_ctags
)
# then
self
.
assertEqual
(
actual_ctags
,
expected_ctags
)
def
test_db_to_mimetype
(
self
):
input_mimetype
=
{
'
id
'
:
b
'
some-id
'
,
'
tool_id
'
:
10
,
'
tool_name
'
:
'
some-toolname
'
,
'
tool_version
'
:
'
some-toolversion
'
,
'
tool_configuration
'
:
{},
'
encoding
'
:
b
'
ascii
'
,
'
mimetype
'
:
b
'
text/plain
'
,
}
expected_mimetype
=
{
'
id
'
:
b
'
some-id
'
,
'
encoding
'
:
b
'
ascii
'
,
'
mimetype
'
:
b
'
text/plain
'
,
'
tool
'
:
{
'
id
'
:
10
,
'
name
'
:
'
some-toolname
'
,
'
version
'
:
'
some-toolversion
'
,
'
configuration
'
:
{},
}
}
actual_mimetype
=
converters
.
db_to_mimetype
(
input_mimetype
)
self
.
assertEqual
(
actual_mimetype
,
expected_mimetype
)
def
test_db_to_language
(
self
):
input_language
=
{
'
id
'
:
b
'
some-id
'
,
'
tool_id
'
:
20
,
'
tool_name
'
:
'
some-toolname
'
,
'
tool_version
'
:
'
some-toolversion
'
,
'
tool_configuration
'
:
{},
'
lang
'
:
b
'
css
'
,
}
expected_language
=
{
'
id
'
:
b
'
some-id
'
,
'
lang
'
:
b
'
css
'
,
'
tool
'
:
{
'
id
'
:
20
,
'
name
'
:
'
some-toolname
'
,
'
version
'
:
'
some-toolversion
'
,
'
configuration
'
:
{},
}
'
indexer_configuration_id
'
:
100
,
}]
# when
actual_ctags
=
list
(
converters
.
ctags_to_db
(
input_ctag
))
# then
assert
actual_ctags
==
expected_ctags
def
test_db_to_ctags
():
input_ctags
=
{
'
id
'
:
b
'
some-id
'
,
'
name
'
:
'
some-name
'
,
'
kind
'
:
'
some-kind
'
,
'
line
'
:
10
,
'
lang
'
:
'
Yaml
'
,
'
tool_id
'
:
200
,
'
tool_name
'
:
'
some-toolname
'
,
'
tool_version
'
:
'
some-toolversion
'
,
'
tool_configuration
'
:
{}
}
expected_ctags
=
{
'
id
'
:
b
'
some-id
'
,
'
name
'
:
'
some-name
'
,
'
kind
'
:
'
some-kind
'
,
'
line
'
:
10
,
'
lang
'
:
'
Yaml
'
,
'
tool
'
:
{
'
id
'
:
200
,
'
name
'
:
'
some-toolname
'
,
'
version
'
:
'
some-toolversion
'
,
'
configuration
'
:
{},
}
actual_language
=
converters
.
db_to_language
(
input_language
)
self
.
assertEqual
(
actual_language
,
expected_language
)
def
test_db_to_fossology_license
(
self
):
input_license
=
{
'
id
'
:
b
'
some-id
'
,
'
tool_id
'
:
20
,
'
tool_name
'
:
'
nomossa
'
,
'
tool_version
'
:
'
5.22
'
,
'
tool_configuration
'
:
{},
'
licenses
'
:
[
'
GPL2.0
'
],
}
# when
actual_ctags
=
converters
.
db_to_ctags
(
input_ctags
)
# then
assert
actual_ctags
==
expected_ctags
def
test_db_to_mimetype
():
input_mimetype
=
{
'
id
'
:
b
'
some-id
'
,
'
tool_id
'
:
10
,
'
tool_name
'
:
'
some-toolname
'
,
'
tool_version
'
:
'
some-toolversion
'
,
'
tool_configuration
'
:
{},
'
encoding
'
:
b
'
ascii
'
,
'
mimetype
'
:
b
'
text/plain
'
,
}
expected_mimetype
=
{
'
id
'
:
b
'
some-id
'
,
'
encoding
'
:
b
'
ascii
'
,
'
mimetype
'
:
b
'
text/plain
'
,
'
tool
'
:
{
'
id
'
:
10
,
'
name
'
:
'
some-toolname
'
,
'
version
'
:
'
some-toolversion
'
,
'
configuration
'
:
{},
}
expected_license
=
{
'
licenses
'
:
[
'
GPL2.0
'
],
'
tool
'
:
{
'
id
'
:
20
,
'
name
'
:
'
nomossa
'
,
'
version
'
:
'
5.22
'
,
'
configuration
'
:
{},
}
}
actual_mimetype
=
converters
.
db_to_mimetype
(
input_mimetype
)
assert
actual_mimetype
==
expected_mimetype
def
test_db_to_language
():
input_language
=
{
'
id
'
:
b
'
some-id
'
,
'
tool_id
'
:
20
,
'
tool_name
'
:
'
some-toolname
'
,
'
tool_version
'
:
'
some-toolversion
'
,
'
tool_configuration
'
:
{},
'
lang
'
:
b
'
css
'
,
}
expected_language
=
{
'
id
'
:
b
'
some-id
'
,
'
lang
'
:
b
'
css
'
,
'
tool
'
:
{
'
id
'
:
20
,
'
name
'
:
'
some-toolname
'
,
'
version
'
:
'
some-toolversion
'
,
'
configuration
'
:
{},
}
actual_license
=
converters
.
db_to_fossology_license
(
input_license
)
self
.
assertEqual
(
actual_license
,
expected_license
)
def
test_db_to_metadata
(
self
):
input_metadata
=
{
'
id
'
:
b
'
some-id
'
,
'
tool_id
'
:
20
,
'
tool_name
'
:
'
some-toolname
'
,
'
tool_version
'
:
'
some-toolversion
'
,
'
tool_configuration
'
:
{},
'
metadata
'
:
b
'
metadata
'
,
}
actual_language
=
converters
.
db_to_language
(
input_language
)
assert
actual_language
==
expected_language
def
test_db_to_fossology_license
():
input_license
=
{
'
id
'
:
b
'
some-id
'
,
'
tool_id
'
:
20
,
'
tool_name
'
:
'
nomossa
'
,
'
tool_version
'
:
'
5.22
'
,
'
tool_configuration
'
:
{},
'
licenses
'
:
[
'
GPL2.0
'
],
}
expected_license
=
{
'
licenses
'
:
[
'
GPL2.0
'
],
'
tool
'
:
{
'
id
'
:
20
,
'
name
'
:
'
nomossa
'
,
'
version
'
:
'
5.22
'
,
'
configuration
'
:
{},
}
expected_metadata
=
{
'
id
'
:
b
'
some-id
'
,
'
metadata
'
:
b
'
metadata
'
,
'
tool
'
:
{
'
id
'
:
20
,
'
name
'
:
'
some-toolname
'
,
'
version
'
:
'
some-toolversion
'
,
'
configuration
'
:
{},
}
}
actual_license
=
converters
.
db_to_fossology_license
(
input_license
)
assert
actual_license
==
expected_license
def
test_db_to_metadata
():
input_metadata
=
{
'
id
'
:
b
'
some-id
'
,
'
tool_id
'
:
20
,
'
tool_name
'
:
'
some-toolname
'
,
'
tool_version
'
:
'
some-toolversion
'
,
'
tool_configuration
'
:
{},
'
metadata
'
:
b
'
metadata
'
,
}
expected_metadata
=
{
'
id
'
:
b
'
some-id
'
,
'
metadata
'
:
b
'
metadata
'
,
'
tool
'
:
{
'
id
'
:
20
,
'
name
'
:
'
some-toolname
'
,
'
version
'
:
'
some-toolversion
'
,
'
configuration
'
:
{},
}
}
actual_metadata
=
converters
.
db_to_metadata
(
input_metadata
)
actual_metadata
=
converters
.
db_to_metadata
(
input_metadata
)
self
.
assertEqual
(
actual_metadata
,
expected_metadata
)
assert
actual_metadata
==
expected_metadata
This diff is collapsed.
Click to expand it.
swh/indexer/tests/storage/test_storage.py
+
34
−
38
View file @
40ced956
...
...
@@ -68,6 +68,40 @@ def expected_summary(
}
def
test_check_config
(
swh_indexer_storage
):
assert
swh_indexer_storage
.
check_config
(
check_write
=
True
)
assert
swh_indexer_storage
.
check_config
(
check_write
=
False
)
def
test_types
(
swh_indexer_storage
):
"""
Checks all methods of StorageInterface are implemented by this
backend, and that they have the same signature.
"""
# Create an instance of the protocol (which cannot be instantiated
# directly, so this creates a subclass, then instantiates it)
interface
=
type
(
'
_
'
,
(
IndexerStorageInterface
,),
{})()
assert
'
content_mimetype_add
'
in
dir
(
interface
)
missing_methods
=
[]
for
meth_name
in
dir
(
interface
):
if
meth_name
.
startswith
(
'
_
'
):
continue
interface_meth
=
getattr
(
interface
,
meth_name
)
try
:
concrete_meth
=
getattr
(
swh_indexer_storage
,
meth_name
)
except
AttributeError
:
missing_methods
.
append
(
meth_name
)
continue
expected_signature
=
inspect
.
signature
(
interface_meth
)
actual_signature
=
inspect
.
signature
(
concrete_meth
)
assert
expected_signature
==
actual_signature
,
meth_name
assert
missing_methods
==
[]
class
StorageETypeTester
:
"""
Base class for testing a series of common behaviour between a bunch of
endpoint types supported by an IndexerStorage.
...
...
@@ -1893,41 +1927,3 @@ class TestIndexerStorageIndexerCondifuration:
expected_tool
[
'
id
'
]
=
actual_tool
[
'
id
'
]
assert
expected_tool
==
actual_tool
class
TestIndexerStorageMisc
:
"""
Misc endpoints tests for the IndexerStorage.
"""
def
test_check_config
(
self
,
swh_indexer_storage
):
storage
=
swh_indexer_storage
assert
storage
.
check_config
(
check_write
=
True
)
assert
storage
.
check_config
(
check_write
=
False
)
def
test_types
(
self
,
swh_indexer_storage
):
"""
Checks all methods of StorageInterface are implemented by this
backend, and that they have the same signature.
"""
# Create an instance of the protocol (which cannot be instantiated
# directly, so this creates a subclass, then instantiates it)
interface
=
type
(
'
_
'
,
(
IndexerStorageInterface
,),
{})()
assert
'
content_mimetype_add
'
in
dir
(
interface
)
missing_methods
=
[]
for
meth_name
in
dir
(
interface
):
if
meth_name
.
startswith
(
'
_
'
):
continue
interface_meth
=
getattr
(
interface
,
meth_name
)
try
:
concrete_meth
=
getattr
(
swh_indexer_storage
,
meth_name
)
except
AttributeError
:
missing_methods
.
append
(
meth_name
)
continue
expected_signature
=
inspect
.
signature
(
interface_meth
)
actual_signature
=
inspect
.
signature
(
concrete_meth
)
assert
expected_signature
==
actual_signature
,
meth_name
assert
missing_methods
==
[]
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