diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-06-15 11:09:58 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-06-15 11:09:58 +0200 |
commit | 22c722bf59e59246f47491c7229b17f9ef783614 (patch) | |
tree | bdcfbfae93f5e54d9b2b39465945419406b5e96a /tests/helpers.py | |
parent | 6bc04f8097e44e55cbf543d811ccd90671faedbc (diff) | |
download | hydrilla-builder-22c722bf59e59246f47491c7229b17f9ef783614.tar.gz hydrilla-builder-22c722bf59e59246f47491c7229b17f9ef783614.zip |
New upstream version 1.1~beta1upstream/1.1_beta1debian-upstream
Diffstat (limited to 'tests/helpers.py')
-rw-r--r-- | tests/helpers.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/helpers.py b/tests/helpers.py new file mode 100644 index 0000000..df474b0 --- /dev/null +++ b/tests/helpers.py @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: CC0-1.0 + +# Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org> +# +# Available under the terms of Creative Commons Zero v1.0 Universal. + +import re + +variable_word_re = re.compile(r'^<(.+)>$') + +def process_command(command, expected_command): + """Validate the command line and extract its variable parts (if any).""" + assert len(command) == len(expected_command) + + extracted = {} + for word, expected_word in zip(command, expected_command): + match = variable_word_re.match(expected_word) + if match: + extracted[match.group(1)] = word + else: + assert word == expected_word + + return extracted + +def run_missing_executable(command, **kwargs): + """ + Instead of running a command, raise FileNotFoundError as if its executable + was missing. + """ + raise FileNotFoundError('dummy') + +class MockedCompletedProcess: + """ + Object with some fields similar to those of subprocess.CompletedProcess. + """ + def __init__(self, args, returncode=0, + stdout='some output', stderr='some error output', + text_output=True): + """ + Initialize MockedCompletedProcess. Convert strings to bytes if needed. + """ + self.args = args + self.returncode = returncode + + if type(stdout) is str and not text_output: + stdout = stdout.encode() + if type(stderr) is str and not text_output: + stderr = stderr.encode() + + self.stdout = stdout + self.stderr = stderr |