]> git.openstreetmap.org Git - nominatim.git/blob - test/bdd/steps/utils.py
enable flake for bdd test code
[nominatim.git] / test / bdd / steps / utils.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2025 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Various smaller helps for step execution.
9 """
10 import logging
11 import subprocess
12
13 LOG = logging.getLogger(__name__)
14
15
16 def run_script(cmd, **kwargs):
17     """ Run the given command, check that it is successful and output
18         when necessary.
19     """
20     proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
21                             **kwargs)
22     (outp, outerr) = proc.communicate()
23     outp = outp.decode('utf-8')
24     outerr = outerr.decode('utf-8').replace('\\n', '\n')
25     LOG.debug("Run command: %s\n%s\n%s", cmd, outp, outerr)
26
27     assert proc.returncode == 0, "Script '{}' failed:\n{}\n{}\n".format(cmd[0], outp, outerr)
28
29     return outp, outerr