From 45e7b3e82362bef96dc33177cc61e770cddc1223 Mon Sep 17 00:00:00 2001 From: Chris Novakovic Date: Wed, 22 Oct 2025 11:43:57 +0100 Subject: [PATCH] Add `InterpreterOptions` e2e test 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. --- test/BUILD | 11 +++++++++++ test/interpreter_options_repo/.plzconfig | 2 ++ test/interpreter_options_repo/BUILD_FILE | 16 ++++++++++++++++ test/interpreter_options_repo/binary.py | 2 ++ test/interpreter_options_repo/plugins/BUILD_FILE | 4 ++++ test/interpreter_options_repo/plzmodule.py | 2 ++ 6 files changed, 37 insertions(+) create mode 100644 test/interpreter_options_repo/.plzconfig create mode 100644 test/interpreter_options_repo/BUILD_FILE create mode 100644 test/interpreter_options_repo/binary.py create mode 100644 test/interpreter_options_repo/plugins/BUILD_FILE create mode 100644 test/interpreter_options_repo/plzmodule.py diff --git a/test/BUILD b/test/BUILD index 216d6e2..108ddae 100644 --- a/test/BUILD +++ b/test/BUILD @@ -202,3 +202,14 @@ python_test( ], labels = ["manual"], ) + +plugin_e2e_test( + name = "interpreter_options_test", + repo = "interpreter_options_repo", + test_cmd = [ + "plz run //:binary > binary", + ], + expected_output = { + "binary": "Executed plzmodule.py", + }, +) diff --git a/test/interpreter_options_repo/.plzconfig b/test/interpreter_options_repo/.plzconfig new file mode 100644 index 0000000..2ffad3a --- /dev/null +++ b/test/interpreter_options_repo/.plzconfig @@ -0,0 +1,2 @@ +[Plugin "python"] +Target = //plugins:python diff --git a/test/interpreter_options_repo/BUILD_FILE b/test/interpreter_options_repo/BUILD_FILE new file mode 100644 index 0000000..94913ca --- /dev/null +++ b/test/interpreter_options_repo/BUILD_FILE @@ -0,0 +1,16 @@ +subinclude("///python//build_defs:python") + +package( + # If InterpreterOptions is being honoured, the Python interpreter should execute plzmodule.py + # as the __main__ module instead of main.py, causing "Executed plzmodule.py" to be printed on + # stdout rather than "Executed binary.py". + python = { + "interpreter_options": ["-m", "plzmodule"], + }, +) + +python_binary( + name = "binary", + main = "binary.py", + srcs = ["plzmodule.py"], +) diff --git a/test/interpreter_options_repo/binary.py b/test/interpreter_options_repo/binary.py new file mode 100644 index 0000000..c16be82 --- /dev/null +++ b/test/interpreter_options_repo/binary.py @@ -0,0 +1,2 @@ +if __name__ == "__main__": + print("Executed binary.py") diff --git a/test/interpreter_options_repo/plugins/BUILD_FILE b/test/interpreter_options_repo/plugins/BUILD_FILE new file mode 100644 index 0000000..bd8b3fd --- /dev/null +++ b/test/interpreter_options_repo/plugins/BUILD_FILE @@ -0,0 +1,4 @@ +plugin_repo( + name = "python", + revision = "e2e", +) diff --git a/test/interpreter_options_repo/plzmodule.py b/test/interpreter_options_repo/plzmodule.py new file mode 100644 index 0000000..4e61a7d --- /dev/null +++ b/test/interpreter_options_repo/plzmodule.py @@ -0,0 +1,2 @@ +if __name__ == "__main__": + print("Executed plzmodule.py")