Skip to content

Commit 0826296

Browse files
committed
rimport: Add tests of --check w/ file pub'd but not relinked. Failing.
1 parent efa3504 commit 0826296

2 files changed

Lines changed: 83 additions & 14 deletions

File tree

tests/rimport/test_cmdline.py

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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()

tests/rimport/test_stage_data.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def fixture_staging_root(tmp_path):
5454
class TestStageData:
5555
"""Test suite for stage_data() function."""
5656

57-
def test_copies_file_to_staging(self, inputdata_root, staging_root):
58-
"""Test that a file is copied to the staging directory."""
57+
def test_copies_and_relinks_unpublished(self, inputdata_root, staging_root):
58+
"""Test that an unpublished file is copied to the staging directory and relinked."""
5959
# Create file in inputdata root
6060
src = inputdata_root / "file.nc"
6161
src.write_text("data content")
@@ -72,22 +72,35 @@ def test_copies_file_to_staging(self, inputdata_root, staging_root):
7272
assert src.is_symlink()
7373
assert src.resolve() == dst
7474

75-
def test_check_doesnt_copy(self, inputdata_root, staging_root, caplog):
76-
"""Test that a file is NOT copied to the staging directory if check is True"""
75+
def test_check_doesnt_copy_unpublished(self, inputdata_root, staging_root, caplog):
76+
"""Test that an unpublished file is NOT copied to the staging directory if check is True"""
7777
# Create file in inputdata root
78-
src = inputdata_root / "file.nc"
78+
file_basename = "file.nc"
79+
src = inputdata_root / file_basename
7980
src.write_text("data content")
8081

8182
# Check the file
8283
rimport.stage_data(src, inputdata_root, staging_root, check=True)
8384

84-
# Verify file was NOT copied to staging
85-
dst = staging_root / "file.nc"
85+
# Verify file was NOT copied to staging or relinked
86+
dst = staging_root / file_basename
8687
assert not dst.exists()
8788
assert not src.is_symlink()
8889

89-
# Verify message was logged
90-
assert "not already published" in caplog.text
90+
def test_check_doesnt_relink_published(self, inputdata_root, staging_root, caplog):
91+
"""Test that a published file is NOT relinked if check is True"""
92+
# Create file in inputdata root and staging
93+
file_basename = "file.nc"
94+
src = inputdata_root / file_basename
95+
src.write_text("data content")
96+
dst = staging_root / file_basename
97+
dst.write_text("data content")
98+
99+
# Check the file
100+
rimport.stage_data(src, inputdata_root, staging_root, check=True)
101+
102+
# Verify file was NOT relinked
103+
assert not src.is_symlink()
91104

92105
def test_preserves_directory_structure(self, inputdata_root, staging_root):
93106
"""Test that directory structure is preserved in staging."""

0 commit comments

Comments
 (0)