From 00226da59e220094f6cf8aab65f9b731cf742eab Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 25 May 2023 09:46:53 +1000 Subject: [PATCH] scanner: add tests for the extra data arguments Fixed in !218, let's test this so we don't break it again. --- .gitlab-ci.yml | 8 ++++---- .gitlab-ci/config.yml | 4 +++- test/test_scanner.py | 42 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 51bc909..e94ed8c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -38,9 +38,9 @@ variables: # See the documentation here: # # https://wayland.freedesktop.org/libinput/doc/latest/building_libinput.html # ############################################################################### - FEDORA_PACKAGES: 'git diffutils gcc gcc-c++ pkgconf-pkg-config systemd-devel libxkbcommon-devel libxml2 doxygen python3-attrs python3-pytest python3-dbusmock python3-jinja2 python3-pip hugo libabigail ' + FEDORA_PACKAGES: 'git diffutils gcc gcc-c++ pkgconf-pkg-config systemd-devel libxkbcommon-devel libxml2 doxygen python3-attrs python3-pytest python3-dbusmock python3-jinja2 python3-pip python3-pyyaml hugo libabigail ' FEDORA_PIP_PACKAGES: 'meson ninja structlog strenum ' - DEBIAN_PACKAGES: 'git gcc g++ pkg-config libsystemd-dev libxkbcommon-dev libxml2 doxygen python3-attr python3-pytest python3-dbusmock python3-jinja2 python3-pip ' + DEBIAN_PACKAGES: 'git gcc g++ pkg-config libsystemd-dev libxkbcommon-dev libxml2 doxygen python3-attr python3-pytest python3-dbusmock python3-jinja2 python3-pip python3-yaml ' DEBIAN_PIP_PACKAGES: 'meson ninja structlog strenum ' ############################ end of package lists ############################# @@ -48,8 +48,8 @@ variables: # changing these will force rebuilding the associated image # Note: these tags have no meaning and are not tied to a particular # libinput version - FEDORA_TAG: '2023-05-18.3' - DEBIAN_TAG: '2023-05-18.3' + FEDORA_TAG: '2023-05-25.0' + DEBIAN_TAG: '2023-05-25.0' FDO_UPSTREAM_REPO: libinput/libei diff --git a/.gitlab-ci/config.yml b/.gitlab-ci/config.yml index 1d75964..44171a7 100644 --- a/.gitlab-ci/config.yml +++ b/.gitlab-ci/config.yml @@ -3,7 +3,7 @@ # # We're happy to rebuild all containers when one changes. -.default_tag: &default_tag '2023-05-18.3' +.default_tag: &default_tag '2023-05-25.0' last_abi_break: 0.99.1 minimum_meson_version: 0.56.0 @@ -29,6 +29,7 @@ distributions: - python3-dbusmock - python3-jinja2 - python3-pip + - python3-pyyaml - hugo # for documentation only - libabigail # for abidiff only pips: @@ -54,6 +55,7 @@ distributions: - python3-dbusmock - python3-jinja2 - python3-pip + - python3-yaml pips: - meson - ninja diff --git a/test/test_scanner.py b/test/test_scanner.py index 588664f..cde1f01 100644 --- a/test/test_scanner.py +++ b/test/test_scanner.py @@ -6,7 +6,7 @@ import pytest try: - from eiscanner import parse, Protocol + from eiscanner import parse, scanner, Protocol except ImportError: print("Run tests from within the build directory") pytest.skip(allow_module_level=True) @@ -44,3 +44,43 @@ class TestScanner: assert "handshake" in [i.plainname for i in protocol.interfaces] assert "connection" in [i.plainname for i in protocol.interfaces] assert "button" in [i.plainname for i in protocol.interfaces] + + @pytest.mark.parametrize("method", ("yamlfile", "jsonfile", "string")) + def test_cli_extra_data(self, tmp_path, method): + result_path = tmp_path / "result" + tmpl_path = tmp_path / "template" + with open(tmpl_path, "w") as template: + template.write(">{{extra.foo}}<") + + if method == "yamlfile": + extra_path = tmp_path / "extra_data.yml" + with open(extra_path, "w") as extra_data: + extra_data.write("foo: 'yes'") + extra_data_arg = f"--jinja-extra-data-file={extra_path}" + elif method == "jsonfile": + extra_path = tmp_path / "extra_data.json" + with open(extra_path, "w") as extra_data: + extra_data.write('{"foo": "yes"}') + extra_data_arg = f"--jinja-extra-data-file={extra_path}" + elif method == "string": + extra_data = '{"foo": "yes"}' + extra_data_arg = f"--jinja-extra-data={extra_data}" + else: + pytest.fail(f"Unsupported method {method}") + + try: + scanner( + [ + f"--output={result_path}", + extra_data_arg, + protofile, + str(tmpl_path), + ] + ) + except SystemExit as e: + pytest.fail(reason=f"Unexpected system exit code {e}") + + assert result_path.exists() + with open(result_path) as fd: + result = fd.read() + assert result == ">yes<"