From 29500e6e618a1b0fc252177ea740ae87e59a82e1 Mon Sep 17 00:00:00 2001 From: Luke Hackwell Date: Tue, 11 Mar 2025 16:22:47 +0000 Subject: [PATCH] test(zip): add native and pytest tests --- e2e/binary/zip/BUILD.bazel | 32 ++++++++++++++++++++++++++------ e2e/binary/zip/fixture.txt | 1 + e2e/binary/zip/zip.py | 22 ++++++++++++++++++++++ 3 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/zip/fixture.txt create mode 100644 e2e/binary/zip/zip.py diff --git a/e2e/binary/zip/BUILD.bazel b/e2e/binary/zip/BUILD.bazel index ce603aa7..11b8352f 100644 --- a/e2e/binary/zip/BUILD.bazel +++ b/e2e/binary/zip/BUILD.bazel @@ -1,11 +1,31 @@ -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 `zip` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["zip.py"], + data = [ + "fixture.txt", + "@ape//ape:zip", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "zip", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:zip"], + src = "@ape//ape:zip", + args = ["--version"], +) + +test_suite( + name = "zip", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/zip/fixture.txt b/e2e/binary/zip/fixture.txt new file mode 100644 index 00000000..ce013625 --- /dev/null +++ b/e2e/binary/zip/fixture.txt @@ -0,0 +1 @@ +hello diff --git a/e2e/binary/zip/zip.py b/e2e/binary/zip/zip.py new file mode 100644 index 00000000..963e1943 --- /dev/null +++ b/e2e/binary/zip/zip.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run +import zipfile + +from binary import Diff, Relative, Tool + + +def test_zip(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("zip") + fixture = relative("fixture.txt") + zipped = tmp_path / "output.zip" + unzipped = tmp_path / "fixture.txt" + + cmd = (binary, "-j", zipped, fixture) + run(cmd, check=True, timeout=30,) + + with zipfile.ZipFile(zipped, "r") as zip: + zip.extractall(tmp_path) + + assert Diff(fixture) == Diff(unzipped) -- GitLab