|
5 | 5 | import cloudpickle as cp
|
6 | 6 | from pathlib import Path
|
7 | 7 | import re
|
8 |
| - |
| 8 | +import json |
| 9 | +import glob as glob |
9 | 10 | from ... import mark
|
10 | 11 | from ..core import Workflow
|
11 | 12 | from ..task import AuditFlag, ShellCommandTask, DockerTask, SingularityTask
|
@@ -986,6 +987,60 @@ def testfunc(a: int, b: float = 0.1) -> ty.NamedTuple("Output", [("out", float)]
|
986 | 987 | assert (tmpdir / funky.checksum / "messages.jsonld").exists()
|
987 | 988 |
|
988 | 989 |
|
| 990 | +def test_audit_task(tmpdir): |
| 991 | + @mark.task |
| 992 | + def testfunc(a: int, b: float = 0.1) -> ty.NamedTuple("Output", [("out", float)]): |
| 993 | + return a + b |
| 994 | + |
| 995 | + from glob import glob |
| 996 | + |
| 997 | + funky = testfunc(a=2, audit_flags=AuditFlag.PROV, messengers=FileMessenger()) |
| 998 | + funky.cache_dir = tmpdir |
| 999 | + funky() |
| 1000 | + message_path = tmpdir / funky.checksum / "messages" |
| 1001 | + # go through each jsonld file in message_path and check if the label field exists |
| 1002 | + json_content = [] |
| 1003 | + for file in glob(str(message_path) + "/*.jsonld"): |
| 1004 | + with open(file, "r") as f: |
| 1005 | + data = json.load(f) |
| 1006 | + if "label" in data: |
| 1007 | + json_content.append(True) |
| 1008 | + assert "testfunc" == data["label"] |
| 1009 | + assert any(json_content) |
| 1010 | + |
| 1011 | + |
| 1012 | +def test_audit_shellcommandtask(tmpdir): |
| 1013 | + args = "-l" |
| 1014 | + shelly = ShellCommandTask( |
| 1015 | + name="shelly", |
| 1016 | + executable="ls", |
| 1017 | + args=args, |
| 1018 | + audit_flags=AuditFlag.PROV, |
| 1019 | + messengers=FileMessenger(), |
| 1020 | + ) |
| 1021 | + |
| 1022 | + from glob import glob |
| 1023 | + |
| 1024 | + shelly.cache_dir = tmpdir |
| 1025 | + shelly() |
| 1026 | + message_path = tmpdir / shelly.checksum / "messages" |
| 1027 | + # go through each jsonld file in message_path and check if the label field exists |
| 1028 | + label_content = [] |
| 1029 | + command_content = [] |
| 1030 | + |
| 1031 | + for file in glob(str(message_path) + "/*.jsonld"): |
| 1032 | + with open(file, "r") as f: |
| 1033 | + data = json.load(f) |
| 1034 | + if "label" in data: |
| 1035 | + label_content.append(True) |
| 1036 | + if "command" in data: |
| 1037 | + command_content.append(True) |
| 1038 | + assert "ls -l" == data["command"] |
| 1039 | + |
| 1040 | + print(command_content) |
| 1041 | + assert any(label_content) |
| 1042 | + |
| 1043 | + |
989 | 1044 | def test_audit_prov_messdir_1(tmpdir, use_validator):
|
990 | 1045 | """customized messenger dir"""
|
991 | 1046 |
|
@@ -1082,7 +1137,7 @@ def testfunc(a: int, b: float = 0.1) -> ty.NamedTuple("Output", [("out", float)]
|
1082 | 1137 | from glob import glob
|
1083 | 1138 |
|
1084 | 1139 | assert len(glob(str(tmpdir / funky.checksum / "proc*.log"))) == 1
|
1085 |
| - assert len(glob(str(message_path / "*.jsonld"))) == 6 |
| 1140 | + assert len(glob(str(message_path / "*.jsonld"))) == 7 |
1086 | 1141 |
|
1087 | 1142 | # commented out to speed up testing
|
1088 | 1143 | collect_messages(tmpdir / funky.checksum, message_path, ld_op="compact")
|
|
0 commit comments