Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/slurm_plugin/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def read_json(file_path, default=None):
)
raise
else:
logger.info("Unable to read file '%s'. Using default: %s", file_path, default)
logger.info("Unable to read file '%s' due to an exception: %s. Using default: %s", file_path, e, default)
return default


Expand Down
16 changes: 15 additions & 1 deletion tests/slurm_plugin/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import pytest
from assertpy import assert_that
from common.utils import time_is_up
from slurm_plugin.common import TIMESTAMP_FORMAT, get_clustermgtd_heartbeat
from slurm_plugin.common import TIMESTAMP_FORMAT, get_clustermgtd_heartbeat, read_json


@pytest.mark.parametrize(
Expand Down Expand Up @@ -76,3 +76,17 @@ def test_get_clustermgtd_heartbeat(time, expected_parsed_time, mocker):
return_value=f"some_random_stdout\n{time.strftime(TIMESTAMP_FORMAT)}",
)
assert_that(get_clustermgtd_heartbeat("some file path")).is_equal_to(expected_parsed_time)


@pytest.mark.parametrize(
"json_file, log_assertion",
[
("test_read_json/faulty.json", lambda logs: "Failed with exception:" in logs),
("test_read_json/standard.json", lambda logs: "Failed with exception:" not in logs),
],
)
def test_read_json(test_datadir, caplog, json_file, log_assertion):
json_file_path = str(test_datadir.joinpath(json_file))
with pytest.raises(Exception):
read_json(json_file_path)
assert log_assertion
5 changes: 5 additions & 0 deletions tests/slurm_plugin/test_common/test_read_json/faulty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
    "test_property_1": {
                    "test_property_2": "test_value"
                }
}
5 changes: 5 additions & 0 deletions tests/slurm_plugin/test_common/test_read_json/standard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"test_property_1": {
"test_property_2": "test_value"
}
}