Skip to content

Commit

Permalink
Add basic tests for multiple args option for other task types
Browse files Browse the repository at this point in the history
Also progress a little further on reducing test dependency on echo and env
  • Loading branch information
nat-n committed Jun 7, 2022
1 parent e1ea459 commit 515467e
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 57 deletions.
21 changes: 17 additions & 4 deletions tests/fixtures/cmds_project/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
tool.poe.tasks.show_env = "env"
tool.poe.tasks.show_env = "poe_test_env"

[tool.poe.tasks.echo]
cmd = "echo POE_ROOT:$POE_ROOT ${BEST_PASSWORD}, task_args:"
cmd = "poe_test_echo POE_ROOT:$POE_ROOT ${BEST_PASSWORD}, task_args:"
help = "It says what you say"
env = { BEST_PASSWORD = "Password1" }

[tool.poe.tasks.greet]
shell = "echo $formal_greeting $subject"
shell = "poe_test_echo $formal_greeting $subject"
args = ["formal-greeting", "subject"]

[tool.poe.tasks.surfin-bird]
cmd = "echo $WORD is the word"
cmd = "poe_test_echo $WORD is the word"
env = { WORD = "${SOME_INPUT_VAR}"}

[tool.poe.tasks.multiple-value-arg]
cmd = "poe_test_echo \"first: ${first} second: ${second}\""

[[tool.poe.tasks.multiple-value-arg.args]]
name = "first"
positional = true

[[tool.poe.tasks.multiple-value-arg.args]]
name = "second"
positional = true
multiple = true
type = "integer"
2 changes: 1 addition & 1 deletion tests/fixtures/default_value_project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ FIVE.default = "nope"
SIX.default = "!six!"

[tool.poe.tasks.test]
cmd = "echo $ONE $TWO $THREE $FOUR $FIVE $SIX"
cmd = "poe_test_echo $ONE $TWO $THREE $FOUR $FIVE $SIX"
env.TWO = "!two!"
env.FIVE = "!five!"
env.SIX.default = "nope"
4 changes: 2 additions & 2 deletions tests/fixtures/envfile_project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ env = { HOST = "${HOST}:80" }

[tool.poe.tasks.deploy-dev]
cmd = """
echo "deploying to ${USER}:${PASSWORD}@${HOST}${PATH_SUFFIX}"
poe_test_echo "deploying to ${USER}:${PASSWORD}@${HOST}${PATH_SUFFIX}"
"""
env = { HOST = "${HOST}80" } # reference and override value from envfile

[tool.poe.tasks.deploy-prod]
cmd = """
echo "deploying to ${USER}:${PASSWORD}@${HOST}${PATH_SUFFIX}"
poe_test_echo "deploying to ${USER}:${PASSWORD}@${HOST}${PATH_SUFFIX}"
"""
envfile = "prod.env"
8 changes: 4 additions & 4 deletions tests/fixtures/includes_project/greet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
default_greeting = "Hello"

[tool.poe.tasks]
echo.cmd = "echo echo echo"
echo.cmd = "poe_test_echo echo echo"
echo.help = "This is ignored becuase it's already defined!"

greet = "echo $default_greeting"
greet = "poe_test_echo $default_greeting"

greet1 = "echo Hoi"
greet1 = "poe_test_echo Hoi"

