]> git.openstreetmap.org Git - nominatim.git/blob - test/bdd/steps/utils.py
Merge pull request #2799 from lonvia/fix-inclusions-with-extratags
[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) 2022 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 def run_script(cmd, **kwargs):
16     """ Run the given command, check that it is successful and output
17         when necessary.
18     """
19     proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
20                             **kwargs)
21     (outp, outerr) = proc.communicate()
22     outp = outp.decode('utf-8')
23     outerr = outerr.decode('utf-8').replace('\\n', '\n')
24     LOG.debug("Run command: %s\n%s\n%s", cmd, outp, outerr)
25
26     assert proc.returncode == 0, "Script '{}' failed:\n{}\n{}\n".format(cmd[0], outp, outerr)
27
28     return outp, outerr