From 912324577534ceb0a7ff5a8ac64221adb4d25386 Mon Sep 17 00:00:00 2001 From: Tim Pillinger <26465611+wxtim@users.noreply.github.com> Date: Wed, 24 Nov 2021 08:09:11 +0000 Subject: [PATCH] fix broken tests --- cylc/flow/workflow_files.py | 6 +++--- tests/unit/test_workflow_files.py | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cylc/flow/workflow_files.py b/cylc/flow/workflow_files.py index c28c37b8413..92b501a2898 100644 --- a/cylc/flow/workflow_files.py +++ b/cylc/flow/workflow_files.py @@ -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. @@ -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'." @@ -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: diff --git a/tests/unit/test_workflow_files.py b/tests/unit/test_workflow_files.py index ebb714d0735..6005e46abc7 100644 --- a/tests/unit/test_workflow_files.py +++ b/tests/unit/test_workflow_files.py @@ -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: @@ -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', [ @@ -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() @@ -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', [