From 2a14a7f0e619b78353cb006488d8e6b8f20fe01c Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Tue, 4 Feb 2025 16:18:28 +0000 Subject: [PATCH 1/5] test: rename `binary.diff{,erence}` It conflicts with `pytest` files within `binary/diff` directory. Adds the convenience `from binary import Diff, Relative, Tool` imports --- e2e/binary/BUILD.bazel | 3 ++- e2e/binary/__init__.py | 7 +++++++ e2e/binary/b2sum/digest.py | 4 +--- e2e/binary/brotli/roundtrip.py | 4 +--- e2e/binary/bzip2/roundtrip.py | 4 +--- e2e/binary/conftest.py | 6 ++++-- e2e/binary/{diff.py => difference.py} | 0 e2e/binary/gzip/roundtrip.py | 4 +--- e2e/binary/pigz/roundtrip.py | 4 +--- e2e/binary/xz/roundtrip.py | 4 +--- e2e/binary/zstd/roundtrip.py | 4 +--- 11 files changed, 20 insertions(+), 24 deletions(-) create mode 100644 e2e/binary/__init__.py rename e2e/binary/{diff.py => difference.py} (100%) diff --git a/e2e/binary/BUILD.bazel b/e2e/binary/BUILD.bazel index 12a2bf99..ede035ea 100644 --- a/e2e/binary/BUILD.bazel +++ b/e2e/binary/BUILD.bazel @@ -12,8 +12,9 @@ build_test( py_library( name = "pytest", srcs = [ + "__init__.py", "conftest.py", - "diff.py", + "difference.py", "relative.py", "runfile.py", "tool.py", diff --git a/e2e/binary/__init__.py b/e2e/binary/__init__.py new file mode 100644 index 00000000..f79c1894 --- /dev/null +++ b/e2e/binary/__init__.py @@ -0,0 +1,7 @@ +from __future__ import annotations + +from binary.difference import Diff +from binary.relative import Relative +from binary.tool import Tool + +__all__ = ("Diff", "Tool", "Relative") diff --git a/e2e/binary/b2sum/digest.py b/e2e/binary/b2sum/digest.py index 987f41f8..bfe47245 100644 --- a/e2e/binary/b2sum/digest.py +++ b/e2e/binary/b2sum/digest.py @@ -3,9 +3,7 @@ from __future__ import annotations from pathlib import Path from subprocess import run -from binary.diff import Diff -from binary.relative import Relative -from binary.tool import Tool +from binary import Diff, Relative, Tool def test_digest(tool: Tool, relative: Relative, tmp_path: Path) -> None: diff --git a/e2e/binary/brotli/roundtrip.py b/e2e/binary/brotli/roundtrip.py index af04d8fb..e9f67d19 100644 --- a/e2e/binary/brotli/roundtrip.py +++ b/e2e/binary/brotli/roundtrip.py @@ -4,9 +4,7 @@ from pathlib import Path from shutil import copyfileobj from subprocess import PIPE, Popen -from binary.diff import Diff -from binary.relative import Relative -from binary.tool import Tool +from binary import Diff, Relative, Tool def test_roundtrip(tool: Tool, relative: Relative, tmp_path: Path) -> None: diff --git a/e2e/binary/bzip2/roundtrip.py b/e2e/binary/bzip2/roundtrip.py index f2feaa65..5ef47ea5 100644 --- a/e2e/binary/bzip2/roundtrip.py +++ b/e2e/binary/bzip2/roundtrip.py @@ -4,9 +4,7 @@ from pathlib import Path from shutil import copyfileobj from subprocess import PIPE, Popen -from binary.diff import Diff -from binary.relative import Relative -from binary.tool import Tool +from binary import Diff, Relative, Tool def test_roundtrip(tool: Tool, relative: Relative, tmp_path: Path) -> None: diff --git a/e2e/binary/conftest.py b/e2e/binary/conftest.py index 4c98c8bc..f85f9f59 100644 --- a/e2e/binary/conftest.py +++ b/e2e/binary/conftest.py @@ -2,12 +2,14 @@ from __future__ import annotations from pytest import fixture -from .diff import Diff -from .diff import repr as diff +from .difference import Diff +from .difference import repr as diff from .relative import Relative from .runfile import Runfile, SupportsRlocation, create from .tool import Tool +__all__ = ("Diff", "Relative", "Tool", "Runfile") + @fixture def runfiles() -> SupportsRlocation: diff --git a/e2e/binary/diff.py b/e2e/binary/difference.py similarity index 100% rename from e2e/binary/diff.py rename to e2e/binary/difference.py diff --git a/e2e/binary/gzip/roundtrip.py b/e2e/binary/gzip/roundtrip.py index 68a3d112..3e83ebb5 100644 --- a/e2e/binary/gzip/roundtrip.py +++ b/e2e/binary/gzip/roundtrip.py @@ -4,9 +4,7 @@ from pathlib import Path from shutil import copyfileobj from subprocess import PIPE, Popen -from binary.diff import Diff -from binary.relative import Relative -from binary.tool import Tool +from binary import Diff, Relative, Tool def test_roundtrip(tool: Tool, relative: Relative, tmp_path: Path) -> None: diff --git a/e2e/binary/pigz/roundtrip.py b/e2e/binary/pigz/roundtrip.py index af06be6a..a1ee0d78 100644 --- a/e2e/binary/pigz/roundtrip.py +++ b/e2e/binary/pigz/roundtrip.py @@ -4,9 +4,7 @@ from pathlib import Path from shutil import copyfileobj from subprocess import PIPE, Popen -from binary.diff import Diff -from binary.relative import Relative -from binary.tool import Tool +from binary import Diff, Relative, Tool def test_roundtrip(tool: Tool, relative: Relative, tmp_path: Path) -> None: diff --git a/e2e/binary/xz/roundtrip.py b/e2e/binary/xz/roundtrip.py index dc768863..f2c3cda2 100644 --- a/e2e/binary/xz/roundtrip.py +++ b/e2e/binary/xz/roundtrip.py @@ -4,9 +4,7 @@ from pathlib import Path from shutil import copyfileobj from subprocess import PIPE, Popen -from binary.diff import Diff -from binary.relative import Relative -from binary.tool import Tool +from binary import Diff, Relative, Tool def test_roundtrip(tool: Tool, relative: Relative, tmp_path: Path) -> None: diff --git a/e2e/binary/zstd/roundtrip.py b/e2e/binary/zstd/roundtrip.py index 71d2b3e8..3d633609 100644 --- a/e2e/binary/zstd/roundtrip.py +++ b/e2e/binary/zstd/roundtrip.py @@ -4,9 +4,7 @@ from pathlib import Path from shutil import copyfileobj from subprocess import PIPE, Popen -from binary.diff import Diff -from binary.relative import Relative -from binary.tool import Tool +from binary import Diff, Relative, Tool def test_roundtrip(tool: Tool, relative: Relative, tmp_path: Path) -> None: -- GitLab From 8c55c72ebddf1099b0499f5d27177c48dba65cad Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Tue, 4 Feb 2025 16:18:43 +0000 Subject: [PATCH 2/5] test(diff): add version and unified test --- e2e/binary/diff/BUILD.bazel | 34 ++++++++++++++++++++++++++++------ e2e/binary/diff/a.txt | 5 +++++ e2e/binary/diff/b.txt | 8 ++++++++ e2e/binary/diff/expected.txt | 11 +++++++++++ e2e/binary/diff/normal.py | 23 +++++++++++++++++++++++ 5 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/diff/a.txt create mode 100644 e2e/binary/diff/b.txt create mode 100644 e2e/binary/diff/expected.txt create mode 100644 e2e/binary/diff/normal.py diff --git a/e2e/binary/diff/BUILD.bazel b/e2e/binary/diff/BUILD.bazel index a4d66069..45fa9b5c 100644 --- a/e2e/binary/diff/BUILD.bazel +++ b/e2e/binary/diff/BUILD.bazel @@ -1,11 +1,33 @@ -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 `diff` +py_pytest_test( + name = "normal", + size = "small", + srcs = ["normal.py"], + data = [ + "a.txt", + "b.txt", + "expected.txt", + "@ape//ape:diff", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "diff", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:diff"], + src = "@ape//ape:diff", + args = ["--version"], +) + +test_suite( + name = "diff", + tests = [ + ":normal", + ":version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/diff/a.txt b/e2e/binary/diff/a.txt new file mode 100644 index 00000000..d47fbf50 --- /dev/null +++ b/e2e/binary/diff/a.txt @@ -0,0 +1,5 @@ +Hello, world! + +This is some text. + +This is some other text. diff --git a/e2e/binary/diff/b.txt b/e2e/binary/diff/b.txt new file mode 100644 index 00000000..00a57ad5 --- /dev/null +++ b/e2e/binary/diff/b.txt @@ -0,0 +1,8 @@ +Hello, world? + +This is text. + + +This is some text. + +This is more text. diff --git a/e2e/binary/diff/expected.txt b/e2e/binary/diff/expected.txt new file mode 100644 index 00000000..cb9c196e --- /dev/null +++ b/e2e/binary/diff/expected.txt @@ -0,0 +1,11 @@ +1c1,4 +< Hello, world! +--- +> Hello, world? +> +> This is text. +> +5c8 +< This is some other text. +--- +> This is more text. diff --git a/e2e/binary/diff/normal.py b/e2e/binary/diff/normal.py new file mode 100644 index 00000000..cb9a9931 --- /dev/null +++ b/e2e/binary/diff/normal.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run +from tarfile import REGTYPE, TarFile + +from binary import Diff, Relative, Tool + + +def test_normal(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("diff") + a = relative("a.txt") + b = relative("b.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, str(a), str(b)) + with open(output, "w", encoding="utf-8") as stream: + result = run(cmd, timeout=30, stdout=stream) + assert 1 == result.returncode + + with open(expected) as a, open(output) as b: + assert a.read() == b.read() -- GitLab From 89afc6336c38a7112816d3ba4cee441d6f73f7c0 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Tue, 4 Feb 2025 16:27:16 +0000 Subject: [PATCH 3/5] test(diff3): add version and threeway test --- e2e/binary/diff3/BUILD.bazel | 36 +++++++++++++++++++++++++++++------ e2e/binary/diff3/a.txt | 5 +++++ e2e/binary/diff3/b.txt | 8 ++++++++ e2e/binary/diff3/c.txt | 5 +++++ e2e/binary/diff3/expected.txt | 23 ++++++++++++++++++++++ e2e/binary/diff3/threeway.py | 24 +++++++++++++++++++++++ 6 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/diff3/a.txt create mode 100644 e2e/binary/diff3/b.txt create mode 100644 e2e/binary/diff3/c.txt create mode 100644 e2e/binary/diff3/expected.txt create mode 100644 e2e/binary/diff3/threeway.py diff --git a/e2e/binary/diff3/BUILD.bazel b/e2e/binary/diff3/BUILD.bazel index 57ddfd71..26e6bf02 100644 --- a/e2e/binary/diff3/BUILD.bazel +++ b/e2e/binary/diff3/BUILD.bazel @@ -1,11 +1,35 @@ -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 `diff3` +py_pytest_test( + name = "threeway", + size = "small", + srcs = ["threeway.py"], + data = [ + "a.txt", + "b.txt", + "c.txt", + "expected.txt", + "@ape//ape:diff", + "@ape//ape:diff3", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "diff3", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:diff3"], + src = "@ape//ape:diff3", + args = ["--version"], +) + +test_suite( + name = "diff3", + tests = [ + ":threeway", + ":version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/diff3/a.txt b/e2e/binary/diff3/a.txt new file mode 100644 index 00000000..d47fbf50 --- /dev/null +++ b/e2e/binary/diff3/a.txt @@ -0,0 +1,5 @@ +Hello, world! + +This is some text. + +This is some other text. diff --git a/e2e/binary/diff3/b.txt b/e2e/binary/diff3/b.txt new file mode 100644 index 00000000..00a57ad5 --- /dev/null +++ b/e2e/binary/diff3/b.txt @@ -0,0 +1,8 @@ +Hello, world? + +This is text. + + +This is some text. + +This is more text. diff --git a/e2e/binary/diff3/c.txt b/e2e/binary/diff3/c.txt new file mode 100644 index 00000000..13a7ca44 --- /dev/null +++ b/e2e/binary/diff3/c.txt @@ -0,0 +1,5 @@ +Hello, Earth! + +This is some words. + +This is some other text. diff --git a/e2e/binary/diff3/expected.txt b/e2e/binary/diff3/expected.txt new file mode 100644 index 00000000..3d3ec2a1 --- /dev/null +++ b/e2e/binary/diff3/expected.txt @@ -0,0 +1,23 @@ +==== +1:1c + Hello, world! +2:1c + Hello, world? +3:1c + Hello, Earth! +==== +1:3c + This is some text. +2:3c + This is text. +3:3c + This is some words. +====2 +1:5c +3:5c + This is some other text. +2:5,8c + + This is some text. + + This is more text. diff --git a/e2e/binary/diff3/threeway.py b/e2e/binary/diff3/threeway.py new file mode 100644 index 00000000..252e1502 --- /dev/null +++ b/e2e/binary/diff3/threeway.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run +from tarfile import REGTYPE, TarFile + +from binary import Diff, Relative, Tool + + +def test_threeway(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("diff3") + diff = tool("diff") + a = relative("a.txt") + b = relative("b.txt") + c = relative("c.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, "--diff-program", str(diff), str(a), str(b), str(c)) + with open(output, "w", encoding="utf-8") as stream: + result = run(cmd, timeout=30, stdout=stream, check=True) + + with open(expected) as a, open(output) as b: + assert a.read() == b.read() -- GitLab From 9e6250dad14a8614d7f1bdd898232846af176d21 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Tue, 4 Feb 2025 16:32:01 +0000 Subject: [PATCH 4/5] test(sdiff): add version and diff test --- e2e/binary/sdiff/BUILD.bazel | 35 +++++++++++++++++++++++++++++------ e2e/binary/sdiff/a.txt | 5 +++++ e2e/binary/sdiff/b.txt | 8 ++++++++ e2e/binary/sdiff/diff.py | 24 ++++++++++++++++++++++++ e2e/binary/sdiff/expected.txt | 8 ++++++++ 5 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/sdiff/a.txt create mode 100644 e2e/binary/sdiff/b.txt create mode 100644 e2e/binary/sdiff/diff.py create mode 100644 e2e/binary/sdiff/expected.txt diff --git a/e2e/binary/sdiff/BUILD.bazel b/e2e/binary/sdiff/BUILD.bazel index b1760484..db219d12 100644 --- a/e2e/binary/sdiff/BUILD.bazel +++ b/e2e/binary/sdiff/BUILD.bazel @@ -1,11 +1,34 @@ -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 `sdiff` +py_pytest_test( + name = "diff", + size = "small", + srcs = ["diff.py"], + data = [ + "a.txt", + "b.txt", + "expected.txt", + "@ape//ape:diff", + "@ape//ape:sdiff", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "sdiff", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:sdiff"], + src = "@ape//ape:sdiff", + args = ["--version"], +) + +test_suite( + name = "sdiff", + tests = [ + ":diff", + ":version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/sdiff/a.txt b/e2e/binary/sdiff/a.txt new file mode 100644 index 00000000..d47fbf50 --- /dev/null +++ b/e2e/binary/sdiff/a.txt @@ -0,0 +1,5 @@ +Hello, world! + +This is some text. + +This is some other text. diff --git a/e2e/binary/sdiff/b.txt b/e2e/binary/sdiff/b.txt new file mode 100644 index 00000000..00a57ad5 --- /dev/null +++ b/e2e/binary/sdiff/b.txt @@ -0,0 +1,8 @@ +Hello, world? + +This is text. + + +This is some text. + +This is more text. diff --git a/e2e/binary/sdiff/diff.py b/e2e/binary/sdiff/diff.py new file mode 100644 index 00000000..0402883f --- /dev/null +++ b/e2e/binary/sdiff/diff.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run +from tarfile import REGTYPE, TarFile + +from binary import Diff, Relative, Tool + + +def test_diff(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("sdiff") + diff = tool("diff") + a = relative("a.txt") + b = relative("b.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, f"--diff-program={diff}", "--width=80", str(a), str(b)) + with open(output, "w", encoding="utf-8") as stream: + result = run(cmd, timeout=30, stdout=stream) + assert 1 == result.returncode + + with open(expected) as a, open(output) as b: + assert a.read() == b.read() diff --git a/e2e/binary/sdiff/expected.txt b/e2e/binary/sdiff/expected.txt new file mode 100644 index 00000000..47e69649 --- /dev/null +++ b/e2e/binary/sdiff/expected.txt @@ -0,0 +1,8 @@ +Hello, world! | Hello, world? + > + > This is text. + > + +This is some text. This is some text. + +This is some other text. | This is more text. -- GitLab From 1f2050341fa44b1ee527f0b46efd1d8e7cbe5d53 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Tue, 4 Feb 2025 16:52:43 +0000 Subject: [PATCH 5/5] test(cmp): add version and text comparison test --- e2e/binary/cmp/BUILD.bazel | 34 ++++++++++++++++++++++++++++------ e2e/binary/cmp/a.txt | 5 +++++ e2e/binary/cmp/b.txt | 8 ++++++++ e2e/binary/cmp/expected.txt | 1 + e2e/binary/cmp/text.py | 23 +++++++++++++++++++++++ 5 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/cmp/a.txt create mode 100644 e2e/binary/cmp/b.txt create mode 100644 e2e/binary/cmp/expected.txt create mode 100644 e2e/binary/cmp/text.py diff --git a/e2e/binary/cmp/BUILD.bazel b/e2e/binary/cmp/BUILD.bazel index 02947c53..5e657eae 100644 --- a/e2e/binary/cmp/BUILD.bazel +++ b/e2e/binary/cmp/BUILD.bazel @@ -1,11 +1,33 @@ -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 `cmp` +py_pytest_test( + name = "text", + size = "small", + srcs = ["text.py"], + data = [ + "a.txt", + "b.txt", + "expected.txt", + "@ape//ape:cmp", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "cmp", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:cmp"], + src = "@ape//ape:cmp", + args = ["--version"], +) + +test_suite( + name = "cmp", + tests = [ + ":text", + ":version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/cmp/a.txt b/e2e/binary/cmp/a.txt new file mode 100644 index 00000000..d47fbf50 --- /dev/null +++ b/e2e/binary/cmp/a.txt @@ -0,0 +1,5 @@ +Hello, world! + +This is some text. + +This is some other text. diff --git a/e2e/binary/cmp/b.txt b/e2e/binary/cmp/b.txt new file mode 100644 index 00000000..00a57ad5 --- /dev/null +++ b/e2e/binary/cmp/b.txt @@ -0,0 +1,8 @@ +Hello, world? + +This is text. + + +This is some text. + +This is more text. diff --git a/e2e/binary/cmp/expected.txt b/e2e/binary/cmp/expected.txt new file mode 100644 index 00000000..7c963faf --- /dev/null +++ b/e2e/binary/cmp/expected.txt @@ -0,0 +1 @@ +binary/cmp/a.txt binary/cmp/b.txt differ: char 13, line 1 diff --git a/e2e/binary/cmp/text.py b/e2e/binary/cmp/text.py new file mode 100644 index 00000000..fe9e7b81 --- /dev/null +++ b/e2e/binary/cmp/text.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run +from tarfile import REGTYPE, TarFile + +from binary import Diff, Relative, Tool + + +def test_normal(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("cmp") + a = relative("a.txt") + b = relative("b.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, str(a), str(b)) + with open(output, "w", encoding="utf-8") as stream: + result = run(cmd, timeout=30, stdout=stream) + assert 1 == result.returncode + + with open(expected) as a, open(output) as b: + assert a.read() == b.read() -- GitLab