Skip to content

Commit 85b7f33

Browse files
Mock the failure to test the fallback.
1 parent 12cec19 commit 85b7f33

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

src/uwtools/tests/drivers/test_stager.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
"""
44

55
from pathlib import Path
6+
from unittest.mock import patch
67

7-
from pytest import fixture
8+
from pytest import fixture, mark
89

910
from uwtools.api.config import get_yaml_config
1011
from uwtools.drivers.stager import FileStager
11-
12-
# Need one file on a non-/tmp disk for testing hardlink fallback
13-
B_FILE = Path("./b.foo").resolve()
12+
from uwtools.utils import tasks
1413

1514

1615
class NullDriver(FileStager):
@@ -24,14 +23,6 @@ def taskname(self, s):
2423
return f"Null {s}"
2524

2625

27-
def setup_module(module): # noqa: ARG001
28-
B_FILE.touch()
29-
30-
31-
def teardown_module(module): # noqa: ARG001
32-
B_FILE.unlink()
33-
34-
3526
@fixture
3627
def driver(tmp_path):
3728
i = tmp_path / "input"
@@ -42,15 +33,14 @@ def driver(tmp_path):
4233
tmp: %s
4334
files_to_copy:
4435
a.foo: '{{ tmp }}/input/a.foo'
45-
b.foo: %s
36+
b.foo: '{{ tmp }}/input/b.foo'
4637
files_to_link:
4738
c.foo: '{{ tmp }}/input/a.foo'
4839
d.foo: '{{ tmp }}/input/a.foo'
4940
output/<files>: !glob '{{ tmp }}/input/*.foo'
5041
files_to_hardlink:
51-
e.foo: %s
52-
f.foo: '{{ tmp }}/input/a.foo'
53-
""" % (tmp_path, B_FILE, B_FILE)
42+
e.foo: '{{ tmp }}/input/a.foo'
43+
""" % (tmp_path)
5444
cfg = tmp_path / "config.yaml"
5545
cfg.write_text(config)
5646
return NullDriver(config_file=cfg, rundir=tmp_path)
@@ -62,14 +52,18 @@ def test_files_to_copy(driver, tmp_path):
6252
assert (tmp_path / "b.foo").is_file()
6353

6454

65-
def test_files_to_hardlink(driver, tmp_path):
66-
driver.files_hardlinked()
67-
a = tmp_path / "input" / "a.foo"
55+
@mark.parametrize("success", [True, False])
56+
def test_files_to_hardlink(driver, success, tmp_path):
6857
e = tmp_path / "e.foo"
69-
f = tmp_path / "f.foo"
70-
assert e.is_file()
71-
assert not e.samefile(B_FILE)
72-
assert a.samefile(f)
58+
if success:
59+
driver.files_hardlinked()
60+
# It's a hardlink
61+
assert e.stat().st_nlink == 2
62+
else:
63+
with patch.object(tasks.os, "link", side_effect=OSError()):
64+
driver.files_hardlinked()
65+
# It's a copy
66+
assert e.stat().st_nlink == 1
7367

7468

7569
def test_files_to_link(driver, tmp_path):

0 commit comments

Comments
 (0)