@@ -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"
@@ -249,22 +237,13 @@ def test_modules_version_snapshot_content_md5_hash(self):
249
237
assert len (version_content_failures ) == 1 , (
250
238
f"Expected 1 test_snap_version_content failure, got { len (version_content_failures )} "
251
239
)
252
- assert version_content_failures [0 ].lint_test == "test_snap_version_content"
253
-
254
- # reset the file
255
- with open (snap_file , "w" ) as fh :
256
- fh .write (content )
257
240
258
241
@pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
259
242
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
- """
243
+ """Test linting a nf-test module with version information as actual content, which should pass."""
265
244
snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
266
245
snap = json .load (snap_file .open ())
267
- content = snap_file .read_text ()
246
+ snap_file .read_text ()
268
247
269
248
# Add a version entry with actual content (the new way that should pass)
270
249
snap ["my test" ]["content" ][0 ]["versions" ] = {"ALE" : {"ale" : "20180904" }}
@@ -291,20 +270,12 @@ def test_modules_version_snapshot_content_valid(self):
291
270
]
292
271
assert len (version_content_passed ) > 0 , "test_snap_version_content not found in passed tests"
293
272
294
- # reset the file
295
- with open (snap_file , "w" ) as fh :
296
- fh .write (content )
297
-
298
273
@pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
299
274
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
- """
275
+ """Test linting a nf-test module with version information as SHA hash, which should fail."""
305
276
snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
306
277
snap = json .load (snap_file .open ())
307
- content = snap_file .read_text ()
278
+ snap_file .read_text ()
308
279
309
280
# Add a version entry with SHA hash format (should be flagged)
310
281
snap ["my test" ]["content" ][0 ]["versions" ] = (
@@ -323,73 +294,50 @@ def test_modules_version_snapshot_content_sha_hash(self):
323
294
f"Expected 1 test_snap_version_content failure, got { len (version_content_failures )} "
324
295
)
325
296
326
- # reset the file
327
- with open (snap_file , "w" ) as fh :
328
- fh .write (content )
329
-
330
297
@pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
331
- 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
- """
298
+ def test_modules_version_snapshot_no_version_content (self ):
299
+ """Test linting when no version information is present - should not trigger version content check."""
337
300
snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
338
301
snap = json .load (snap_file .open ())
339
- content = snap_file .read_text ()
302
+ snap_file .read_text ()
340
303
341
- # Create a scenario with multiple tests - one with hash, one with valid content
342
- snap [ "test_with_hash" ] = { "content" : [{ "versions" : "versions.yml:md5,949da9c6297b613b50e24c421576f3f1" }]}
343
- snap ["test_with_valid_content" ] = { "content" : [{ "versions" : { "BPIPE" : { "bpipe" : "0.9.11" }}}]}
304
+ # Remove version information entirely
305
+ if "content" in snap [ "my test" ] and snap [ "my test" ][ "content" ]:
306
+ snap ["my test" ][ "content" ][ 0 ]. pop ( "versions" , None )
344
307
345
308
with open (snap_file , "w" ) as fh :
346
309
json .dump (snap , fh )
347
310
348
311
module_lint = nf_core .modules .lint .ModuleLint (directory = self .nfcore_modules )
349
312
module_lint .lint (print_results = False , module = "bpipe/test" )
350
313
351
- # Should have failure for the hash test
314
+ # Should not have version content check failures when no version data present
352
315
version_content_failures = [x for x in module_lint .failed if x .lint_test == "test_snap_version_content" ]
353
- assert len (version_content_failures ) >= 1 , "Expected at least 1 failure for hash format"
354
-
355
- # Should have pass for the valid content test
356
- version_content_passed = [
357
- x
358
- for x in module_lint .passed
359
- if (hasattr (x , "lint_test" ) and x .lint_test == "test_snap_version_content" )
360
- or (isinstance (x , tuple ) and len (x ) > 0 and x [0 ] == "test_snap_version_content" )
361
- ]
362
- assert len (version_content_passed ) >= 1 , "Expected at least 1 pass for valid content"
316
+ assert len (version_content_failures ) == 0 , "Should not have version content failures when no versions present"
363
317
364
- # reset the file
365
- with open ( snap_file , "w" ) as fh :
366
- fh . write ( content )
318
+ # Should have test_snap_versions failure since no versions are present
319
+ version_failures = [ x for x in module_lint . failed if x . lint_test == "test_snap_versions" ]
320
+ assert len ( version_failures ) == 1 , "Expected test_snap_versions failure when no versions present"
367
321
368
322
@pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
369
- 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
- """
323
+ def test_modules_version_snapshot_hash_in_keys (self ):
324
+ """Test linting when version hash appears in snapshot keys rather than content."""
375
325
snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
376
326
snap = json .load (snap_file .open ())
377
- content = snap_file .read_text ()
327
+ snap_file .read_text ()
378
328
379
- # Remove version information entirely
380
- if "content" in snap ["my test" ] and snap ["my test" ]["content" ]:
381
- snap ["my test" ]["content" ][0 ].pop ("versions" , None )
329
+ # Create a test where version hash appears in the test keys
330
+ snap ["test_with_hash_key" ] = {
331
+ "content" : [{"versions.yml:md5,949da9c6297b613b50e24c421576f3f1" : "some_value" }],
332
+ "versions" : {"BPIPE" : {"bpipe" : "0.9.11" }},
333
+ }
382
334
383
335
with open (snap_file , "w" ) as fh :
384
336
json .dump (snap , fh )
385
337
386
338
module_lint = nf_core .modules .lint .ModuleLint (directory = self .nfcore_modules )
387
339
module_lint .lint (print_results = False , module = "bpipe/test" )
388
340
389
- # Should not have version content check failures when no version data present
341
+ # Should fail because version hash is in the keys
390
342
version_content_failures = [x for x in module_lint .failed if x .lint_test == "test_snap_version_content" ]
391
- assert len (version_content_failures ) == 0 , "Should not have version content failures when no versions present"
392
-
393
- # reset the file
394
- with open (snap_file , "w" ) as fh :
395
- fh .write (content )
343
+ assert len (version_content_failures ) >= 1 , "Expected failure for hash in keys"
0 commit comments