From 3398b195fcf99439de14851205ca562e93439f80 Mon Sep 17 00:00:00 2001 From: Adam Cmiel Date: Mon, 24 Oct 2022 16:46:52 +0200 Subject: [PATCH] Fix tests to run on python3.9 staticmethods are not directly callable in python < 3.10: https://github.com/python/cpython/issues/87848 Signed-off-by: Adam Cmiel --- tests/unit/test_cli.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index 8dc220fc7..70ed5c43c 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -381,27 +381,27 @@ def test_write_json_output(self, request_output: RequestOutput, tmp_cwd: Path): assert written_output == request_output +def env_file_as_json(for_output_dir: Path) -> str: + gocache = f'{{"name": "GOCACHE", "value": "{for_output_dir}/deps/gomod"}}' + gosumdb = '{"name": "GOSUMDB", "value": "off"}' + return f"[{gocache}, {gosumdb}]\n" + + +def env_file_as_env(for_output_dir: Path) -> str: + return dedent( + f""" + export GOCACHE={for_output_dir}/deps/gomod + export GOSUMDB=off + """ + ).lstrip() + + class TestGenerateEnv: ENV_VARS = [ {"name": "GOCACHE", "value": "deps/gomod", "kind": "path"}, {"name": "GOSUMDB", "value": "off", "kind": "literal"}, ] - @staticmethod - def env_file_as_json(for_output_dir: Path) -> str: - gocache = f'{{"name": "GOCACHE", "value": "{for_output_dir}/deps/gomod"}}' - gosumdb = '{"name": "GOSUMDB", "value": "off"}' - return f"[{gocache}, {gosumdb}]\n" - - @staticmethod - def env_file_as_env(for_output_dir: Path) -> str: - return dedent( - f""" - export GOCACHE={for_output_dir}/deps/gomod - export GOSUMDB=off - """ - ).lstrip() - @pytest.fixture def tmp_cwd_as_output_dir(self, tmp_cwd: Path) -> Path: """Change working directory to a tmpdir and write output.json into it.""" @@ -463,9 +463,9 @@ def test_generate_for_different_output_dir( resolved_output_dir = Path(expect_output_dir.format(cwd=tmp_cwd_as_output_dir)) if fmt == "env": - expect_output = self.env_file_as_env(resolved_output_dir) + expect_output = env_file_as_env(resolved_output_dir) else: - expect_output = self.env_file_as_json(resolved_output_dir) + expect_output = env_file_as_json(resolved_output_dir) assert result.stdout == expect_output