From 1bc97abfe574e1771f79ae46c7ea9e5158b7cbfe Mon Sep 17 00:00:00 2001 From: Luke Hackwell Date: Tue, 11 Mar 2025 17:02:39 +0000 Subject: [PATCH] test(unzip): add native and pytest tests --- e2e/binary/unzip/BUILD.bazel | 32 ++++++++++++++++++++++++++------ e2e/binary/unzip/fixture.txt | 1 + e2e/binary/unzip/unzip.py | 22 ++++++++++++++++++++++ 3 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/unzip/fixture.txt create mode 100644 e2e/binary/unzip/unzip.py diff --git a/e2e/binary/unzip/BUILD.bazel b/e2e/binary/unzip/BUILD.bazel index d88b69fc..09df8a35 100644 --- a/e2e/binary/unzip/BUILD.bazel +++ b/e2e/binary/unzip/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 `unzip` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["unzip.py"], + data = [ + "fixture.txt", + "@ape//ape:unzip", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "unzip", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:unzip"], + src = "@ape//ape:unzip", + args = ["-v"], +) + +test_suite( + name = "unzip", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/unzip/fixture.txt b/e2e/binary/unzip/fixture.txt new file mode 100644 index 00000000..ce013625 --- /dev/null +++ b/e2e/binary/unzip/fixture.txt @@ -0,0 +1 @@ +hello diff --git a/e2e/binary/unzip/unzip.py b/e2e/binary/unzip/unzip.py new file mode 100644 index 00000000..83e4f4cc --- /dev/null +++ b/e2e/binary/unzip/unzip.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_unzip(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("unzip") + fixture = relative("fixture.txt") + zipped = tmp_path / "output.zip" + unzipped = tmp_path / "fixture.txt" + + with zipfile.ZipFile(zipped, "w") as zip: + zip.write(fixture, arcname=fixture.name) + + cmd = (binary, zipped, "-d", tmp_path) + run(cmd, check=True, timeout=30,) + + assert Diff(fixture) == Diff(unzipped) -- GitLab