|
22 | 22 |
|
23 | 23 | from .content_tests import ContentTestCollector |
24 | 24 | from .schema import FileTest |
25 | | -from .util import file_md5sum |
| 25 | +from .util import extract_md5sum, file_md5sum |
26 | 26 | from .workflow import Workflow |
27 | 27 |
|
28 | 28 |
|
@@ -76,7 +76,16 @@ def collect(self): |
76 | 76 | parent=self, |
77 | 77 | filepath=filepath, |
78 | 78 | md5sum=self.filetest.md5sum, |
79 | | - workflow=self.workflow)] |
| 79 | + workflow=self.workflow, |
| 80 | + extract=False)] |
| 81 | + |
| 82 | + if self.filetest.extract_md5sum: |
| 83 | + tests += [FileMd5.from_parent( |
| 84 | + parent=self, |
| 85 | + filepath=filepath, |
| 86 | + md5sum=self.filetest.extract_md5sum, |
| 87 | + workflow=self.workflow, |
| 88 | + extract=True)] |
80 | 89 |
|
81 | 90 | return tests |
82 | 91 |
|
@@ -119,32 +128,37 @@ def repr_failure(self, excinfo, style=None): |
119 | 128 |
|
120 | 129 | class FileMd5(pytest.Item): |
121 | 130 | def __init__(self, parent: pytest.Collector, filepath: Path, |
122 | | - md5sum: str, workflow: Workflow): |
| 131 | + md5sum: str, workflow: Workflow, extract: bool): |
123 | 132 | """ |
124 | 133 | Create a tests for the file md5sum. |
125 | 134 | :param parent: The collector that started this item |
126 | 135 | :param filepath: The path to the file |
127 | 136 | :param md5sum: The expected md5sum |
128 | 137 | :param workflow: The workflow running to generate the file |
| 138 | + :param extract: Whether the file should be extracted before calculating |
129 | 139 | """ |
130 | | - name = "md5sum" |
| 140 | + name = "extract_md5sum" if extract else "md5sum" |
131 | 141 | super().__init__(name, parent) |
132 | 142 | self.filepath = filepath |
133 | 143 | self.expected_md5sum = md5sum |
134 | 144 | self.observed_md5sum = None |
135 | 145 | self.workflow = workflow |
| 146 | + self.extract = extract |
136 | 147 |
|
137 | 148 | def runtest(self): |
138 | 149 | # Wait for the workflow to finish before we check the md5sum of a file. |
139 | 150 | self.workflow.wait() |
140 | 151 | if not self.workflow.matching_exitcode(): |
141 | 152 | pytest.skip(f"'{self.parent.workflow.name}' did not exit with" |
142 | 153 | f"desired exit code.") |
143 | | - self.observed_md5sum = file_md5sum(self.filepath) |
| 154 | + sum_func = extract_md5sum if self.extract else file_md5sum |
| 155 | + self.observed_md5sum = sum_func(self.filepath) |
144 | 156 | assert self.observed_md5sum == self.expected_md5sum |
145 | 157 |
|
146 | 158 | def repr_failure(self, excinfo, style=None): |
| 159 | + metric = "extract_md5sum" if self.extract else "md5sum" |
147 | 160 | return ( |
148 | | - f"Observed md5sum '{self.observed_md5sum}' not equal to expected " |
149 | | - f"md5sum '{self.expected_md5sum}' for file '{self.filepath}'" |
150 | | - ) |
| 161 | + f"Observed {metric} '{self.observed_md5sum}' not equal to " |
| 162 | + f"expected {metric} '{self.expected_md5sum}' for file " |
| 163 | + f"'{self.filepath}'" |
| 164 | + ) |
0 commit comments