Skip to content

Commit

Permalink
fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Nov 24, 2021
1 parent 3690653 commit 9123245
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions cylc/flow/workflow_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ def _parse_src_reg(reg: Path, cur_dir_only: bool = False) -> Tuple[Path, Path]:
return (reg, abs_path)


def validate_workflow_name(name: str) -> None:
def validate_workflow_name(name: str, runNcheck=False) -> None:
"""Check workflow name is valid and not an absolute path.
Raise WorkflowFilesError if not valid.
Expand All @@ -1326,7 +1326,7 @@ def validate_workflow_name(name: str) -> None:
"Workflow name cannot be a path that points to the cylc-run "
"directory or above"
)
if re.findall(r'^run(N|\d+)$', Path(name).name):
if runNcheck and re.findall(r'^run(N|\d+)$', Path(name).name):
raise WorkflowFilesError(
"Workflow name cannot be a folder called 'runN' or "
"'run<number>'."
Expand Down Expand Up @@ -1585,7 +1585,7 @@ def install_workflow(
source = Path(expand_path(source))
if not workflow_name:
workflow_name = source.name
validate_workflow_name(workflow_name)
validate_workflow_name(workflow_name, runNcheck=True)
if run_name in WorkflowFiles.RESERVED_NAMES:
raise WorkflowFilesError(f'Run name cannot be "{run_name}".')
if run_name is not None and len(Path(run_name).parts) != 1:
Expand Down
14 changes: 9 additions & 5 deletions tests/unit/test_workflow_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,16 @@ def test_check_nested_run_dirs(tmp_run_dir: Callable):
('./foo', WorkflowFilesError, "invalid workflow name"),
('meow/..', WorkflowFilesError,
"cannot be a path that points to the cylc-run directory or above"),
('run6', WorkflowFilesError, "cannot end with a folder called 'runN'"),
('e/run6', WorkflowFilesError, "cannot end with a folder called 'runN'"),
('runN', WorkflowFilesError, "cannot end with a folder called 'runN'"),
('e/runN', WorkflowFilesError, "cannot end with a folder called 'runN'")]
('run6', WorkflowFilesError, "cannot be a folder called 'runN'"),
('e/run6', WorkflowFilesError, "cannot be a folder called 'runN'"),
('runN', WorkflowFilesError, "cannot be a folder called 'runN'"),
('e/runN', WorkflowFilesError, "cannot be a folder called 'runN'")]
)
def test_validate_workflow_name(reg, expected_err, expected_msg):
if expected_err:
with pytest.raises(expected_err) as exc:
workflow_files.validate_workflow_name(reg)
runNcheck = 'cannot be a folder called' in expected_msg
workflow_files.validate_workflow_name(reg, runNcheck=runNcheck)
if expected_msg:
assert expected_msg in str(exc.value)
else:
Expand Down Expand Up @@ -1579,6 +1580,7 @@ def mocked_remote_clean_cmd_side_effect(reg, platform, rm_dirs, timeout):
for p_name in failed_platforms:
assert f"{p_name} - {PlatformError.MSG_TIDY}" in caplog.text


@pytest.mark.parametrize(
'rm_dirs, expected_args',
[
Expand Down Expand Up @@ -1760,6 +1762,7 @@ def test_check_flow_file(
else:
assert check_flow_file(tmp_path) == tmp_path.joinpath(expected_file)


def test_detect_both_flow_and_suite(tmp_path):
"""Test flow.cylc and suite.rc together in dir raises error."""
tmp_path.joinpath(WorkflowFiles.FLOW_FILE).touch()
Expand All @@ -1775,6 +1778,7 @@ def test_detect_both_flow_and_suite(tmp_path):
"#backward-compatibility"
)


@pytest.mark.parametrize(
'flow_file_target, suiterc_exists, err, expected_file',
[
Expand Down

0 comments on commit 9123245

Please sign in to comment.