Skip to content

Commit 3b6f370

Browse files
authored
Merge pull request #26 from Sage-Bionetworks-Workflows/ataylor/ORCA-136/grep-date-test
[ORCA-136] Add rudimental PHI detection by doing a grep
2 parents e6b51c7 + 0acc55a commit 3b6f370

File tree

5 files changed

+62
-6
lines changed

5 files changed

+62
-6
lines changed

src/dcqc/suites/suites.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class JsonLdSuite(JsonSuite):
2222

2323
class TiffSuite(FileSuite):
2424
file_type = FileType.get_file_type("TIFF")
25-
add_tests = (tests.LibTiffInfoTest,)
25+
add_tests = (tests.LibTiffInfoTest, tests.GrepDateTest)
2626

2727

2828
class OmeTiffSuite(TiffSuite):

src/dcqc/tests/tests.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,24 @@ def generate_process(self) -> Process:
136136
command_args=command_args,
137137
)
138138
return process
139+
140+
141+
class GrepDateTest(ExternalTestMixin, TestABC):
142+
tier = 4
143+
144+
def generate_process(self) -> Process:
145+
file = self.get_file()
146+
path = file.local_path.as_posix()
147+
command_args = [
148+
"grep",
149+
"-E",
150+
"-w",
151+
"-i",
152+
"'date|time'",
153+
path,
154+
]
155+
process = Process(
156+
container="quay.io/biocontainers/coreutils:8.30--h14c3975_1000",
157+
command_args=command_args,
158+
)
159+
return process
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file contains the word date and therefore should fail the GrepDateTest test.

tests/test_suites.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
from dcqc.suites.suite_abc import SuiteABC
55
from dcqc.suites.suites import FileSuite, OmeTiffSuite, TiffSuite
66
from dcqc.tests.test_abc import TestABC, TestStatus
7-
from dcqc.tests.tests import FileExtensionTest, LibTiffInfoTest
7+
from dcqc.tests.tests import FileExtensionTest, GrepDateTest, LibTiffInfoTest
88

99
FileType("None", ())
1010
FileType("Unpaired", ())
1111

1212

1313
class RedundantFileSuite(TiffSuite):
1414
file_type = FileType.get_file_type("None")
15-
del_tests = (LibTiffInfoTest,)
15+
del_tests = (
16+
LibTiffInfoTest,
17+
GrepDateTest,
18+
)
1619

1720

1821
class DummyTest(TestABC):
@@ -70,7 +73,7 @@ def test_that_the_generic_file_suite_is_retrieved_for_an_unpaired_file_type():
7073

7174

7275
def test_that_the_default_required_tests_are_only_tiers_1_and_2(test_suites):
73-
suite = test_suites["tiff"]
76+
suite = test_suites["jsonld"]
7477
assert all(test.tier <= 2 for test in suite.tests)
7578

7679

@@ -97,7 +100,7 @@ def test_for_an_error_when_building_suite_from_tests_with_diff_targets(test_targ
97100
def test_that_a_suite_will_not_consider_unrequired_tests(test_targets):
98101
target = test_targets["bad"]
99102
required_tests = []
100-
skipped_tests = ["LibTiffInfoTest"]
103+
skipped_tests = ["LibTiffInfoTest", "GrepDateTest"]
101104
suite = SuiteABC.from_target(target, required_tests, skipped_tests)
102105
suite_status = suite.compute_status()
103106
assert suite_status == TestStatus.PASS
@@ -106,7 +109,7 @@ def test_that_a_suite_will_not_consider_unrequired_tests(test_targets):
106109
def test_that_a_suite_will_consider_required_tests_when_failing(test_targets):
107110
target = test_targets["bad"]
108111
required_tests = ["FileExtensionTest"]
109-
skipped_tests = ["LibTiffInfoTest"]
112+
skipped_tests = ["LibTiffInfoTest", "GrepDateTest"]
110113
suite = SuiteABC.from_target(target, required_tests, skipped_tests)
111114
suite_status = suite.compute_status()
112115
assert suite_status == TestStatus.FAIL

tests/test_tests.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,37 @@ def test_that_a_process_can_be_serialized_and_deserialized():
192192
assert process_dict == process_from_dict.to_dict()
193193

194194

195+
def test_that_the_grep_date_test_correctly_interprets_exit_code_0_and_1(
196+
test_files, mocker
197+
):
198+
tiff_file = test_files["tiff"]
199+
target = Target(tiff_file)
200+
with TemporaryDirectory() as tmp_dir:
201+
path_0 = Path(tmp_dir, "code_0.txt")
202+
path_1 = Path(tmp_dir, "code_1.txt")
203+
path_0.write_text("0")
204+
path_1.write_text("1")
205+
good_outputs = {"std_out": path_1, "std_err": path_1, "exit_code": path_0}
206+
bad_outputs = {"std_out": path_0, "std_err": path_0, "exit_code": path_1}
207+
208+
test = tests.GrepDateTest(target)
209+
mocker.patch.object(test, "_find_process_outputs", return_value=good_outputs)
210+
test_status = test.get_status()
211+
assert test_status == TestStatus.PASS
212+
213+
test = tests.LibTiffInfoTest(target)
214+
mocker.patch.object(test, "_find_process_outputs", return_value=bad_outputs)
215+
test_status = test.get_status()
216+
assert test_status == TestStatus.FAIL
217+
218+
219+
def test_that_the_grep_date_test_command_is_produced(test_targets):
220+
target = test_targets["tiff"]
221+
test = tests.GrepDateTest(target)
222+
process = test.generate_process()
223+
assert "grep" in process.command
224+
225+
195226
def test_for_an_error_when_getting_one_file_from_multi_file_target(test_files):
196227
file = test_files["good"]
197228
target = Target(file, file)

0 commit comments

Comments
 (0)