Skip to content

Commit 36acfaa

Browse files
committed
add test for parse function
1 parent d374e9d commit 36acfaa

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

app/tests/components_tests/test_backends.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from grandchallenge.components.backends.exceptions import ComponentException
2525
from grandchallenge.components.backends.utils import (
2626
_filter_members,
27+
parse_structured_log,
2728
user_error,
2829
)
2930
from grandchallenge.components.models import (
@@ -867,3 +868,39 @@ def test_invocation_results_signature_verified(settings):
867868
)
868869

869870
assert executor._get_inference_result() == inference_result
871+
872+
873+
def test_parse_structured_logs_filters_task():
874+
log_with_task = json.dumps(
875+
{
876+
"log": "message with task",
877+
"source": "stdout",
878+
"internal": False,
879+
"task": "1",
880+
}
881+
)
882+
log_without_task = json.dumps(
883+
{
884+
"log": "message without task",
885+
"source": "stdout",
886+
"internal": False,
887+
"task": None,
888+
}
889+
)
890+
891+
parsed_log = parse_structured_log(log=log_with_task, task="1")
892+
893+
assert parsed_log.message == "message with task"
894+
895+
parsed_log = parse_structured_log(log=log_without_task, task="1")
896+
897+
assert parsed_log is None
898+
899+
parsed_log = parse_structured_log(log=log_with_task, task=None)
900+
901+
# when `task` is None, messages with a task are __included__
902+
assert parsed_log.message == "message with task"
903+
904+
parsed_log = parse_structured_log(log=log_without_task, task=None)
905+
906+
assert parsed_log.message == "message without task"

0 commit comments

Comments
 (0)