@@ -171,7 +171,7 @@ def test_modules_empty_file_in_snapshot(self):
171
171
"""Test linting a nf-test module with an empty file sha sum in the test snapshot, which should make it fail (if it is not a stub)"""
172
172
snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
173
173
snap = json .load (snap_file .open ())
174
- content = snap_file .read_text ()
174
+ snap_file .read_text ()
175
175
snap ["my test" ]["content" ][0 ]["0" ] = "test:md5,d41d8cd98f00b204e9800998ecf8427e"
176
176
177
177
with open (snap_file , "w" ) as fh :
@@ -184,15 +184,11 @@ def test_modules_empty_file_in_snapshot(self):
184
184
assert len (module_lint .warned ) >= 0
185
185
assert module_lint .failed [0 ].lint_test == "test_snap_md5sum"
186
186
187
- # reset the file
188
- with open (snap_file , "w" ) as fh :
189
- fh .write (content )
190
-
191
187
def test_modules_empty_file_in_stub_snapshot (self ):
192
188
"""Test linting a nf-test module with an empty file sha sum in the stub test snapshot, which should make it not fail"""
193
189
snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
194
190
snap = json .load (snap_file .open ())
195
- content = snap_file .read_text ()
191
+ snap_file .read_text ()
196
192
snap ["my_test_stub" ] = {"content" : [{"0" : "test:md5,d41d8cd98f00b204e9800998ecf8427e" , "versions" : {}}]}
197
193
198
194
with open (snap_file , "w" ) as fh :
@@ -219,20 +215,12 @@ def test_modules_empty_file_in_stub_snapshot(self):
219
215
220
216
assert found_test , "test_snap_md5sum not found in passed tests"
221
217
222
- # reset the file
223
- with open (snap_file , "w" ) as fh :
224
- fh .write (content )
225
-
226
218
@pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
227
219
def test_modules_version_snapshot_content_md5_hash (self ):
228
- """Test linting a nf-test module with version information as MD5 hash instead of actual content, which should fail.
229
-
230
- Related to: https://github.com/nf-core/modules/issues/6505
231
- Fixed in: https://github.com/nf-core/tools/pull/3676
232
- """
220
+ """Test linting a nf-test module with version information as MD5 hash instead of actual content, which should fail."""
233
221
snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
234
222
snap = json .load (snap_file .open ())
235
- content = snap_file .read_text ()
223
+ snap_file .read_text ()
236
224
237
225
# Add a version entry with MD5 hash format (the old way that should be flagged)
238
226
snap ["my test" ]["content" ][0 ]["versions" ] = "versions.yml:md5,949da9c6297b613b50e24c421576f3f1"
@@ -251,20 +239,12 @@ def test_modules_version_snapshot_content_md5_hash(self):
251
239
)
252
240
assert version_content_failures [0 ].lint_test == "test_snap_version_content"
253
241
254
- # reset the file
255
- with open (snap_file , "w" ) as fh :
256
- fh .write (content )
257
-
258
242
@pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
259
243
def test_modules_version_snapshot_content_valid (self ):
260
- """Test linting a nf-test module with version information as actual content, which should pass.
261
-
262
- Related to: https://github.com/nf-core/modules/issues/6505
263
- Fixed in: https://github.com/nf-core/tools/pull/3676
264
- """
244
+ """Test linting a nf-test module with version information as actual content, which should pass."""
265
245
snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
266
246
snap = json .load (snap_file .open ())
267
- content = snap_file .read_text ()
247
+ snap_file .read_text ()
268
248
269
249
# Add a version entry with actual content (the new way that should pass)
270
250
snap ["my test" ]["content" ][0 ]["versions" ] = {"ALE" : {"ale" : "20180904" }}
@@ -291,20 +271,12 @@ def test_modules_version_snapshot_content_valid(self):
291
271
]
292
272
assert len (version_content_passed ) > 0 , "test_snap_version_content not found in passed tests"
293
273
294
- # reset the file
295
- with open (snap_file , "w" ) as fh :
296
- fh .write (content )
297
-
298
274
@pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
299
275
def test_modules_version_snapshot_content_sha_hash (self ):
300
- """Test linting a nf-test module with version information as SHA hash, which should fail.
301
-
302
- Related to: https://github.com/nf-core/modules/issues/6505
303
- Fixed in: https://github.com/nf-core/tools/pull/3676
304
- """
276
+ """Test linting a nf-test module with version information as SHA hash, which should fail."""
305
277
snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
306
278
snap = json .load (snap_file .open ())
307
- content = snap_file .read_text ()
279
+ snap_file .read_text ()
308
280
309
281
# Add a version entry with SHA hash format (should be flagged)
310
282
snap ["my test" ]["content" ][0 ]["versions" ] = (
@@ -323,20 +295,12 @@ def test_modules_version_snapshot_content_sha_hash(self):
323
295
f"Expected 1 test_snap_version_content failure, got { len (version_content_failures )} "
324
296
)
325
297
326
- # reset the file
327
- with open (snap_file , "w" ) as fh :
328
- fh .write (content )
329
-
330
298
@pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
331
299
def test_modules_version_snapshot_content_mixed_scenario (self ):
332
- """Test linting with mixed version content - some valid, some hash format.
333
-
334
- Related to: https://github.com/nf-core/modules/issues/6505
335
- Fixed in: https://github.com/nf-core/tools/pull/3676
336
- """
300
+ """Test linting with mixed version content - some valid, some hash format."""
337
301
snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
338
302
snap = json .load (snap_file .open ())
339
- content = snap_file .read_text ()
303
+ snap_file .read_text ()
340
304
341
305
# Create a scenario with multiple tests - one with hash, one with valid content
342
306
snap ["test_with_hash" ] = {"content" : [{"versions" : "versions.yml:md5,949da9c6297b613b50e24c421576f3f1" }]}
@@ -361,20 +325,12 @@ def test_modules_version_snapshot_content_mixed_scenario(self):
361
325
]
362
326
assert len (version_content_passed ) >= 1 , "Expected at least 1 pass for valid content"
363
327
364
- # reset the file
365
- with open (snap_file , "w" ) as fh :
366
- fh .write (content )
367
-
368
328
@pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
369
329
def test_modules_version_snapshot_no_version_content (self ):
370
- """Test linting when no version information is present - should not trigger version content check.
371
-
372
- Related to: https://github.com/nf-core/modules/issues/6505
373
- Fixed in: https://github.com/nf-core/tools/pull/3676
374
- """
330
+ """Test linting when no version information is present - should not trigger version content check."""
375
331
snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
376
332
snap = json .load (snap_file .open ())
377
- content = snap_file .read_text ()
333
+ snap_file .read_text ()
378
334
379
335
# Remove version information entirely
380
336
if "content" in snap ["my test" ] and snap ["my test" ]["content" ]:
@@ -390,6 +346,25 @@ def test_modules_version_snapshot_no_version_content(self):
390
346
version_content_failures = [x for x in module_lint .failed if x .lint_test == "test_snap_version_content" ]
391
347
assert len (version_content_failures ) == 0 , "Should not have version content failures when no versions present"
392
348
393
- # reset the file
349
+ @pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
350
+ def test_modules_version_snapshot_hash_in_keys (self ):
351
+ """Test linting when version hash appears in snapshot keys rather than content."""
352
+ snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
353
+ snap = json .load (snap_file .open ())
354
+ snap_file .read_text ()
355
+
356
+ # Create a test where version hash appears in the test keys
357
+ snap ["test_with_hash_key" ] = {
358
+ "content" : [{"versions.yml:md5,949da9c6297b613b50e24c421576f3f1" : "some_value" }],
359
+ "versions" : {"BPIPE" : {"bpipe" : "0.9.11" }},
360
+ }
361
+
394
362
with open (snap_file , "w" ) as fh :
395
- fh .write (content )
363
+ json .dump (snap , fh )
364
+
365
+ module_lint = nf_core .modules .lint .ModuleLint (directory = self .nfcore_modules )
366
+ module_lint .lint (print_results = False , module = "bpipe/test" )
367
+
368
+ # Should fail because version hash is in the keys
369
+ version_content_failures = [x for x in module_lint .failed if x .lint_test == "test_snap_version_content" ]
370
+ assert len (version_content_failures ) >= 1 , "Expected failure for hash in keys"
0 commit comments