From 73fc3d44b9cf63cf6de82d5ccd09563ce54152e8 Mon Sep 17 00:00:00 2001 From: Luke Hackwell Date: Thu, 27 Feb 2025 16:25:06 +0000 Subject: [PATCH] test(sum): add native and pytest tests --- e2e/binary/sum/BUILD.bazel | 31 +++++++++++++++++++++++++------ e2e/binary/sum/sum.py | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/sum/sum.py diff --git a/e2e/binary/sum/BUILD.bazel b/e2e/binary/sum/BUILD.bazel index 60c1d1fa..cf42fdae 100644 --- a/e2e/binary/sum/BUILD.bazel +++ b/e2e/binary/sum/BUILD.bazel @@ -1,11 +1,30 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") -# TODO: write an _actual_ test for `sum` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["sum.py"], + data = [ + "@ape//ape:sum", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "sum", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:sum"], + src = "@ape//ape:sum", + args = ["--version"], +) + +test_suite( + name = "sum", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/sum/sum.py b/e2e/binary/sum/sum.py new file mode 100644 index 00000000..9264550b --- /dev/null +++ b/e2e/binary/sum/sum.py @@ -0,0 +1,21 @@ +from __future__ import annotations + +from subprocess import run +from pathlib import Path + +from binary.tool import Tool + + +def test_sum(tool: Tool, tmp_path: Path) -> None: + binary = tool("sum") + input_path = tmp_path / "input_file" + + with open(input_path, "w") as file: + file.write("hello") + cmd = (binary, input_path) + result = run(cmd, check=True, timeout=30, capture_output=True, text=True) + + # Remove path from output + actual = result.stdout.rsplit(" ", 1)[0] + expected = "08403 1" + assert actual == expected -- GitLab