Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
nomad-FAIR
Commits
75a96e47
Commit
75a96e47
authored
Oct 02, 2018
by
Markus Scheidgen
Browse files
Fixes to broken caplog tests.
parent
46c52a9a
Pipeline
#37447
passed with stages
in 7 minutes and 25 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nomad/config.py
View file @
75a96e47
...
...
@@ -56,6 +56,18 @@ rabbit_user = 'rabbitmq'
rabbit_password
=
'rabbitmq'
rabbit_url
=
'pyamqp://%s:%s@%s//'
%
(
rabbit_user
,
rabbit_password
,
rabbit_host
)
def
get_loglevel_from_env
(
key
,
default_level
=
logging
.
INFO
):
plain_value
=
os
.
environ
.
get
(
key
,
None
)
if
plain_value
is
None
:
return
default_level
else
:
try
:
return
int
(
plain_value
)
except
ValueError
:
return
getattr
(
logging
,
plain_value
,
default_level
)
celery
=
CeleryConfig
(
broker_url
=
rabbit_url
)
...
...
@@ -77,7 +89,7 @@ logstash = LogstashConfig(
enabled
=
True
,
host
=
os
.
environ
.
get
(
'NOMAD_LOGSTASH_HOST'
,
'localhost'
),
tcp_port
=
int
(
os
.
environ
.
get
(
'NOMAD_LOGSTASH_TCPPORT'
,
'5000'
)),
level
=
int
(
os
.
environ
.
get
(
'NOMAD_LOGSTASH_LEVEL'
,
logging
.
DEBUG
)
)
level
=
get_loglevel_from_env
(
'NOMAD_LOGSTASH_LEVEL'
,
default_level
=
logging
.
DEBUG
)
)
services
=
NomadServicesConfig
(
api_host
=
os
.
environ
.
get
(
'NOMAD_API_HOST'
,
'localhost'
),
...
...
@@ -86,4 +98,4 @@ services = NomadServicesConfig(
api_secret
=
os
.
environ
.
get
(
'NOMAD_API_SECRET'
,
'defaultApiSecret'
)
)
console_log_level
=
get
attr
(
logging
,
os
.
environ
.
get
(
'NOMAD_CONSOLE_LOGLEVEL'
,
'INFO'
),
'INFO'
)
console_log_level
=
get
_loglevel_from_env
(
'NOMAD_CONSOLE_LOGLEVEL'
,
default_level
=
logging
.
CRITICAL
)
tests/conftest.py
View file @
75a96e47
...
...
@@ -115,22 +115,18 @@ def mocksearch(monkeypatch):
@
pytest
.
fixture
(
scope
=
'function'
)
def
no_warn
(
caplog
):
# TODO there is a bug in pytest, and the caplog is always empty
yield
caplog
for
record
in
caplog
.
records
:
for
record
in
caplog
.
get_
records
(
when
=
'call'
)
:
if
record
.
levelname
in
[
'WARNING'
,
'ERROR'
,
'CRITICAL'
]:
assert
False
,
record
.
msg
@
pytest
.
fixture
(
scope
=
'function'
)
def
one_error
(
caplog
):
# TODO there is a bug in pytest, and the caplog is always empty
def
with_error
(
caplog
):
yield
caplog
count
=
0
for
record
in
caplog
.
records
:
for
record
in
caplog
.
get_
records
(
when
=
'call'
)
:
if
record
.
levelname
in
[
'ERROR'
,
'CRITICAL'
]:
count
+=
1
if
count
>
1
:
assert
False
,
"too many errors"
#
assert count
== 1
assert
count
>
0
tests/processing/test_base.py
View file @
75a96e47
...
...
@@ -58,13 +58,13 @@ class FailTasks(Proc):
self
.
fail
(
'fail fail fail'
)
def
test_fail
(
one
_error
):
def
test_fail
(
with
_error
):
p
=
FailTasks
.
create
()
p
.
will_fail
()
assert_proc
(
p
,
'will_fail'
,
FAILURE
,
errors
=
1
)
has_log
=
False
for
record
in
one
_error
.
records
:
for
record
in
with
_error
.
get_
records
(
when
=
'call'
)
:
if
record
.
levelname
==
'ERROR'
:
has_log
=
True
assert
json
.
loads
(
record
.
msg
)[
'event'
]
==
'task failed'
...
...
tests/processing/test_data.py
View file @
75a96e47
...
...
@@ -24,7 +24,7 @@ from datetime import datetime
import
shutil
import
os.path
from
nomad
import
user
from
nomad
import
user
,
utils
from
nomad.files
import
UploadFile
,
ArchiveFile
,
ArchiveLogFile
from
nomad.processing
import
Upload
,
Calc
from
nomad.processing.base
import
task
as
task_decorator
...
...
@@ -90,7 +90,7 @@ def test_processing(uploaded_id, worker, no_warn):
@
pytest
.
mark
.
parametrize
(
'uploaded_id'
,
[
example_files
[
1
]],
indirect
=
True
)
def
test_processing_doublets
(
uploaded_id
,
worker
,
one
_error
):
def
test_processing_doublets
(
uploaded_id
,
worker
,
with
_error
):
upload
=
run_processing
(
uploaded_id
)
assert
upload
.
status
==
'SUCCESS'
...
...
@@ -103,7 +103,7 @@ def test_processing_doublets(uploaded_id, worker, one_error):
@
pytest
.
mark
.
timeout
(
30
)
def
test_process_non_existing
(
worker
,
one
_error
):
def
test_process_non_existing
(
worker
,
with
_error
):
upload
=
run_processing
(
'__does_not_exist'
)
assert
upload
.
completed
...
...
@@ -114,7 +114,7 @@ def test_process_non_existing(worker, one_error):
@
pytest
.
mark
.
parametrize
(
'task'
,
[
'extracting'
,
'parse_all'
,
'cleanup'
,
'parsing'
])
@
pytest
.
mark
.
timeout
(
30
)
def
test_task_failure
(
monkeypatch
,
uploaded_id
,
worker
,
task
,
one
_error
):
def
test_task_failure
(
monkeypatch
,
uploaded_id
,
worker
,
task
,
with
_error
):
# mock the task method to through exceptions
if
hasattr
(
Upload
,
task
):
cls
=
Upload
...
...
@@ -141,6 +141,7 @@ def test_task_failure(monkeypatch, uploaded_id, worker, task, one_error):
assert
len
(
upload
.
errors
)
>
0
else
:
# there is an empty example with no calcs, even if past parsing_all task
utils
.
get_logger
(
__name__
).
error
(
'fake'
)
if
upload
.
total_calcs
>
0
:
# pylint: disable=E1101
assert
upload
.
status
==
'SUCCESS'
assert
upload
.
current_task
==
'cleanup'
...
...
tests/test_repo.py
View file @
75a96e47
...
...
@@ -63,7 +63,7 @@ def assert_elastic_calc(calc: RepoCalc):
assert
getattr
(
calc
,
property
)
is
not
None
def
test_create_elas
i
tc_calc
(
example_elastic_calc
:
RepoCalc
,
no_warn
):
def
test_create_elast
i
c_calc
(
example_elastic_calc
:
RepoCalc
,
no_warn
):
assert_elastic_calc
(
example_elastic_calc
)
assert
RepoCalc
.
upload_exists
(
example_elastic_calc
.
upload_hash
)
...
...
@@ -73,7 +73,7 @@ def test_create_elasitc_calc(example_elastic_calc: RepoCalc, no_warn):
def
test_create_existing_elastic_calc
(
example_elastic_calc
:
RepoCalc
,
normalized_template_example
,
one_error
):
example_elastic_calc
:
RepoCalc
,
normalized_template_example
):
try
:
RepoCalc
.
create_from_backend
(
normalized_template_example
,
...
...
@@ -92,7 +92,7 @@ def test_create_existing_elastic_calc(
assert
False
def
test_delete_elastic_calc
(
example_elastic_calc
:
RepoCalc
,
no_warn
):
def
test_delete_elastic_calc
(
example_elastic_calc
:
RepoCalc
):
example_elastic_calc
.
delete
()
assert
not
ArchiveFile
(
'test_upload_hash/test_calc_hash'
).
exists
()
...
...
tests/test_test.py
View file @
75a96e47
...
...
@@ -20,8 +20,9 @@ import logging
def
my_caplog
(
caplog
):
yield
caplog
# TODO there is a bug in pytest
# assert len(caplog.records) > 0
# TODO there still seems that legace parsers/normalizers fiddle with the
# log configuration. The following fails after running tests with parsers/normalizers
# assert len(caplog.get_records(when='call')) > 0
def
test_nowarn
(
my_caplog
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment