Skip to content

Commit

Permalink
Merge pull request #6321 from MetRonnie/tests
Browse files Browse the repository at this point in the history
Prevent a couple of unit tests from installing into `~/cylc-run`
  • Loading branch information
wxtim authored Aug 23, 2024
2 parents 6a51b48 + 83b7db9 commit fafe8e5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
50 changes: 25 additions & 25 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,36 +82,36 @@ def _tmp_run_dir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
# Or:
cylc_run_dir = tmp_run_dir()
"""
cylc_run_dir = tmp_path / 'cylc-run'
cylc_run_dir.mkdir(exist_ok=True)
monkeypatch.setattr('cylc.flow.pathutil._CYLC_RUN_DIR', cylc_run_dir)

def __tmp_run_dir(
id_: Optional[str] = None,
installed: bool = False,
named: bool = False
) -> Path:
nonlocal tmp_path
nonlocal monkeypatch
cylc_run_dir = tmp_path / 'cylc-run'
cylc_run_dir.mkdir(exist_ok=True)
monkeypatch.setattr('cylc.flow.pathutil._CYLC_RUN_DIR', cylc_run_dir)
if id_:
run_dir = cylc_run_dir.joinpath(id_)
run_dir.mkdir(parents=True, exist_ok=True)
(run_dir / WorkflowFiles.FLOW_FILE).touch(exist_ok=True)
(run_dir / WorkflowFiles.Service.DIRNAME).mkdir(exist_ok=True)
if run_dir.name.startswith('run'):
unlink_runN(run_dir.parent)
link_runN(run_dir)
if installed:
if named:
if len(Path(id_).parts) < 2:
raise ValueError("Named run requires two-level id_")
(run_dir.parent / WorkflowFiles.Install.DIRNAME).mkdir(
exist_ok=True)
else:
(run_dir / WorkflowFiles.Install.DIRNAME).mkdir(
exist_ok=True)

return run_dir
return cylc_run_dir
if not id_:
return cylc_run_dir

run_dir = cylc_run_dir.joinpath(id_)
run_dir.mkdir(parents=True, exist_ok=True)
(run_dir / WorkflowFiles.FLOW_FILE).touch(exist_ok=True)
(run_dir / WorkflowFiles.Service.DIRNAME).mkdir(exist_ok=True)
if run_dir.name.startswith('run'):
unlink_runN(run_dir.parent)
link_runN(run_dir)
if installed:
if named:
if len(Path(id_).parts) < 2:
raise ValueError("Named run requires two-level id_")
(run_dir.parent / WorkflowFiles.Install.DIRNAME).mkdir(
exist_ok=True)
else:
(run_dir / WorkflowFiles.Install.DIRNAME).mkdir(exist_ok=True)

return run_dir

return __tmp_run_dir


Expand Down
2 changes: 0 additions & 2 deletions tests/unit/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def test_init_clean__no_dir(
) -> None:
"""Test init_clean() when the run dir doesn't exist"""
caplog.set_level(logging.INFO, CYLC_LOG)
tmp_run_dir()
mock_clean = monkeymock('cylc.flow.clean.clean')
mock_remote_clean = monkeymock('cylc.flow.clean.remote_clean')

Expand Down Expand Up @@ -754,7 +753,6 @@ def test_clean__targeted(
"""
# --- Setup ---
caplog.set_level(logging.DEBUG, CYLC_LOG)
tmp_run_dir()
id_ = 'foo/bar'
run_dir: Path
files_to_delete: List[str]
Expand Down
6 changes: 2 additions & 4 deletions tests/unit/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def test_install_workflow__max_depth(
prevent_symlinking,
):
"""Test that trying to install beyond max depth fails."""
tmp_run_dir()
src_dir = tmp_src_dir('bar')
if err_expected:
with pytest.raises(WorkflowFilesError) as exc_info:
Expand Down Expand Up @@ -138,7 +137,6 @@ def test_install_workflow__symlink_target_exists(
already exists."""
id_ = 'smeagol'
src_dir: Path = tmp_src_dir(id_)
tmp_run_dir()
sym_run = tmp_path / 'sym-run'
sym_log = tmp_path / 'sym-log'
mock_glbl_cfg(
Expand Down Expand Up @@ -544,7 +542,7 @@ def test_validate_source_dir(tmp_run_dir: Callable, tmp_src_dir: Callable):
assert "exists in source directory" in str(exc_info.value)


def test_install_workflow_failif_name_name(tmp_src_dir):
def test_install_workflow_failif_name_name(tmp_src_dir, tmp_run_dir):
"""If a run_name is given validate_workflow_name is called on
the workflow and the run name in combination.
"""
Expand All @@ -560,7 +558,7 @@ def test_install_workflow_failif_name_name(tmp_src_dir):
install_workflow(src_dir, workflow_name='foo', run_name='bar?')


def test_install_workflow_failif_reserved_name(tmp_src_dir):
def test_install_workflow_failif_reserved_name(tmp_src_dir, tmp_run_dir):
"""Reserved names cause install validation failure.
n.b. manually defined to avoid test dependency on workflow_files.
Expand Down

0 comments on commit fafe8e5

Please sign in to comment.