From 1462412eb36d54eecbb1888cb345b89e40819b7d Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 4 Jun 2025 16:27:27 +0100 Subject: [PATCH 1/3] test(pypack1): add version and scripting test --- e2e/binary/pypack1/BUILD.bazel | 33 +++++++++++++++++++++++++++------ e2e/binary/pypack1/hello.py | 11 +++++++++++ e2e/binary/pypack1/python.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/pypack1/hello.py create mode 100644 e2e/binary/pypack1/python.py diff --git a/e2e/binary/pypack1/BUILD.bazel b/e2e/binary/pypack1/BUILD.bazel index ec004a69..462efb24 100644 --- a/e2e/binary/pypack1/BUILD.bazel +++ b/e2e/binary/pypack1/BUILD.bazel @@ -1,11 +1,32 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") -# TODO: write an _actual_ test for `pypack1` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["python.py"], + data = [ + "hello.py", + "@ape//ape:pypack1", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "pypack1", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:pypack1"], + src = "@ape//ape:pypack1", + args = ["--version"], + visibility = ["//:__subpackages__"], +) + +test_suite( + name = "pypack1", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/pypack1/hello.py b/e2e/binary/pypack1/hello.py new file mode 100644 index 00000000..1d1fe875 --- /dev/null +++ b/e2e/binary/pypack1/hello.py @@ -0,0 +1,11 @@ +import sys + + +def main() -> int: + print("Hello!", end="") + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/e2e/binary/pypack1/python.py b/e2e/binary/pypack1/python.py new file mode 100644 index 00000000..87b0d306 --- /dev/null +++ b/e2e/binary/pypack1/python.py @@ -0,0 +1,30 @@ +from __future__ import annotations + +from subprocess import PIPE, run + +from binary import Relative, Tool + + +def test_script(tool: Tool, relative: Relative) -> None: + binary = tool("pypack1") + hello = relative("hello.py") + + cmd = (binary, hello) + r = run(cmd, check=True, timeout=30, stdout=PIPE, text=True) + + assert 0 == r.returncode + assert "Hello!" == r.stdout + + +def test_command(tool: Tool) -> None: + binary = tool("pypack1") + + cmd = ( + binary, + "-c", + "print('Hello!', end='')", + ) + r = run(cmd, check=True, timeout=30, stdout=PIPE, text=True) + + assert 0 == r.returncode + assert "Hello!" == r.stdout -- GitLab From f444b8d3b93d477137eae15425020589073d0e2e Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 4 Jun 2025 16:28:07 +0100 Subject: [PATCH 2/3] test(pypack2): add version and scripting test --- e2e/binary/pypack2/BUILD.bazel | 33 +++++++++++++++++++++++++++------ e2e/binary/pypack2/hello.py | 11 +++++++++++ e2e/binary/pypack2/python.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/pypack2/hello.py create mode 100644 e2e/binary/pypack2/python.py diff --git a/e2e/binary/pypack2/BUILD.bazel b/e2e/binary/pypack2/BUILD.bazel index e88a9837..325bca7e 100644 --- a/e2e/binary/pypack2/BUILD.bazel +++ b/e2e/binary/pypack2/BUILD.bazel @@ -1,11 +1,32 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") -# TODO: write an _actual_ test for `pypack2` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["python.py"], + data = [ + "hello.py", + "@ape//ape:pypack2", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "pypack2", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:pypack2"], + src = "@ape//ape:pypack2", + args = ["--version"], + visibility = ["//:__subpackages__"], +) + +test_suite( + name = "pypack2", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/pypack2/hello.py b/e2e/binary/pypack2/hello.py new file mode 100644 index 00000000..1d1fe875 --- /dev/null +++ b/e2e/binary/pypack2/hello.py @@ -0,0 +1,11 @@ +import sys + + +def main() -> int: + print("Hello!", end="") + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/e2e/binary/pypack2/python.py b/e2e/binary/pypack2/python.py new file mode 100644 index 00000000..0e1cb389 --- /dev/null +++ b/e2e/binary/pypack2/python.py @@ -0,0 +1,30 @@ +from __future__ import annotations + +from subprocess import PIPE, run + +from binary import Relative, Tool + + +def test_script(tool: Tool, relative: Relative) -> None: + binary = tool("pypack2") + hello = relative("hello.py") + + cmd = (binary, hello) + r = run(cmd, check=True, timeout=30, stdout=PIPE, text=True) + + assert 0 == r.returncode + assert "Hello!" == r.stdout + + +def test_command(tool: Tool) -> None: + binary = tool("pypack2") + + cmd = ( + binary, + "-c", + "print('Hello!', end='')", + ) + r = run(cmd, check=True, timeout=30, stdout=PIPE, text=True) + + assert 0 == r.returncode + assert "Hello!" == r.stdout -- GitLab From 73986b301a8f116f6ef387fe731ba44900b41fe9 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 4 Jun 2025 16:30:06 +0100 Subject: [PATCH 3/3] test(datasette): add version and scripting case --- e2e/binary/datasette/BUILD.bazel | 33 ++++++++++++++++++++++++++------ e2e/binary/datasette/hello.py | 11 +++++++++++ e2e/binary/datasette/python.py | 30 +++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/datasette/hello.py create mode 100644 e2e/binary/datasette/python.py diff --git a/e2e/binary/datasette/BUILD.bazel b/e2e/binary/datasette/BUILD.bazel index 9cf32e2b..b4c6b1c0 100644 --- a/e2e/binary/datasette/BUILD.bazel +++ b/e2e/binary/datasette/BUILD.bazel @@ -1,11 +1,32 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") -# TODO: write an _actual_ test for `datasette` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["python.py"], + data = [ + "hello.py", + "@ape//ape:datasette", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "datasette", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:datasette"], + src = "@ape//ape:datasette", + args = ["--version"], + visibility = ["//:__subpackages__"], +) + +test_suite( + name = "datasette", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/datasette/hello.py b/e2e/binary/datasette/hello.py new file mode 100644 index 00000000..1d1fe875 --- /dev/null +++ b/e2e/binary/datasette/hello.py @@ -0,0 +1,11 @@ +import sys + + +def main() -> int: + print("Hello!", end="") + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/e2e/binary/datasette/python.py b/e2e/binary/datasette/python.py new file mode 100644 index 00000000..21f063b0 --- /dev/null +++ b/e2e/binary/datasette/python.py @@ -0,0 +1,30 @@ +from __future__ import annotations + +from subprocess import PIPE, run + +from binary import Relative, Tool + + +def test_script(tool: Tool, relative: Relative) -> None: + binary = tool("datasette") + hello = relative("hello.py") + + cmd = (binary, hello) + r = run(cmd, check=True, timeout=30, stdout=PIPE, text=True) + + assert 0 == r.returncode + assert "Hello!" == r.stdout + + +def test_command(tool: Tool) -> None: + binary = tool("datasette") + + cmd = ( + binary, + "-c", + "print('Hello!', end='')", + ) + r = run(cmd, check=True, timeout=30, stdout=PIPE, text=True) + + assert 0 == r.returncode + assert "Hello!" == r.stdout -- GitLab