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
ae163923
Commit
ae163923
authored
Jan 28, 2019
by
speckhard
Browse files
Put assert_log method in a new utils file for tests.
parent
b810be40
Pipeline
#42852
canceled with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tests/test_normalizing.py
View file @
ae163923
...
...
@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
json
import
pytest
from
nomad.parsing
import
LocalBackend
...
...
@@ -22,7 +21,7 @@ from tests.test_parsing import parsed_vasp_example # pylint: disable=unused-imp
from
tests.test_parsing
import
parsed_template_example
# pylint: disable=unused-import
from
tests.test_parsing
import
parsed_example
# pylint: disable=unused-import
from
tests.test_parsing
import
parsed_faulty_unknown_matid_example
# pylint: disable=unused-import
from
tests.utils
import
assert_log
def
run_normalize
(
backend
:
LocalBackend
)
->
LocalBackend
:
status
,
_
=
backend
.
status
...
...
@@ -84,11 +83,3 @@ def test_normalizer_faulty_matid(
assert_log
(
caplog
,
'ERROR'
,
unknown_class_error
)
assert_log
(
caplog
,
'ERROR'
,
wrong_class_for_no_sim_cell
)
def
assert_log
(
caplog
,
level
,
event_part
):
# TODO: @dts, find a new home for this fxn, sadly it can't go in conftest.py
record_receieved
=
False
for
record
in
caplog
.
get_records
(
when
=
'call'
):
if
record
.
levelname
==
level
:
record_receieved
|=
event_part
in
json
.
loads
(
record
.
msg
)[
'event'
]
assert
record_receieved
tests/utils.py
0 → 100644
View file @
ae163923
# Copyright 2019 Markus Scheidgen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an"AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Methods to help with testing of Nomad-FAIR."""
import
json
def
assert_log
(
caplog
,
level
,
event_part
):
"""
Assert whether a log message exists in the logs of the tests at a certain level.
Parameters
----------
caplog : pytest fixture
This informs pytest that we want to access the logs from a pytest test.
level : str
The level of type of log for which we will search (e.g. 'WARN',
'ERROR', 'DEBUG').
event_part : str
The error message we're after. We search the logs matching level if they
contain this string.
"""
record_receieved
=
False
for
record
in
caplog
.
get_records
(
when
=
'call'
):
if
record
.
levelname
==
level
:
if
(
event_part
in
json
.
loads
(
record
.
msg
)[
'event'
]):
record_receieved
=
True
# No need to look for more matches since we aren't counting matches.
break
assert
(
record_receieved
)
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