Skip to content

Commit

Permalink
Fix tests to run on python3.9
Browse files Browse the repository at this point in the history
staticmethods are not directly callable in python < 3.10:
python/cpython#87848

Signed-off-by: Adam Cmiel <[email protected]>
  • Loading branch information
chmeliik committed Oct 25, 2022
1 parent e2925aa commit 3398b19
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 3398b19

Please sign in to comment.