Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mpsd-software-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
MPSD Computational Science
mpsd-software-manager
Commits
5c441ea5
Commit
5c441ea5
authored
1 year ago
by
Hans Fangohr
Browse files
Options
Downloads
Patches
Plain Diff
additional tests
parent
464b60e1
No related branches found
Branches containing commit
No related tags found
1 merge request
!28
improve machine readable logging
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests.py
+34
-10
34 additions, 10 deletions
tests.py
with
34 additions
and
10 deletions
tests.py
+
34
−
10
View file @
5c441ea5
"""
Tests for mpsd-software-environment.py.
"""
import
importlib
import
logging
import
os
import
shutil
import
subprocess
...
...
@@ -317,18 +318,41 @@ def test_install_environment_zlib():
def
test_metadata_logging
(
tmp_path
):
"""
Test that metadata is logged and read correctly.
"""
# Test that the metadata is logged correctly
mod
.
set_up_logging
(
loglevel
=
"
debug
"
,
filename
=
tmp_path
/
"
test-metadata.log
"
)
key
=
"
important_key
"
value
=
"
important_value
"
mod
.
log_metadata
(
key
,
value
)
open_tag
=
mod
.
config_vars
[
"
metadata_tag_open
"
]
close_tag
=
mod
.
config_vars
[
"
metadata_tag_close
"
]
expected_log
=
f
"
{
open_tag
}{
key
}
:
{
value
}{
close_tag
}
"
filename
=
tmp_path
/
"
test-metadata.log
"
print
(
f
"
Writing to
{
filename
}
"
)
mod
.
set_up_logging
(
loglevel
=
"
debug
"
,
filename
=
filename
)
# our test data
keys
=
[
"
important_key
"
,
"
important_value2
"
]
values
=
[
"
important_value
"
,
"
important_value2
"
]
expected_log_entries
=
[]
for
key
,
value
in
zip
(
keys
,
values
):
mod
.
log_metadata
(
key
,
value
)
mod
.
log_metadata
(
key
,
value
)
open_tag
=
mod
.
config_vars
[
"
metadata_tag_open
"
]
close_tag
=
mod
.
config_vars
[
"
metadata_tag_close
"
]
expected_log
=
f
"
{
open_tag
}{
key
}
:
{
value
}{
close_tag
}
"
expected_log_entries
.
append
(
expected_log
)
logging
.
info
(
f
"
Add some other info (after adding
{
key
=
}
)
"
)
logging
.
debug
(
"
Add some other info
"
)
logging
.
warning
(
"
Add some other info
"
)
# Check that relevant lines show up in the log file somewhere
with
open
(
tmp_path
/
"
test-metadata.log
"
,
"
r
"
)
as
f
:
assert
expected_log
in
f
.
read
()
# Test that the metadata is read correctly
logfile_content
=
f
.
read
()
for
expected_log
in
expected_log_entries
:
assert
expected_log
in
logfile_content
# Test that the metadata is read correctly using our parser
read_dict
=
mod
.
read_metadata_from_logfile
(
tmp_path
/
"
test-metadata.log
"
)
assert
read_dict
[
key
]
==
value
# check all entries are in the file
for
key
,
value
in
zip
(
keys
,
values
):
read_dict
[
key
]
==
value
# check no additional entries are there
assert
len
(
read_dict
)
==
len
(
keys
)
def
test_interface
(
tmp_path
):
...
...
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