@@ -1007,9 +1007,6 @@ def testfunc(a: int, b: float = 0.1) -> ty.NamedTuple("Output", [("out", float)]
1007
1007
funky .cache_dir = tmpdir
1008
1008
funky ()
1009
1009
message_path = tmpdir / funky .checksum / "messages"
1010
- print (message_path )
1011
- # go through each jsonld file in message_path and check if the label field exists
1012
- json_content = []
1013
1010
1014
1011
for file in glob (str (message_path ) + "/*.jsonld" ):
1015
1012
with open (file , "r" ) as f :
@@ -1021,12 +1018,6 @@ def testfunc(a: int, b: float = 0.1) -> ty.NamedTuple("Output", [("out", float)]
1021
1018
if "@type" in data :
1022
1019
if data ["@type" ] == "input" :
1023
1020
assert None == data ["Label" ]
1024
- # placeholder for atlocation until
1025
- # new test is added
1026
- assert None == data ["AtLocation" ]
1027
-
1028
- # assert data["Type"] == "input"
1029
-
1030
1021
if "AssociatedWith" in data :
1031
1022
assert None == data ["AssociatedWith" ]
1032
1023
@@ -1072,13 +1063,27 @@ def test_audit_shellcommandtask(tmpdir):
1072
1063
1073
1064
1074
1065
def test_audit_shellcommandtask_file (tmpdir ):
1066
+ # sourcery skip: use-fstring-for-concatenation
1067
+ import glob
1068
+ import shutil
1069
+
1075
1070
# create test.txt file with "This is a test" in it in the tmpdir
1076
- with open (tmpdir / "test.txt" , "w" ) as f :
1077
- f .write ("This is a test." )
1071
+ # create txt file in cwd
1072
+ with open ("test.txt" , "w" ) as f :
1073
+ f .write ("This is a test" )
1074
+
1075
+ with open ("test2.txt" , "w" ) as f :
1076
+ f .write ("This is a test" )
1077
+
1078
+ # copy the test.txt file to the tmpdir
1079
+ shutil .copy ("test.txt" , tmpdir )
1080
+ shutil .copy ("test2.txt" , tmpdir )
1078
1081
1079
1082
cmd = "cat"
1080
1083
file_in = tmpdir / "test.txt"
1084
+ file_in_2 = tmpdir / "test2.txt"
1081
1085
test_file_hash = hash_file (file_in )
1086
+ test_file_hash_2 = hash_file (file_in_2 )
1082
1087
my_input_spec = SpecInfo (
1083
1088
name = "Input" ,
1084
1089
fields = [
@@ -1093,29 +1098,45 @@ def test_audit_shellcommandtask_file(tmpdir):
1093
1098
"mandatory" : True ,
1094
1099
},
1095
1100
),
1096
- )
1101
+ ),
1102
+ (
1103
+ "in_file_2" ,
1104
+ attr .ib (
1105
+ type = File ,
1106
+ metadata = {
1107
+ "position" : 2 ,
1108
+ "argstr" : "" ,
1109
+ "help_string" : "text" ,
1110
+ "mandatory" : True ,
1111
+ },
1112
+ ),
1113
+ ),
1097
1114
],
1098
1115
bases = (ShellSpec ,),
1099
1116
)
1100
1117
shelly = ShellCommandTask (
1101
1118
name = "shelly" ,
1102
1119
in_file = file_in ,
1120
+ in_file_2 = file_in_2 ,
1103
1121
input_spec = my_input_spec ,
1104
1122
executable = cmd ,
1105
1123
audit_flags = AuditFlag .PROV ,
1106
- messengers = PrintMessenger (),
1124
+ messengers = FileMessenger (),
1107
1125
)
1108
1126
shelly .cache_dir = tmpdir
1109
1127
shelly ()
1110
1128
message_path = tmpdir / shelly .checksum / "messages"
1111
1129
for file in glob .glob (str (message_path ) + "/*.jsonld" ):
1112
- with open (file , "r" ) as f :
1113
- data = json .load (f )
1114
- print (file_in )
1115
- if "AtLocation" in data :
1116
- assert data ["AtLocation" ] == str (file_in )
1117
- if "digest" in data :
1118
- assert test_file_hash == data ["digest" ]
1130
+ with open (file , "r" ) as x :
1131
+ data = json .load (x )
1132
+ if "@type" in data :
1133
+ if data ["@type" ] == "input" :
1134
+ if data ["Label" ] == "in_file" :
1135
+ assert data ["AtLocation" ] == str (file_in )
1136
+ assert data ["digest" ] == test_file_hash
1137
+ if data ["Label" ] == "in_file_2" :
1138
+ assert data ["AtLocation" ] == str (file_in_2 )
1139
+ assert data ["digest" ] == test_file_hash_2
1119
1140
1120
1141
1121
1142
def test_audit_shellcommandtask_version (tmpdir ):
@@ -1247,7 +1268,7 @@ def testfunc(a: int, b: float = 0.1) -> ty.NamedTuple("Output", [("out", float)]
1247
1268
from glob import glob
1248
1269
1249
1270
assert len (glob (str (tmpdir / funky .checksum / "proc*.log" ))) == 1
1250
- assert len (glob (str (message_path / "*.jsonld" ))) == 8
1271
+ assert len (glob (str (message_path / "*.jsonld" ))) == 7
1251
1272
1252
1273
# commented out to speed up testing
1253
1274
collect_messages (tmpdir / funky .checksum , message_path , ld_op = "compact" )
0 commit comments