From 24f0cac1215b0033d94bafce2733398d7bf05f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Nowacki?= Date: Wed, 25 Oct 2023 12:04:46 +0200 Subject: [PATCH] fix pypy integration tests --- CHANGELOG.md | 1 + test/integration/helpers.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48c3dcfed..19c3069c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed * `--quiet` now will implicitly set `--noProgress` option as well +* pypy integration tests ## [3.11.0] - 2023-10-04 diff --git a/test/integration/helpers.py b/test/integration/helpers.py index 8195116b0..61a55e22d 100644 --- a/test/integration/helpers.py +++ b/test/integration/helpers.py @@ -442,6 +442,12 @@ def should_succeed( assert any(p.match(line) for p in self.EXPECTED_STDERR_PATTERNS), \ f'Unexpected stderr line: {repr(line)}' + if platform.python_implementation().lower() == 'pypy': + # TODO: remove after pypy removes the leftover print and resolve + # https://github.com/Backblaze/B2_Command_Line_Tool/issues/936 + while stdout.startswith('/'): + stdout = stdout.split('\n', 1)[-1] + if expected_pattern is not None: assert re.search(expected_pattern, stdout), \ f'did not match pattern="{expected_pattern}", stdout="{stdout}"' @@ -454,7 +460,12 @@ def should_succeed_json(self, args, additional_env: Optional[dict] = None): if there was an error; otherwise, treats the stdout as JSON and returns the data in it. """ - return json.loads(self.should_succeed(args, additional_env=additional_env)) + result = self.should_succeed(args, additional_env=additional_env) + try: + loaded_result = json.loads(result) + except json.JSONDecodeError: + raise ValueError(f'{result} is not a valid json') + return loaded_result def should_fail(self, args, expected_pattern, additional_env: Optional[dict] = None): """ @@ -464,6 +475,12 @@ def should_fail(self, args, expected_pattern, additional_env: Optional[dict] = N status, stdout, stderr = run_command(self.command, args, additional_env) assert status != 0, 'ERROR: should have failed' + if platform.python_implementation().lower() == 'pypy': + # TODO: remove after pypy removes the leftover print and resolve + # https://github.com/Backblaze/B2_Command_Line_Tool/issues/936 + while stdout.startswith('/'): + stdout = stdout.split('\n', 1)[-1] + assert re.search(expected_pattern, stdout + stderr), \ f'did not match pattern="{expected_pattern}", stdout="{stdout}", stderr="{stderr}"'