|
11 | 11 | from ..core import Workflow
|
12 | 12 | from ..task import AuditFlag, ShellCommandTask, DockerTask, SingularityTask
|
13 | 13 | from ...utils.messenger import FileMessenger, PrintMessenger, collect_messages
|
14 |
| -from .utils import gen_basic_wf, use_validator |
15 |
| -from ..specs import MultiInputObj, MultiOutputObj, SpecInfo, FunctionSpec, BaseSpec |
| 14 | +from .utils import gen_basic_wf, use_validator, Submitter |
| 15 | +from ..specs import MultiInputObj, MultiOutputObj, SpecInfo, FunctionSpec, BaseSpec, ShellSpec, File |
| 16 | +from ..helpers import hash_file |
16 | 17 |
|
17 | 18 | no_win = pytest.mark.skipif(
|
18 | 19 | sys.platform.startswith("win"),
|
@@ -1021,6 +1022,7 @@ def testfunc(a: int, b: float = 0.1) -> ty.NamedTuple("Output", [("out", float)]
|
1021 | 1022 | if "AssociatedWith" in data:
|
1022 | 1023 | assert None == data["AssociatedWith"]
|
1023 | 1024 |
|
| 1025 | + |
1024 | 1026 | # assert any(json_content)
|
1025 | 1027 |
|
1026 | 1028 |
|
@@ -1062,6 +1064,50 @@ def test_audit_shellcommandtask(tmpdir):
|
1062 | 1064 | assert any(command_content)
|
1063 | 1065 |
|
1064 | 1066 |
|
| 1067 | +def test_audit_shellcommandtask_file(tmpdir): |
| 1068 | + # create test.txt file with "This is a test" in it in the tmpdir |
| 1069 | + with open(tmpdir / "test.txt", "w") as f: |
| 1070 | + f.write("This is a test.") |
| 1071 | + |
| 1072 | + cmd = "cat" |
| 1073 | + file_in = tmpdir / "test.txt" |
| 1074 | + test_file_hash = hash_file(file_in) |
| 1075 | + my_input_spec = SpecInfo( |
| 1076 | + name='Input', |
| 1077 | + fields=[ |
| 1078 | + ( |
| 1079 | + 'in_file', |
| 1080 | + attr.ib( |
| 1081 | + type=File, |
| 1082 | + metadata={ |
| 1083 | + 'position': 1, |
| 1084 | + 'argstr': '', |
| 1085 | + 'help_string': 'text', |
| 1086 | + 'mandatory': True, |
| 1087 | + }, |
| 1088 | + ), |
| 1089 | + ) |
| 1090 | + ], |
| 1091 | + bases=(ShellSpec,), |
| 1092 | +) |
| 1093 | + shelly = ShellCommandTask( |
| 1094 | + name='shelly', in_file=file_in, input_spec=my_input_spec, executable=cmd, audit_flags=AuditFlag.PROV, messengers=PrintMessenger() |
| 1095 | +) |
| 1096 | + shelly.cache_dir = tmpdir |
| 1097 | + shelly() |
| 1098 | + message_path = tmpdir / shelly.checksum / "messages" |
| 1099 | + for file in glob.glob(str(message_path) + "/*.jsonld"): |
| 1100 | + with open(file, "r") as f: |
| 1101 | + data = json.load(f) |
| 1102 | + print(file_in) |
| 1103 | + if "AtLocation" in data: |
| 1104 | + assert data["AtLocation"] == str(file_in) |
| 1105 | + if "digest" in data: |
| 1106 | + assert test_file_hash == data["digest"] |
| 1107 | + |
| 1108 | + |
| 1109 | + |
| 1110 | + |
1065 | 1111 | def test_audit_shellcommandtask_version(tmpdir):
|
1066 | 1112 | import subprocess as sp
|
1067 | 1113 |
|
|
0 commit comments