@@ -455,13 +455,14 @@ def test_error_symlink_pointing_outside_staging(
455455 msg = "is outside staging directory"
456456 assert msg in result .stderr
457457
458- def test_check_doesnt_copy (self , rimport_script , test_env , rimport_env ):
459- """Test that a file is NOT copied to the staging directory if check is True."""
458+ def test_check_doesnt_copy_unpublished (self , rimport_script , test_env , rimport_env ):
459+ """Test that an unpublished file is not copied to the staging directory if check is True."""
460460 inputdata_root = test_env ["inputdata_root" ]
461461 staging_root = test_env ["staging_root" ]
462462
463463 # Create a file in inputdata
464- test_file = inputdata_root / "test.nc"
464+ file_basename = "test.nc"
465+ test_file = inputdata_root / file_basename
465466 test_file .write_text ("test data" )
466467
467468 # Make sure --check skips ensure_running_as()
@@ -472,7 +473,7 @@ def test_check_doesnt_copy(self, rimport_script, test_env, rimport_env):
472473 sys .executable ,
473474 rimport_script ,
474475 "-file" ,
475- "test.nc" ,
476+ file_basename ,
476477 "-inputdata" ,
477478 str (inputdata_root ),
478479 "--check" ,
@@ -490,11 +491,66 @@ def test_check_doesnt_copy(self, rimport_script, test_env, rimport_env):
490491 assert result .returncode == 0 , f"Command failed: { result .stderr } "
491492
492493 # Verify file was not staged
493- staged_file = staging_root / "test.nc"
494+ staged_file = staging_root / file_basename
494495 assert not staged_file .exists ()
495496
496497 # Verify file was not replaced with a symlink
497498 assert not test_file .is_symlink ()
498499
499500 # Verify message was printed
500501 assert "not already published" in result .stdout
502+
503+ # Verify messages weren't printed
504+ assert "already published but NOT linked" .lower () not in result .stdout .lower ()
505+ assert "Deleted original file" .lower () not in result .stdout .lower ()
506+ assert "Created symbolic link" .lower () not in result .stdout .lower ()
507+ assert "Error creating symlink" .lower () not in result .stdout .lower ()
508+
509+ def test_check_doesnt_relink_published (self , rimport_script , test_env , rimport_env ):
510+ """Test that published file is not relinked if check is True."""
511+ inputdata_root = test_env ["inputdata_root" ]
512+ staging_root = test_env ["staging_root" ]
513+
514+ # Create a file in inputdata and staging
515+ file_basename = "test.nc"
516+ test_file = inputdata_root / file_basename
517+ test_file .write_text ("test data" )
518+ staged_file = staging_root / file_basename
519+ staged_file .write_text ("test data" )
520+
521+ # Make sure --check skips ensure_running_as()
522+ del rimport_env ["RIMPORT_SKIP_USER_CHECK" ]
523+
524+ # Run rimport with --check option
525+ command = [
526+ sys .executable ,
527+ rimport_script ,
528+ "-file" ,
529+ file_basename ,
530+ "-inputdata" ,
531+ str (inputdata_root ),
532+ "--check" ,
533+ ]
534+
535+ result = subprocess .run (
536+ command ,
537+ capture_output = True ,
538+ text = True ,
539+ check = False ,
540+ env = rimport_env ,
541+ )
542+
543+ # Verify success
544+ assert result .returncode == 0 , f"Command failed: { result .stderr } "
545+
546+ # Verify file was not replaced with a symlink
547+ assert not test_file .is_symlink ()
548+
549+ # Verify message was printed
550+ assert "already published but NOT linked" .lower () in result .stdout .lower ()
551+
552+ # Verify messages weren't printed
553+ assert "linking now" .lower () not in result .stdout .lower ()
554+ assert "Deleted original file" .lower () not in result .stdout .lower ()
555+ assert "Created symbolic link" .lower () not in result .stdout .lower ()
556+ assert "Error creating symlink" .lower () not in result .stdout .lower ()
0 commit comments