-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
test_poetry_plugin.py
200 lines (167 loc) · 6.98 KB
/
test_poetry_plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import os
import re
import pytest
@pytest.fixture(scope="session")
def _setup_poetry_project(run_poetry, projects):
run_poetry(["install"], cwd=projects["poetry_plugin"])
@pytest.fixture(scope="session")
def _setup_poetry_project_empty_prefix(run_poetry, projects):
run_poetry(["install"], cwd=projects["poetry_plugin/empty_prefix"].parent)
@pytest.fixture(scope="session")
def _setup_poetry_project_with_prefix(run_poetry, projects):
run_poetry(["install"], cwd=projects["poetry_plugin/with_prefix"].parent)
@pytest.mark.slow()
def test_poetry_help(run_poetry, projects):
result = run_poetry([], cwd=projects["poetry_plugin"])
assert result.stdout.startswith("Poetry (version ")
assert "poe cow-greet" in result.stdout
assert re.search(r"\n poe echo\s+It's like echo\n", result.stdout)
# assert result.stderr == ""
# TODO: re-enable this test
@pytest.mark.skipif(
os.environ.get("GITHUB_ACTIONS", "false") == "true",
reason="Skipping test the doesn't seem to work in GitHub Actions lately",
)
@pytest.mark.slow()
@pytest.mark.usefixtures("_setup_poetry_project")
def test_task_with_cli_dependency(run_poetry, projects, is_windows):
result = run_poetry(
["poe", "cow-greet", "yo yo yo"],
cwd=projects["poetry_plugin"],
)
if is_windows:
assert result.stdout.startswith("Poe => cowpy 'yo yo yo'")
assert "< yo yo yo >" in result.stdout
else:
# On POSIX cowpy expects notices its being called as a subprocess and tries
# unproductively to take input from stdin
assert result.stdout.startswith("Poe => cowpy 'yo yo yo'")
assert (
"< Cowacter, eyes:default, tongue:False, thoughts:False >" in result.stdout
)
# assert result.stderr == ""
# TODO: re-enable this test
@pytest.mark.skipif(
os.environ.get("GITHUB_ACTIONS", "false") == "true",
reason="Skipping test the doesn't seem to work in GitHub Actions lately",
)
@pytest.mark.slow()
@pytest.mark.usefixtures("_setup_poetry_project")
def test_task_with_lib_dependency(run_poetry, projects):
result = run_poetry(["poe", "cow-cheese"], cwd=projects["poetry_plugin"])
assert result.stdout == (
"Poe => from cowpy import cow; print(list(cow.COWACTERS)[5])\ncheese\n"
)
# assert result.stderr == ""
@pytest.mark.slow()
@pytest.mark.usefixtures("_setup_poetry_project")
def test_task_accepts_any_args(run_poetry, projects):
result = run_poetry(
["poe", "echo", "--lol=:D", "--version", "--help"],
cwd=projects["poetry_plugin"],
)
assert result.stdout == (
"Poe => poe_test_echo --lol=:D --version --help\n--lol=:D --version --help\n"
)
# assert result.stderr == ""
@pytest.mark.slow()
@pytest.mark.usefixtures("_setup_poetry_project_empty_prefix")
def test_poetry_help_without_poe_command_prefix(run_poetry, projects):
result = run_poetry([], cwd=projects["poetry_plugin/empty_prefix"].parent)
assert result.stdout.startswith("Poetry (version ")
assert "\n cow-greet" in result.stdout
assert "\n echo It's like echo\n" in result.stdout
# assert result.stderr == ""
@pytest.mark.slow()
@pytest.mark.usefixtures("_setup_poetry_project_empty_prefix")
def test_running_tasks_without_poe_command_prefix(run_poetry, projects):
result = run_poetry(
["echo", "--lol=:D", "--version", "--help"],
cwd=projects["poetry_plugin/empty_prefix"].parent,
)
assert result.stdout == (
"Poe => poe_test_echo --lol=:D --version --help\n--lol=:D --version --help\n"
)
# assert result.stderr == ""
@pytest.mark.slow()
@pytest.mark.usefixtures("_setup_poetry_project_empty_prefix")
def test_poetry_command_from_included_file_with_empty_prefix(run_poetry, projects):
result = run_poetry(
["included-greeting"],
cwd=projects["poetry_plugin/empty_prefix"].parent,
)
assert result.stdout.startswith("Poe => echo 'Greetings from another file!'")
# assert result.stderr == ""
@pytest.mark.slow()
@pytest.mark.usefixtures("_setup_poetry_project_empty_prefix")
def test_poetry_help_with_poe_command_prefix(run_poetry, projects):
result = run_poetry([], cwd=projects["poetry_plugin/with_prefix"].parent)
assert result.stdout.startswith("Poetry (version ")
assert "\n foo cow-greet" in result.stdout
assert "\n foo echo It's like echo\n" in result.stdout
# assert result.stderr == ""
@pytest.mark.slow()
@pytest.mark.usefixtures("_setup_poetry_project_with_prefix")
def test_running_tasks_with_poe_command_prefix(run_poetry, projects):
result = run_poetry(
["foo", "echo", "--lol=:D", "--version", "--help"],
cwd=projects["poetry_plugin/with_prefix"].parent,
)
assert result.stdout == (
"Poe => poe_test_echo --lol=:D --version --help\n--lol=:D --version --help\n"
)
# assert result.stderr == ""
@pytest.mark.slow()
@pytest.mark.usefixtures("_setup_poetry_project_with_prefix")
def test_running_tasks_with_poe_command_prefix_missing_args(run_poetry, projects):
result = run_poetry(
["foo"],
cwd=projects["poetry_plugin/with_prefix"].parent,
)
assert "Usage:\n poetry foo [global options]" in result.stdout
# assert result.stderr == ""
@pytest.mark.slow()
@pytest.mark.usefixtures("_setup_poetry_project")
def test_running_poetry_command_with_hooks(run_poetry, projects):
result = run_poetry(["env", "info"], cwd=projects["poetry_plugin"])
assert "THIS IS YOUR ENV!" in result.stdout
assert "THAT WAS YOUR ENV!" in result.stdout
# assert result.stderr == ""
@pytest.mark.slow()
@pytest.mark.usefixtures("_setup_poetry_project")
def test_running_poetry_command_with_hooks_with_directory(run_poetry, projects):
result = run_poetry(
["--directory=" + str(projects["poetry_plugin"]), "env", "info"],
cwd=projects["poetry_plugin"].parent,
)
assert "THIS IS YOUR ENV!" in result.stdout
assert "THAT WAS YOUR ENV!" in result.stdout
# assert result.stderr == ""
# TODO: re-enable this test
@pytest.mark.skipif(
os.environ.get("GITHUB_ACTIONS", "false") == "true",
reason="Skipping test the doesn't seem to work in GitHub Actions lately",
)
@pytest.mark.slow()
@pytest.mark.usefixtures("_setup_poetry_project")
def test_task_with_cli_dependency_with_directory(run_poetry, projects, is_windows):
result = run_poetry(
[
"--directory=" + str(projects["poetry_plugin"]),
"poe",
"cow-greet",
"yo yo yo",
],
cwd=projects["poetry_plugin"].parent,
)
if is_windows:
assert result.stdout.startswith("Poe => cowpy 'yo yo yo'")
assert "< yo yo yo >" in result.stdout
else:
# On POSIX cowpy expects notices its being called as a subprocess and tries
# unproductively to take input from stdin
assert result.stdout.startswith("Poe => cowpy 'yo yo yo'")
assert (
"< Cowacter, eyes:default, tongue:False, thoughts:False >" in result.stdout
)
# assert result.stderr == ""