@@ -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"
@@ -251,20 +239,12 @@ def test_modules_version_snapshot_content_md5_hash(self):
251239 )
252240 assert version_content_failures [0 ].lint_test == "test_snap_version_content"
253241
254- # reset the file
255- with open (snap_file , "w" ) as fh :
256- fh .write (content )
257-
258242 @pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
259243 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."""
265245 snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
266246 snap = json .load (snap_file .open ())
267- content = snap_file .read_text ()
247+ snap_file .read_text ()
268248
269249 # Add a version entry with actual content (the new way that should pass)
270250 snap ["my test" ]["content" ][0 ]["versions" ] = {"ALE" : {"ale" : "20180904" }}
@@ -291,20 +271,12 @@ def test_modules_version_snapshot_content_valid(self):
291271 ]
292272 assert len (version_content_passed ) > 0 , "test_snap_version_content not found in passed tests"
293273
294- # reset the file
295- with open (snap_file , "w" ) as fh :
296- fh .write (content )
297-
298274 @pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
299275 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."""
305277 snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
306278 snap = json .load (snap_file .open ())
307- content = snap_file .read_text ()
279+ snap_file .read_text ()
308280
309281 # Add a version entry with SHA hash format (should be flagged)
310282 snap ["my test" ]["content" ][0 ]["versions" ] = (
@@ -323,20 +295,12 @@ def test_modules_version_snapshot_content_sha_hash(self):
323295 f"Expected 1 test_snap_version_content failure, got { len (version_content_failures )} "
324296 )
325297
326- # reset the file
327- with open (snap_file , "w" ) as fh :
328- fh .write (content )
329-
330298 @pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
331299 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."""
337301 snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
338302 snap = json .load (snap_file .open ())
339- content = snap_file .read_text ()
303+ snap_file .read_text ()
340304
341305 # Create a scenario with multiple tests - one with hash, one with valid content
342306 snap ["test_with_hash" ] = {"content" : [{"versions" : "versions.yml:md5,949da9c6297b613b50e24c421576f3f1" }]}
@@ -361,20 +325,12 @@ def test_modules_version_snapshot_content_mixed_scenario(self):
361325 ]
362326 assert len (version_content_passed ) >= 1 , "Expected at least 1 pass for valid content"
363327
364- # reset the file
365- with open (snap_file , "w" ) as fh :
366- fh .write (content )
367-
368328 @pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
369329 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."""
375331 snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
376332 snap = json .load (snap_file .open ())
377- content = snap_file .read_text ()
333+ snap_file .read_text ()
378334
379335 # Remove version information entirely
380336 if "content" in snap ["my test" ] and snap ["my test" ]["content" ]:
@@ -390,6 +346,25 @@ def test_modules_version_snapshot_no_version_content(self):
390346 version_content_failures = [x for x in module_lint .failed if x .lint_test == "test_snap_version_content" ]
391347 assert len (version_content_failures ) == 0 , "Should not have version content failures when no versions present"
392348
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+
394362 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