Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container 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
Workers
Base Worker
Commits
07322a5a
Commit
07322a5a
authored
2 years ago
by
Chaza Abdelwahab
Committed by
Yoann Schneider
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fixed tests (finally)
parent
8cec3dfc
No related branches found
No related tags found
1 merge request
!179
Move developer setup in a dedicated method
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_base_worker.py
+17
-13
17 additions, 13 deletions
tests/test_base_worker.py
tests/test_merge.py
+1
-0
1 addition, 0 deletions
tests/test_merge.py
with
18 additions
and
13 deletions
tests/test_base_worker.py
+
17
−
13
View file @
07322a5a
...
...
@@ -49,7 +49,8 @@ def test_init_var_worker_version_id_missing(monkeypatch):
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
worker
"
])
monkeypatch
.
delenv
(
"
WORKER_VERSION_ID
"
)
worker
=
BaseWorker
()
worker
.
configure
()
worker
.
args
=
worker
.
parser
.
parse_args
()
worker
.
configure_for_developers
()
assert
worker
.
worker_version_id
is
None
assert
worker
.
is_read_only
is
True
assert
worker
.
config
==
{}
# default empty case
...
...
@@ -63,7 +64,8 @@ def test_init_var_worker_local_file(monkeypatch, tmp_path):
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
worker
"
,
"
-c
"
,
str
(
config
)])
monkeypatch
.
delenv
(
"
WORKER_VERSION_ID
"
)
worker
=
BaseWorker
()
worker
.
configure
()
worker
.
args
=
worker
.
parser
.
parse_args
()
worker
.
configure_for_developers
()
assert
worker
.
worker_version_id
is
None
assert
worker
.
is_read_only
is
True
assert
worker
.
config
==
{
"
localKey
"
:
"
abcdef123
"
}
# Use a local file for devs
...
...
@@ -71,12 +73,13 @@ def test_init_var_worker_local_file(monkeypatch, tmp_path):
config
.
unlink
()
def
test_cli_default
(
mocker
):
def
test_cli_default
(
mocker
,
mock_config_api
):
worker
=
BaseWorker
()
assert
logger
.
level
==
logging
.
NOTSET
assert
not
hasattr
(
worker
,
"
api_client
"
)
mocker
.
patch
.
object
(
sys
,
"
argv
"
,
[
"
worker
"
])
worker
.
args
=
worker
.
parser
.
parse_args
()
worker
.
configure
()
assert
not
worker
.
args
.
verbose
assert
logger
.
level
==
logging
.
NOTSET
...
...
@@ -88,18 +91,14 @@ def test_cli_default(mocker):
logger
.
setLevel
(
logging
.
NOTSET
)
def
test_cli_arg_verbose_given
(
mocker
):
def
test_cli_arg_verbose_given
(
mocker
,
mock_config_api
):
worker
=
BaseWorker
()
spy
=
mocker
.
spy
(
worker
,
"
add_arguments
"
)
assert
not
spy
.
called
assert
logger
.
level
==
logging
.
NOTSET
assert
not
hasattr
(
worker
,
"
api_client
"
)
mocker
.
patch
.
object
(
sys
,
"
argv
"
,
[
"
worker
"
,
"
-v
"
])
worker
.
args
=
worker
.
parser
.
parse_args
()
worker
.
configure
()
assert
spy
.
called
assert
spy
.
call_count
==
1
assert
worker
.
args
.
verbose
assert
logger
.
level
==
logging
.
DEBUG
assert
worker
.
api_client
...
...
@@ -110,14 +109,14 @@ def test_cli_arg_verbose_given(mocker):
logger
.
setLevel
(
logging
.
NOTSET
)
def
test_cli_envvar_debug_given
(
mocker
,
monkeypatch
):
def
test_cli_envvar_debug_given
(
mocker
,
monkeypatch
,
mock_config_api
):
worker
=
BaseWorker
()
assert
logger
.
level
==
logging
.
NOTSET
assert
not
hasattr
(
worker
,
"
api_client
"
)
mocker
.
patch
.
object
(
sys
,
"
argv
"
,
[
"
worker
"
])
monkeypatch
.
setenv
(
"
ARKINDEX_DEBUG
"
,
True
)
worker
.
args
=
worker
.
parser
.
parse_args
()
worker
.
configure
()
assert
logger
.
level
==
logging
.
DEBUG
assert
worker
.
api_client
...
...
@@ -137,7 +136,8 @@ def test_configure_dev_mode(mocker, monkeypatch):
monkeypatch
.
setenv
(
"
ARKINDEX_WORKER_RUN_ID
"
,
"
aaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
"
)
worker
.
configure
()
worker
.
args
=
worker
.
parser
.
parse_args
()
worker
.
configure_for_developers
()
assert
worker
.
args
.
dev
is
True
assert
worker
.
process_information
is
None
...
...
@@ -162,6 +162,7 @@ def test_configure_worker_run(mocker, monkeypatch, responses, mock_config_api):
f
"
http://testserver/api/v1/workers/configurations/
{
configuration_id
}
/
"
,
json
=
{
"
id
"
:
configuration_id
,
"
name
"
:
"
BBB
"
,
"
configuration
"
:
{
"
a
"
:
"
b
"
}},
)
worker
.
args
=
worker
.
parser
.
parse_args
()
worker
.
configure
()
assert
worker
.
user_configuration
==
{
"
a
"
:
"
b
"
}
...
...
@@ -183,6 +184,7 @@ def test_configure_user_configuration_defaults(
f
"
http://testserver/api/v1/imports/workers/
{
run_id
}
/
"
,
json
=
{
"
id
"
:
run_id
},
)
worker
.
args
=
worker
.
parser
.
parse_args
()
worker
.
configure
()
assert
worker
.
config
==
{
"
param_1
"
:
"
/some/path/file.pth
"
,
"
param_2
"
:
12
}
...
...
@@ -194,7 +196,7 @@ def test_configure_user_configuration_defaults(
@pytest.mark.parametrize
(
"
debug_dict
"
,
[{
"
debug
"
:
True
},
{
"
debug
"
:
False
}])
def
test_configure_user_config_debug
(
mocker
,
monkeypatch
,
responses
,
mock_config_api
,
debug_dict
mocker
,
monkeypatch
,
responses
,
debug_dict
,
mock_config_api
):
worker
=
BaseWorker
()
mocker
.
patch
.
object
(
sys
,
"
argv
"
,
[
"
worker
"
])
...
...
@@ -212,6 +214,7 @@ def test_configure_user_config_debug(
f
"
http://testserver/api/v1/workers/configurations/
{
configuration_id
}
/
"
,
json
=
{
"
id
"
:
configuration_id
,
"
name
"
:
"
BBB
"
,
"
configuration
"
:
debug_dict
},
)
worker
.
args
=
worker
.
parser
.
parse_args
()
worker
.
configure
()
assert
worker
.
user_configuration
==
debug_dict
...
...
@@ -238,6 +241,7 @@ def test_configure_worker_run_missing_conf(
f
"
http://testserver/api/v1/workers/configurations/
{
configuration_id
}
/
"
,
json
=
{
"
id
"
:
configuration_id
,
"
name
"
:
"
BBB
"
},
)
worker
.
args
=
worker
.
parser
.
parse_args
()
worker
.
configure
()
assert
worker
.
user_configuration
is
None
...
...
This diff is collapsed.
Click to expand it.
tests/test_merge.py
+
1
−
0
View file @
07322a5a
...
...
@@ -181,6 +181,7 @@ def test_merge_from_worker(
monkeypatch
.
setenv
(
"
PONOS_DATA
"
,
str
(
tmpdir
))
# Create the task's output dir, so that it can create its own database
(
tmpdir
/
"
my_task
"
).
mkdir
()
mock_base_worker_with_cache
.
args
=
mock_base_worker_with_cache
.
parser
.
parse_args
()
mock_base_worker_with_cache
.
configure
()
mock_base_worker_with_cache
.
configure_cache
()
...
...
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