Skip to content

Commit

Permalink
Add passing test for #198
Browse files Browse the repository at this point in the history
  • Loading branch information
nat-n committed Apr 27, 2024
1 parent edb3383 commit 9f18478
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 24 deletions.
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 34 additions & 0 deletions tests/test_env_config.py
Original file line number Diff line number Diff line change
@@ -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:] + "'")
7 changes: 2 additions & 5 deletions tests/test_ignore_fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down
21 changes: 21 additions & 0 deletions tests/test_ref_task.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
19 changes: 0 additions & 19 deletions tests/test_task_running.py

This file was deleted.

0 comments on commit 9f18478

Please sign in to comment.