Skip to content

Commit 03fab44

Browse files
Add InterpreterOptions e2e test (#262)
This new test ensures that the `InterpreterOptions` plugin config option is being honoured by `python_binary` by changing the `__main__` module that the Python interpreter is supposed to execute and checking that the correct one is in fact executed.
1 parent 9a17c22 commit 03fab44

File tree

6 files changed

+37
-0
lines changed

6 files changed

+37
-0
lines changed

test/BUILD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,14 @@ python_test(
202202
],
203203
labels = ["manual"],
204204
)
205+
206+
plugin_e2e_test(
207+
name = "interpreter_options_test",
208+
repo = "interpreter_options_repo",
209+
test_cmd = [
210+
"plz run //:binary > binary",
211+
],
212+
expected_output = {
213+
"binary": "Executed plzmodule.py",
214+
},
215+
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Plugin "python"]
2+
Target = //plugins:python
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
subinclude("///python//build_defs:python")
2+
3+
package(
4+
# If InterpreterOptions is being honoured, the Python interpreter should execute plzmodule.py
5+
# as the __main__ module instead of main.py, causing "Executed plzmodule.py" to be printed on
6+
# stdout rather than "Executed binary.py".
7+
python = {
8+
"interpreter_options": ["-m", "plzmodule"],
9+
},
10+
)
11+
12+
python_binary(
13+
name = "binary",
14+
main = "binary.py",
15+
srcs = ["plzmodule.py"],
16+
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if __name__ == "__main__":
2+
print("Executed binary.py")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
plugin_repo(
2+
name = "python",
3+
revision = "e2e",
4+
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if __name__ == "__main__":
2+
print("Executed plzmodule.py")

0 commit comments

Comments
 (0)