@@ -171,7 +171,7 @@ def test_modules_empty_file_in_snapshot(self):
171171 """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)"""
172172 snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
173173 snap = json .load (snap_file .open ())
174- content = snap_file .read_text ()
174+ snap_file .read_text ()
175175 snap ["my test" ]["content" ][0 ]["0" ] = "test:md5,d41d8cd98f00b204e9800998ecf8427e"
176176
177177 with open (snap_file , "w" ) as fh :
@@ -184,15 +184,11 @@ def test_modules_empty_file_in_snapshot(self):
184184 assert len (module_lint .warned ) >= 0
185185 assert module_lint .failed [0 ].lint_test == "test_snap_md5sum"
186186
187- # reset the file
188- with open (snap_file , "w" ) as fh :
189- fh .write (content )
190-
191187 def test_modules_empty_file_in_stub_snapshot (self ):
192188 """Test linting a nf-test module with an empty file sha sum in the stub test snapshot, which should make it not fail"""
193189 snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
194190 snap = json .load (snap_file .open ())
195- content = snap_file .read_text ()
191+ snap_file .read_text ()
196192 snap ["my_test_stub" ] = {"content" : [{"0" : "test:md5,d41d8cd98f00b204e9800998ecf8427e" , "versions" : {}}]}
197193
198194 with open (snap_file , "w" ) as fh :
@@ -219,20 +215,12 @@ def test_modules_empty_file_in_stub_snapshot(self):
219215
220216 assert found_test , "test_snap_md5sum not found in passed tests"
221217
222- # reset the file
223- with open (snap_file , "w" ) as fh :
224- fh .write (content )
225-
226218 @pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
227219 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."""
233221 snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
234222 snap = json .load (snap_file .open ())
235- content = snap_file .read_text ()
223+ snap_file .read_text ()
236224
237225 # Add a version entry with MD5 hash format (the old way that should be flagged)
238226 snap ["my test" ]["content" ][0 ]["versions" ] = "versions.yml:md5,949da9c6297b613b50e24c421576f3f1"
@@ -249,22 +237,13 @@ def test_modules_version_snapshot_content_md5_hash(self):
249237 assert len (version_content_failures ) == 1 , (
250238 f"Expected 1 test_snap_version_content failure, got { len (version_content_failures )} "
251239 )
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 )
257240
258241 @pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
259242 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."""
265244 snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
266245 snap = json .load (snap_file .open ())
267- content = snap_file .read_text ()
246+ snap_file .read_text ()
268247
269248 # Add a version entry with actual content (the new way that should pass)
270249 snap ["my test" ]["content" ][0 ]["versions" ] = {"ALE" : {"ale" : "20180904" }}
@@ -291,20 +270,12 @@ def test_modules_version_snapshot_content_valid(self):
291270 ]
292271 assert len (version_content_passed ) > 0 , "test_snap_version_content not found in passed tests"
293272
294- # reset the file
295- with open (snap_file , "w" ) as fh :
296- fh .write (content )
297-
298273 @pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
299274 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."""
305276 snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
306277 snap = json .load (snap_file .open ())
307- content = snap_file .read_text ()
278+ snap_file .read_text ()
308279
309280 # Add a version entry with SHA hash format (should be flagged)
310281 snap ["my test" ]["content" ][0 ]["versions" ] = (
@@ -323,73 +294,50 @@ def test_modules_version_snapshot_content_sha_hash(self):
323294 f"Expected 1 test_snap_version_content failure, got { len (version_content_failures )} "
324295 )
325296
326- # reset the file
327- with open (snap_file , "w" ) as fh :
328- fh .write (content )
329-
330297 @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."""
337300 snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
338301 snap = json .load (snap_file .open ())
339- content = snap_file .read_text ()
302+ snap_file .read_text ()
340303
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 )
344307
345308 with open (snap_file , "w" ) as fh :
346309 json .dump (snap , fh )
347310
348311 module_lint = nf_core .modules .lint .ModuleLint (directory = self .nfcore_modules )
349312 module_lint .lint (print_results = False , module = "bpipe/test" )
350313
351- # Should have failure for the hash test
314+ # Should not have version content check failures when no version data present
352315 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"
363317
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"
367321
368322 @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."""
375325 snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
376326 snap = json .load (snap_file .open ())
377- content = snap_file .read_text ()
327+ snap_file .read_text ()
378328
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+ }
382334
383335 with open (snap_file , "w" ) as fh :
384336 json .dump (snap , fh )
385337
386338 module_lint = nf_core .modules .lint .ModuleLint (directory = self .nfcore_modules )
387339 module_lint .lint (print_results = False , module = "bpipe/test" )
388340
389- # Should not have version content check failures when no version data present
341+ # Should fail because version hash is in the keys
390342 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