Skip to content

Commit 45bbcba

Browse files
authored
Merge pull request #47 from Sage-Bionetworks-Workflows/bwmac/orca-268/tiff_date_test
[ORCA-268] Adds TiffDateTimeTest
2 parents 2effca6 + 4b3567e commit 45bbcba

File tree

6 files changed

+70
-5
lines changed

6 files changed

+70
-5
lines changed

src/dcqc/suites/suites.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TiffSuite(FileSuite):
2424
file_type = FileType.get_file_type("TIFF")
2525
add_tests = (
2626
tests.LibTiffInfoTest,
27-
tests.GrepDateTest,
27+
tests.TiffDateTimeTest,
2828
tests.TiffTag306DateTimeTest,
2929
)
3030

src/dcqc/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
from dcqc.tests.md5_checksum_test import Md5ChecksumTest
99
from dcqc.tests.ome_xml_schema_test import OmeXmlSchemaTest
1010
from dcqc.tests.paired_fastq_parity_test import PairedFastqParityTest
11+
from dcqc.tests.tiff_date_time_test import TiffDateTimeTest
1112
from dcqc.tests.tiff_tag_306_date_time_test import TiffTag306DateTimeTest
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from dcqc.target import SingleTarget
2+
from dcqc.tests.base_test import ExternalBaseTest, Process
3+
4+
5+
class TiffDateTimeTest(ExternalBaseTest):
6+
tier = 4
7+
pass_code = "1"
8+
target: SingleTarget
9+
10+
def generate_process(self) -> Process:
11+
path = self.target.file.stage()
12+
13+
command_args = [
14+
"tifftools",
15+
"dump",
16+
f"'{path.name}'",
17+
"--json",
18+
"--silent",
19+
"|",
20+
"jq",
21+
"-e",
22+
"'.[].ifds[].tags[]'.data",
23+
"|",
24+
"grep",
25+
"-Ei",
26+
"'date|time'",
27+
]
28+
process = Process(
29+
container="ghcr.io/sage-bionetworks-workflows/tifftools:latest",
30+
command_args=command_args,
31+
)
32+
return process

tests/data/date_tag.tif

74.9 KB
Binary file not shown.

tests/test_suites.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from dcqc.tests import (
99
BaseTest,
1010
FileExtensionTest,
11-
GrepDateTest,
1211
LibTiffInfoTest,
1312
TestStatus,
13+
TiffDateTimeTest,
1414
TiffTag306DateTimeTest,
1515
)
1616

@@ -20,7 +20,7 @@
2020

2121
class RedundantFileSuite(TiffSuite):
2222
file_type = FileType.get_file_type("None")
23-
del_tests = (LibTiffInfoTest, GrepDateTest, TiffTag306DateTimeTest)
23+
del_tests = (LibTiffInfoTest, TiffDateTimeTest, TiffTag306DateTimeTest)
2424

2525

2626
class DummyTest(BaseTest):
@@ -105,7 +105,7 @@ def test_for_an_error_when_building_suite_from_tests_with_diff_targets(test_targ
105105
def test_that_a_suite_will_consider_non_required_failed_tests(test_targets):
106106
target = test_targets["bad"]
107107
required_tests = []
108-
skipped_tests = ["LibTiffInfoTest", "GrepDateTest", "TiffTag306DateTimeTest"]
108+
skipped_tests = ["LibTiffInfoTest", "TiffDateTimeTest", "TiffTag306DateTimeTest"]
109109
suite = SuiteABC.from_target(target, required_tests, skipped_tests)
110110
suite_status = suite.compute_status()
111111
assert suite_status == SuiteStatus.AMBER
@@ -114,7 +114,7 @@ def test_that_a_suite_will_consider_non_required_failed_tests(test_targets):
114114
def test_that_a_suite_will_consider_required_tests_when_failing(test_targets):
115115
target = test_targets["bad"]
116116
required_tests = ["FileExtensionTest"]
117-
skipped_tests = ["LibTiffInfoTest", "GrepDateTest", "TiffTag306DateTimeTest"]
117+
skipped_tests = ["LibTiffInfoTest", "TiffDateTimeTest", "TiffTag306DateTimeTest"]
118118
suite = SuiteABC.from_target(target, required_tests, skipped_tests)
119119
suite_status = suite.compute_status()
120120
assert suite_status == SuiteStatus.RED

tests/test_tests.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,38 @@ def test_that_the_tifftag306datetimetest_correctly_interprets_exit_code_0_and_1(
295295
assert test_status == TestStatus.FAIL
296296

297297

298+
def test_that_the_tiffdatetimetest_command_is_produced(test_targets):
299+
target = test_targets["tiff"]
300+
test = tests.TiffDateTimeTest(target)
301+
process = test.generate_process()
302+
assert "grep" in process.command
303+
304+
305+
def test_that_the_tiffdatetimetest_correctly_interprets_exit_code_0_and_1(
306+
test_files, mocker
307+
):
308+
# 1 is pass, 0 is fail
309+
tiff_file = test_files["tiff"]
310+
target = SingleTarget(tiff_file)
311+
with TemporaryDirectory() as tmp_dir:
312+
path_0 = Path(tmp_dir, "code_0.txt")
313+
path_1 = Path(tmp_dir, "code_1.txt")
314+
path_0.write_text("0")
315+
path_1.write_text("1")
316+
fail_outputs = {"std_out": path_1, "std_err": path_1, "exit_code": path_0}
317+
pass_outputs = {"std_out": path_0, "std_err": path_0, "exit_code": path_1}
318+
319+
test = tests.TiffDateTimeTest(target)
320+
mocker.patch.object(test, "_find_process_outputs", return_value=pass_outputs)
321+
test_status = test.get_status()
322+
assert test_status == TestStatus.PASS
323+
324+
test = tests.TiffDateTimeTest(target)
325+
mocker.patch.object(test, "_find_process_outputs", return_value=fail_outputs)
326+
test_status = test.get_status()
327+
assert test_status == TestStatus.FAIL
328+
329+
298330
def test_that_paired_fastq_parity_test_correctly_passes_identical_fastq_files(
299331
test_files,
300332
):

0 commit comments

Comments
 (0)