greet2.cmd = "echo Hola"
greet2.cmd = "poe_test_echo Hola"
greet2.help = "Issue a greeting from the Iberian Peninsula"
4 changes: 2 additions & 2 deletions tests/fixtures/includes_project/laugh.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"envfile": "some_vars.env",
"tasks": {
"laugh": {
"shell": "echo $ONE_LAUGH | tr a-z A-Z",
"shell": "poe_test_echo $ONE_LAUGH | tr a-z A-Z",
"help": "a mirthful task"
},
"echo": {
"shell": "echo echo echo",
"shell": "poe_test_echo echo echo",
"help": "This is ignored becuase it's already defined!"
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/includes_project/multiple_includes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
include = ["greet.toml", "laugh.json"]

[tool.poe.tasks.echo]
cmd = "echo"
cmd = "poe_test_echo"
help = "says what you say"
2 changes: 1 addition & 1 deletion tests/fixtures/includes_project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ include = "greet.toml"


[tool.poe.tasks.echo]
cmd = "echo"
cmd = "poe_test_echo"
help = "says what you say"
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@


def echo():
print(sys.argv[1:])
"""
Imitates the basic usage of the standard echo command for cross platform usage
"""
print(" ".join(sys.argv[1:]))


def env():
"""
Imitates the basic usage of the standard env command for cross platform usage
"""
for key, value in os.environ.items():
print(f"{key}={value}")
21 changes: 17 additions & 4 deletions tests/fixtures/sequences_project/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[tool.poe.tasks]

part1 = "echo 'Hello'"
_part2.cmd = "echo '${SUBJECT}!'"
part1 = "poe_test_echo 'Hello'"
_part2.cmd = "poe_test_echo '${SUBJECT}!'"
_part2.env = { SUBJECT = "World" }
composite_task.sequence = [
["part1", "_part2"],
# wrapping in arrays means we can have different types of task in the sequence
[{cmd = "echo '${SMILEY}!'"}]
[{cmd = "poe_test_echo '${SMILEY}!'"}]
]
# env var is inherited by subtask
composite_task.env = { SMILEY = ":)" }
Expand All @@ -20,6 +20,19 @@ greet-multiple.args = ["mouse"]


travel = [
{ cmd = "echo 'from $PLANET to'" },
{ cmd = "poe_test_echo 'from $PLANET to'" },
{ script = "my_package:print_var('DEST')" }
]

[tool.poe.tasks.multiple-value-arg]
sequence = [{ cmd = "poe_test_echo first: ${first}" }, { cmd = " poe_test_echo second: ${second}" }]

[[tool.poe.tasks.multiple-value-arg.args]]
name = "first"
positional = true

[[tool.poe.tasks.multiple-value-arg.args]]
name = "second"
positional = true
multiple = true
type = "integer"
39 changes: 30 additions & 9 deletions tests/fixtures/shells_project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@ tool.poe.default_task_type = "shell"

[tool.poe.tasks]

count = "echo 1 && echo 2 && echo $(python -c 'print(1 + 2)')"
count = "poe_test_echo 1 && poe_test_echo 2 && poe_test_echo $(python -c 'print(1 + 2)')"

sing = """
echo "this is the story";
echo "all about how" && # the last line won't run
echo "my life got flipped;
poe_test_echo "this is the story";
poe_test_echo "all about how" && # the last line won't run
poe_test_echo "my life got flipped;
turned upside down" ||
echo "bam bam baaam bam"
poe_test_echo "bam bam baaam bam"
"""

[tool.poe.tasks.greet]
shell = "echo $formal_greeting $subject"
shell = "poe_test_echo $formal_greeting $subject"
args = ["formal-greeting", "subject"]


[tool.poe.tasks.echo_sh]
interpreter = ["sh"]
shell = "echo $0 $test_var"
shell = "poe_test_echo $0 $test_var"
env = { test_var = "roflcopter"}


[tool.poe.tasks.echo_bash]
interpreter = "bash"
shell = "echo $0 $test_var"
shell = "poe_test_echo $0 $test_var"
env = { test_var = "roflcopter"}


[tool.poe.tasks.echo_pwsh]
interpreter = "pwsh"
shell = "echo $ENV:test_var"
shell = "poe_test_echo $ENV:test_var"
env = { test_var = "roflcopter"}


Expand All @@ -42,3 +42,24 @@ import sys, os
print(sys.version_info, os.environ.get("test_var"))
"""
env = { test_var = "roflcopter"}


[tool.poe.tasks.multiple-value-arg]
shell = """
poe_test_echo "first: ${first} second: ${second}"
# bash treats space delimited string like array for iteration!
for word in $second; do
poe_test_echo $word
done
"""

[[tool.poe.tasks.multiple-value-arg.args]]
name = "first"
positional = true

[[tool.poe.tasks.multiple-value-arg.args]]
name = "second"
positional = true
multiple = true
type = "integer"
15 changes: 11 additions & 4 deletions tests/test_cmd_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ def test_call_echo_task(run_poe_subproc, projects, esc_prefix):
result = run_poe_subproc("echo", "foo", "!", project="cmds")
assert (
result.capture
== f"Poe => echo POE_ROOT:{projects['cmds']} Password1, task_args: foo !\n"
== f"Poe => poe_test_echo POE_ROOT:{projects['cmds']} Password1, task_args: foo !\n"
)
assert result.stdout == f"POE_ROOT:{projects['cmds']} Password1, task_args: foo !\n"
assert result.stderr == ""


def test_setting_envvar_in_task(run_poe_subproc, projects):
result = run_poe_subproc("show_env", project="cmds")
assert result.capture == f"Poe => env\n"
assert result.capture == f"Poe => poe_test_env\n"
assert f"POE_ROOT={projects['cmds']}" in result.stdout
assert result.stderr == ""

Expand All @@ -19,7 +19,7 @@ def test_cmd_task_with_dash_case_arg(run_poe_subproc):
result = run_poe_subproc(
"greet", "--formal-greeting=hey", "--subject=you", project="cmds"
)
assert result.capture == f"Poe => echo $formal_greeting $subject\n"
assert result.capture == f"Poe => poe_test_echo $formal_greeting $subject\n"
assert result.stdout == "hey you\n"
assert result.stderr == ""

Expand All @@ -28,6 +28,13 @@ def test_cmd_alias_env_var(run_poe_subproc):
result = run_poe_subproc(
"surfin-bird", project="cmds", env={"SOME_INPUT_VAR": "BIRD"}
)
assert result.capture == f"Poe => echo BIRD is the word\n"
assert result.capture == f"Poe => poe_test_echo BIRD is the word\n"
assert result.stdout == "BIRD is the word\n"
assert result.stderr == ""


def test_cmd_multiple_value_arg(run_poe_subproc):
result = run_poe_subproc("multiple-value-arg", "hey", "1", "2", "3", project="cmds")
assert result.capture == "Poe => poe_test_echo first: hey second: 1 2 3\n"
assert result.stdout == "first: hey second: 1 2 3\n"
assert result.stderr == ""
7 changes: 5 additions & 2 deletions tests/test_default_value.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
def test_global_envfile_and_default(run_poe_subproc):
result = run_poe_subproc("test", project="default_value")
assert "Poe => echo !one! !two! !three! !four! !five! !six!\n" in result.capture
assert (
"Poe => poe_test_echo !one! !two! !three! !four! !five! !six!\n"
in result.capture
)
assert result.stdout == "!one! !two! !three! !four! !five! !six!\n"
assert result.stderr == ""

Expand All @@ -16,6 +19,6 @@ def test_global_envfile_and_default_with_presets(run_poe_subproc):
}

result = run_poe_subproc("test", project="default_value", env=env)
assert "Poe => echo !one! !two! !three! 444 !five! 666\n" in result.capture
assert "Poe => poe_test_echo !one! !two! !three! 444 !five! 666\n" in result.capture
assert result.stdout == "!one! !two! !three! 444 !five! 666\n"
assert result.stderr == ""
8 changes: 4 additions & 4 deletions tests/test_envfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ def test_global_envfile_and_default(run_poe_subproc, is_windows):
if is_windows:
# On windows shlex works in non-POSIX mode which results in quotes
assert (
'Poe => echo "deploying to admin:12345@dev.example.com:8080"\n'
'Poe => poe_test_echo "deploying to admin:12345@dev.example.com:8080"\n'
in result.capture
)
assert result.stdout == '"deploying to admin:12345@dev.example.com:8080"\n'
assert result.stderr == ""
else:
assert (
"Poe => echo deploying to admin:12345@dev.example.com:8080\n"
"Poe => poe_test_echo deploying to admin:12345@dev.example.com:8080\n"
in result.capture
)
assert result.stdout == "deploying to admin:12345@dev.example.com:8080\n"
Expand All @@ -26,14 +26,14 @@ def test_task_envfile_and_default(run_poe_subproc, is_windows):
result = run_poe_subproc("deploy-prod", project="envfile")
if is_windows:
assert (
'Poe => echo "deploying to admin:12345@prod.example.com/app"\n'
'Poe => poe_test_echo "deploying to admin:12345@prod.example.com/app"\n'
in result.capture
)
assert result.stdout == '"deploying to admin:12345@prod.example.com/app"\n'
assert result.stderr == ""
else:
assert (
"Poe => echo deploying to admin:12345@prod.example.com/app\n"
"Poe => poe_test_echo deploying to admin:12345@prod.example.com/app\n"
in result.capture
)
assert result.stdout == "deploying to admin:12345@prod.example.com/app\n"
Expand Down
10 changes: 5 additions & 5 deletions tests/test_includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def test_docs_for_include_toml_file(run_poe_subproc):

def test_run_task_included_from_toml_file(run_poe_subproc):
result = run_poe_subproc("greet", "Whirl!", project="includes")
assert result.capture == "Poe => echo Hello Whirl!\n"
assert result.capture == "Poe => poe_test_echo Hello Whirl!\n"
assert result.stdout == "Hello Whirl!\n"
assert result.stderr == ""


def test_run_task_not_included_from_toml_file(run_poe_subproc):
result = run_poe_subproc("echo", "Whirl!", project="includes")
assert result.capture == "Poe => echo Whirl!\n"
assert result.capture == "Poe => poe_test_echo Whirl!\n"
assert result.stdout == "Whirl!\n"
assert result.stderr == ""

Expand Down Expand Up @@ -48,21 +48,21 @@ def test_running_from_multiple_includes(run_poe_subproc, projects):
"Whirl!",
project="includes",
)
assert result.capture == "Poe => echo Whirl!\n"
assert result.capture == "Poe => poe_test_echo Whirl!\n"
assert result.stdout == "Whirl!\n"
assert result.stderr == ""

result = run_poe_subproc(
f'--root={projects["includes/multiple_includes"]}', "greet", "Whirl!"
)
assert result.capture == "Poe => echo Hello Whirl!\n"
assert result.capture == "Poe => poe_test_echo Hello Whirl!\n"
assert result.stdout == "Hello Whirl!\n"
assert result.stderr == ""

result = run_poe_subproc(
f'--root={projects["includes/multiple_includes"]}', "laugh"
)
assert result.capture == "Poe => echo $ONE_LAUGH | tr a-z A-Z\n"
assert result.capture == "Poe => poe_test_echo $ONE_LAUGH | tr a-z A-Z\n"
assert result.stdout == "LOL\n"
assert result.stderr == ""

Expand Down
Loading

0 comments on commit 515467e

Please sign in to comment.