Skip to content

Commit

Permalink
Add failing test and more robust fix for nat-n#158
Browse files Browse the repository at this point in the history
  • Loading branch information
nat-n committed Aug 5, 2023
1 parent 1968a68 commit b59abae
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
5 changes: 3 additions & 2 deletions poethepoet/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ def _merge_config(
include_path: Path,
task_cwd: Optional[str],
):
from .task import PoeTask

try:
poe_config = extra_config.get("tool", {}).get("poe", {})
tasks = poe_config.get("tasks", {})
Expand All @@ -291,8 +293,7 @@ def _merge_config(
for task_name, task_def in tasks.items():
if isinstance(task_def, str):
# If the task is a string, then convert it to the dict form
task_def = {"cmd": task_def}
tasks[task_name] = task_def
task_def = PoeTask.normalize_task_def(task_def, self)
if task_cwd:
# Override the config of each task to use the include level cwd as a
# base for the task level cwd
Expand Down
6 changes: 3 additions & 3 deletions poethepoet/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def from_def(
options["capture_stdout"] = capture_stdout

if isinstance(task_def, (str, list)):
task_def = cls._normalize_task_def(
task_def = cls.normalize_task_def(
task_def, config, task_type=cls.__task_types[task_type]
)

Expand All @@ -151,7 +151,7 @@ def from_def(
)

@classmethod
def _normalize_task_def(
def normalize_task_def(
cls,
task_def: TaskDef,
config: "PoeConfig",
Expand Down Expand Up @@ -450,7 +450,7 @@ def validate_def(
elif isinstance(task_def, list):
task_type_key = config.default_array_task_type
task_type = cls.__task_types[task_type_key]
normalized_task_def = cls._normalize_task_def(
normalized_task_def = cls.normalize_task_def(
task_def, config, task_type=task_type
)
if hasattr(task_type, "_validate_task_def"):
Expand Down
2 changes: 1 addition & 1 deletion poethepoet/task/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _validate_task_def(
else:
subtask_issue = cls.validate_def(
cls._subtask_name(task_name, index),
cls._normalize_task_def(
cls.normalize_task_def(
task_item,
config,
array_item=default_item_type or True,
Expand Down
4 changes: 3 additions & 1 deletion tests/fixtures/monorepo_project/subproject_2/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

tool.poe.include = ["extra_tasks.toml", { path = "../pyproject.toml" }]

[tool.poe.tasks]
echo = "poe_test_echo"

[tool.poe.tasks.get_cwd_2]
interpreter = "python"
shell = "import os; print(os.getcwd())"

22 changes: 10 additions & 12 deletions tests/test_includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def test_monorepo_contains_only_expected_tasks(run_poe_subproc, projects):
"CONFIGURED TASKS\n"
" get_cwd_0 \n"
" get_cwd_1 \n"
" echo \n"
" get_cwd_2 \n\n\n"
)
assert result.stdout == ""
Expand All @@ -98,6 +99,7 @@ def test_monorepo_can_also_include_parent(run_poe_subproc, projects, is_windows)
result = run_poe_subproc(cwd=projects["monorepo/subproject_2"])
assert result.capture.endswith(
"CONFIGURED TASKS\n"
" echo \n"
" get_cwd_2 \n"
" extra_task \n"
" get_cwd_0 \n\n\n"
Expand All @@ -109,12 +111,10 @@ def test_monorepo_can_also_include_parent(run_poe_subproc, projects, is_windows)
assert result.capture == "Poe => import os; print(os.getcwd())\n"
if is_windows:
assert result.stdout.endswith(
"poethepoet\\tests\\fixtures\\monorepo_project\\subproject_2\n"
"\\tests\\fixtures\\monorepo_project\\subproject_2\n"
)
else:
assert result.stdout.endswith(
"poethepoet/tests/fixtures/monorepo_project/subproject_2\n"
)
assert result.stdout.endswith("/tests/fixtures/monorepo_project/subproject_2\n")
assert result.stderr == ""


Expand All @@ -124,27 +124,25 @@ def test_monorepo_runs_each_task_with_expected_cwd(
result = run_poe_subproc("get_cwd_0", project="monorepo")
assert result.capture == "Poe => import os; print(os.getcwd())\n"
if is_windows:
assert result.stdout.endswith("poethepoet\\tests\\fixtures\\monorepo_project\n")
assert result.stdout.endswith("\\tests\\fixtures\\monorepo_project\n")
else:
assert result.stdout.endswith("poethepoet/tests/fixtures/monorepo_project\n")
assert result.stdout.endswith("/tests/fixtures/monorepo_project\n")
assert result.stderr == ""

result = run_poe_subproc("get_cwd_1", project="monorepo")
assert result.capture == "Poe => import os; print(os.getcwd())\n"
if is_windows:
assert result.stdout.endswith("poethepoet\\tests\\fixtures\\monorepo_project\n")
assert result.stdout.endswith("\\tests\\fixtures\\monorepo_project\n")
else:
assert result.stdout.endswith("poethepoet/tests/fixtures/monorepo_project\n")
assert result.stdout.endswith("/tests/fixtures/monorepo_project\n")
assert result.stderr == ""

result = run_poe_subproc("get_cwd_2", project="monorepo")
assert result.capture == "Poe => import os; print(os.getcwd())\n"
if is_windows:
assert result.stdout.endswith(
"poethepoet\\tests\\fixtures\\monorepo_project\\subproject_2\n"
"\\tests\\fixtures\\monorepo_project\\subproject_2\n"
)
else:
assert result.stdout.endswith(
"poethepoet/tests/fixtures/monorepo_project/subproject_2\n"
)
assert result.stdout.endswith("/tests/fixtures/monorepo_project/subproject_2\n")
assert result.stderr == ""

0 comments on commit b59abae

Please sign in to comment.