|
1 | 1 | import json
|
2 | 2 | from pathlib import Path
|
3 | 3 |
|
| 4 | +import pytest |
4 | 5 | from git.repo import Repo
|
5 | 6 |
|
6 | 7 | import nf_core.modules.lint
|
@@ -194,22 +195,94 @@ def test_modules_empty_file_in_stub_snapshot(self):
|
194 | 195 | assert len(module_lint.failed) == 0, f"Linting failed with {[x.__dict__ for x in module_lint.failed]}"
|
195 | 196 | assert len(module_lint.passed) > 0
|
196 | 197 | assert len(module_lint.warned) >= 0
|
197 |
| - |
| 198 | + |
198 | 199 | # Check for test_snap_md5sum in passed tests (handle both tuple and LintResult formats)
|
199 | 200 | found_test = False
|
200 | 201 | for x in module_lint.passed:
|
201 | 202 | test_name = None
|
202 |
| - if hasattr(x, 'lint_test'): |
| 203 | + if hasattr(x, "lint_test"): |
203 | 204 | test_name = x.lint_test
|
204 | 205 | elif isinstance(x, tuple) and len(x) > 0:
|
205 | 206 | test_name = x[0]
|
206 |
| - |
| 207 | + |
207 | 208 | if test_name == "test_snap_md5sum":
|
208 | 209 | found_test = True
|
209 | 210 | break
|
210 |
| - |
| 211 | + |
211 | 212 | assert found_test, "test_snap_md5sum not found in passed tests"
|
212 | 213 |
|
213 | 214 | # reset the file
|
214 | 215 | with open(snap_file, "w") as fh:
|
215 | 216 | fh.write(content)
|
| 217 | + |
| 218 | + @pytest.mark.issue("https://github.com/nf-core/modules/issues/6505") |
| 219 | + def test_modules_version_snapshot_content_md5_hash(self): |
| 220 | + """Test linting a nf-test module with version information as MD5 hash instead of actual content, which should fail. |
| 221 | +
|
| 222 | + Related to: https://github.com/nf-core/modules/issues/6505 |
| 223 | + Fixed in: https://github.com/nf-core/modules/pull/7098 |
| 224 | + """ |
| 225 | + snap_file = self.bpipe_test_module_path / "tests" / "main.nf.test.snap" |
| 226 | + snap = json.load(snap_file.open()) |
| 227 | + content = snap_file.read_text() |
| 228 | + |
| 229 | + # Add a version entry with MD5 hash format (the old way that should be flagged) |
| 230 | + snap["my test"]["content"][0]["versions"] = "versions.yml:md5,949da9c6297b613b50e24c421576f3f1" |
| 231 | + |
| 232 | + with open(snap_file, "w") as fh: |
| 233 | + json.dump(snap, fh) |
| 234 | + |
| 235 | + module_lint = nf_core.modules.lint.ModuleLint(directory=self.nfcore_modules) |
| 236 | + module_lint.lint(print_results=False, module="bpipe/test") |
| 237 | + |
| 238 | + # Should fail because version is using MD5 hash instead of actual content |
| 239 | + # Filter for only our specific test |
| 240 | + version_content_failures = [x for x in module_lint.failed if x.lint_test == "test_snap_version_content"] |
| 241 | + assert len(version_content_failures) == 1, ( |
| 242 | + f"Expected 1 test_snap_version_content failure, got {len(version_content_failures)}" |
| 243 | + ) |
| 244 | + assert version_content_failures[0].lint_test == "test_snap_version_content" |
| 245 | + |
| 246 | + # reset the file |
| 247 | + with open(snap_file, "w") as fh: |
| 248 | + fh.write(content) |
| 249 | + |
| 250 | + @pytest.mark.issue("https://github.com/nf-core/modules/issues/6505") |
| 251 | + def test_modules_version_snapshot_content_valid(self): |
| 252 | + """Test linting a nf-test module with version information as actual content, which should pass. |
| 253 | +
|
| 254 | + Related to: https://github.com/nf-core/modules/issues/6505 |
| 255 | + Fixed in: https://github.com/nf-core/modules/pull/7098 |
| 256 | + """ |
| 257 | + snap_file = self.bpipe_test_module_path / "tests" / "main.nf.test.snap" |
| 258 | + snap = json.load(snap_file.open()) |
| 259 | + content = snap_file.read_text() |
| 260 | + |
| 261 | + # Add a version entry with actual content (the new way that should pass) |
| 262 | + snap["my test"]["content"][0]["versions"] = {"ALE": {"ale": "20180904"}} |
| 263 | + |
| 264 | + with open(snap_file, "w") as fh: |
| 265 | + json.dump(snap, fh) |
| 266 | + |
| 267 | + module_lint = nf_core.modules.lint.ModuleLint(directory=self.nfcore_modules) |
| 268 | + module_lint.lint(print_results=False, module="bpipe/test") |
| 269 | + |
| 270 | + # Should pass because version contains actual content |
| 271 | + # Filter for only our specific test |
| 272 | + version_content_failures = [x for x in module_lint.failed if x.lint_test == "test_snap_version_content"] |
| 273 | + assert len(version_content_failures) == 0, ( |
| 274 | + f"Expected 0 test_snap_version_content failures, got {len(version_content_failures)}" |
| 275 | + ) |
| 276 | + |
| 277 | + # Check for test_snap_version_content in passed tests |
| 278 | + version_content_passed = [ |
| 279 | + x |
| 280 | + for x in module_lint.passed |
| 281 | + if (hasattr(x, "lint_test") and x.lint_test == "test_snap_version_content") |
| 282 | + or (isinstance(x, tuple) and len(x) > 0 and x[0] == "test_snap_version_content") |
| 283 | + ] |
| 284 | + assert len(version_content_passed) > 0, "test_snap_version_content not found in passed tests" |
| 285 | + |
| 286 | + # reset the file |
| 287 | + with open(snap_file, "w") as fh: |
| 288 | + fh.write(content) |
0 commit comments