Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-core
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
Antoine Lambert
swh-core
Commits
5cda0ca6
Verified
Commit
5cda0ca6
authored
2 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
cli.db: Use attribute current_version instead of undeclared getter
Related to T4284
parent
f18016af
No related branches found
Branches containing commit
Tags
v2.16.1
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
swh/core/cli/db.py
+6
-8
6 additions, 8 deletions
swh/core/cli/db.py
swh/core/db/tests/conftest.py
+2
-2
2 additions, 2 deletions
swh/core/db/tests/conftest.py
swh/core/db/tests/test_cli.py
+1
-1
1 addition, 1 deletion
swh/core/db/tests/test_cli.py
with
9 additions
and
11 deletions
swh/core/cli/db.py
+
6
−
8
View file @
5cda0ca6
...
...
@@ -198,16 +198,14 @@ def db_init(ctx, module, dbname, flavor, initial_version):
datastore_factory
=
getattr
(
import_swhmodule
(
module
),
"
get_datastore
"
,
None
)
if
datastore_factory
:
datastore
=
datastore_factory
(
**
cfg
)
try
:
get_current_version
=
datastore
.
get_current_version
except
AttributeError
:
if
not
hasattr
(
datastore
,
"
current_version
"
):
logger
.
warning
(
"
Datastore %s does not
implement
the
"
"'
get_
current_version
()
'
method
"
,
"
Datastore %s does not
declare
the
"
"'
current_version
'
attribute
"
,
datastore
,
)
else
:
code_version
=
get_
current_version
()
code_version
=
datastore
.
current_version
logger
.
info
(
"
Initializing database version to %s from the %s datastore
"
,
code_version
,
...
...
@@ -299,7 +297,7 @@ def db_version(ctx, module, show_all):
datastore_factory
=
getattr
(
import_swhmodule
(
db_module
),
"
get_datastore
"
,
None
)
if
datastore_factory
:
datastore
=
datastore_factory
(
**
cfg
)
code_version
=
datastore
.
get_
current_version
()
code_version
=
datastore
.
current_version
click
.
secho
(
f
"
current code version:
{
code_version
}
"
,
fg
=
"
green
"
if
code_version
==
db_version
else
"
red
"
,
...
...
@@ -387,7 +385,7 @@ def db_upgrade(ctx, module, to_version, interactive):
"
You cannot use this command on old-style datastore backend {db_module}
"
)
datastore
=
datastore_factory
(
**
cfg
)
ds_version
=
datastore
.
get_
current_version
()
ds_version
=
datastore
.
current_version
if
to_version
is
None
:
to_version
=
ds_version
if
to_version
>
ds_version
:
...
...
This diff is collapsed.
Click to expand it.
swh/core/db/tests/conftest.py
+
2
−
2
View file @
5cda0ca6
...
...
@@ -35,7 +35,7 @@ def mock_import_swhmodule(mocker, datadir):
set to `<mod>` and __file__ pointing to `data/<mod>/__init__.py`.
The Mock object also defines a `get_datastore()` attribute on which the
`
get_
current_version
()` exists and will return
42.
`current_version
` attribute is set to
42.
Typical usage::
...
...
@@ -54,7 +54,7 @@ def mock_import_swhmodule(mocker, datadir):
dirname
=
modname
.
split
(
"
.
"
,
1
)[
1
]
def
get_datastore
(
*
args
,
**
kw
):
return
mock
(
get_
current_version
=
lambda
:
42
)
return
mock
(
current_version
=
42
)
return
mock
(
__name__
=
modname
,
...
...
This diff is collapsed.
Click to expand it.
swh/core/db/tests/test_cli.py
+
1
−
1
View file @
5cda0ca6
...
...
@@ -254,7 +254,7 @@ def test_cli_swh_db_upgrade_new_api(cli_runner, postgresql, datadir, mocker, tmp
dirname
=
modname
.
split
(
"
.
"
,
1
)[
1
]
def
get_datastore
(
cls
,
**
kw
):
return
mocker
.
MagicMock
(
get_
current_version
=
lambda
:
current_version
)
return
mocker
.
MagicMock
(
current_version
=
current_version
)
return
mocker
.
MagicMock
(
__name__
=
modname
,
...
...
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