diff --git a/tests/conftest.py b/tests/conftest.py index f7dd92b17..589f41437 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -377,3 +377,16 @@ def with_virtualenv_and_venv( yield return with_virtualenv_and_venv + + +@pytest.fixture() +def temp_pyproject(tmp_path): + """Return function which generates pyproject.toml with the given content""" + + def generator(project_tmpl: str): + with open(tmp_path / "pyproject.toml", "w") as fp: + fp.write(project_tmpl) + + return tmp_path + + return generator diff --git a/tests/test_env_config.py b/tests/test_env_config.py new file mode 100644 index 000000000..9d9a2e5ab --- /dev/null +++ b/tests/test_env_config.py @@ -0,0 +1,34 @@ +EXAMPLE_CONFIG = """ +[tool.poe.env] +GLOBAL_POE_ROOT = "${POE_ROOT}" +GLOBAL_POE_PWD = "${POE_PWD}" + +[tool.poe.tasks.my-task] +default_item_type = "cmd" +sequence = [ + "echo POE_ROOT: ${POE_ROOT}", + "echo GLOBAL_POE_ROOT: ${GLOBAL_POE_ROOT}", + "echo TASK_POE_ROOT: ${TASK_POE_ROOT}", + "echo POE_PWD: ${POE_PWD}", + "echo GLOBAL_POE_PWD: ${GLOBAL_POE_PWD}", + "echo TASK_POE_PWD: ${TASK_POE_PWD}", +] + +[tool.poe.tasks.my-task.env] +TASK_POE_ROOT = "${POE_ROOT}" +TASK_POE_PWD = "${POE_PWD}" +""" + + +def test_global_env_templating(temp_pyproject, run_poe_subproc): + project_path = temp_pyproject(EXAMPLE_CONFIG) + result = run_poe_subproc("my-task", cwd=project_path) + assert result.code == 0 + + printed_vars = { + line.split(": ")[0]: line.split(": ")[1] + for line in result.stdout.split("\n") + if ": " in line + } + for value in printed_vars.values(): + assert value.endswith(str(project_path)[5:]) diff --git a/tests/test_ignore_fail.py b/tests/test_ignore_fail.py index 65c8b2405..97a2b9b31 100644 --- a/tests/test_ignore_fail.py +++ b/tests/test_ignore_fail.py @@ -2,7 +2,7 @@ @pytest.fixture() -def generate_pyproject(tmp_path): +def generate_pyproject(temp_pyproject): """Return function which generates pyproject.toml with a given ignore_fail value.""" def generator(ignore_fail): @@ -20,10 +20,7 @@ def generator(ignore_fail): elif not isinstance(ignore_fail, bool): project_tmpl += f'\nignore_fail = "{ignore_fail}"' - with open(tmp_path / "pyproject.toml", "w") as fp: - fp.write(project_tmpl) - - return tmp_path + return temp_pyproject(project_tmpl) return generator diff --git a/tests/test_ref_task.py b/tests/test_ref_task.py index 82f986109..157e96a5c 100644 --- a/tests/test_ref_task.py +++ b/tests/test_ref_task.py @@ -1,3 +1,24 @@ +def test_ref_task(run_poe_subproc, projects, esc_prefix, is_windows): + # This should be exactly the same as calling the echo task directly + result = run_poe_subproc( + "also_echo", "foo", "!", env={"POETRY_VIRTUALENVS_CREATE": "false"} + ) + if is_windows: + assert result.capture == ( # windows paths need quotes + "Poe => poe_test_echo " + f"'POE_ROOT:{projects['example']}' Password1, task_args: foo '!'\n" + ) + else: + assert result.capture == ( + "Poe => poe_test_echo " + f"POE_ROOT:{projects['example']} Password1, task_args: foo '!'\n" + ) + assert ( + result.stdout == f"POE_ROOT:{projects['example']} Password1, task_args: foo !\n" + ) + assert result.stderr == "" + + def test_ref_passes_named_args_in_definition(run_poe_subproc): result = run_poe_subproc("greet-dave", project="refs") assert result.capture == "Poe => poe_test_echo hi dave\n" diff --git a/tests/test_task_running.py b/tests/test_task_running.py deleted file mode 100644 index 2b55d5f8f..000000000 --- a/tests/test_task_running.py +++ /dev/null @@ -1,19 +0,0 @@ -def test_ref_task(run_poe_subproc, projects, esc_prefix, is_windows): - # This should be exactly the same as calling the echo task directly - result = run_poe_subproc( - "also_echo", "foo", "!", env={"POETRY_VIRTUALENVS_CREATE": "false"} - ) - if is_windows: - assert result.capture == ( # windows paths need quotes - "Poe => poe_test_echo " - f"'POE_ROOT:{projects['example']}' Password1, task_args: foo '!'\n" - ) - else: - assert result.capture == ( - "Poe => poe_test_echo " - f"POE_ROOT:{projects['example']} Password1, task_args: foo '!'\n" - ) - assert ( - result.stdout == f"POE_ROOT:{projects['example']} Password1, task_args: foo !\n" - ) - assert result.stderr == ""