| 1 | import logging |
| 2 | import os |
| 3 | import subprocess |
| 4 | import tempfile |
| 5 | |
| 6 | from .base_utils import (HAS_PBCORE, |
| 7 | pbcore_skip_msg, |
| 8 | get_temp_file, |
| 9 | get_temp_dir) |
| 10 | |
| 11 | log = logging.getLogger(__name__) |
| 12 | |
| 13 | |
| 14 | class PbIntegrationBase: |
| 15 | |
| 16 | def setup_method(self, method): |
| 17 | self._cwd = os.getcwd() |
| 18 | self._tmp_dir = tempfile.mkdtemp() |
| 19 | os.chdir(self._tmp_dir) |
| 20 | |
| 21 | def teardown_method(self, method): |
| 22 | os.chdir(self._cwd) |
| 23 | |
| 24 | def _check_call(self, args): |
| 25 | log.info("Writing logs to subprocess.std* in %s", self._tmp_dir) |
| 26 | with open("subprocess.stdout", "w") as stdout: |
| 27 | with open("subprocess.stderr", "w") as stderr: |
| 28 | try: |
| 29 | return subprocess.check_call( |
| 30 | args, stdout=stdout, stderr=stderr) |
| 31 | except Exception as e: |
| 32 | log.error(e) |
| 33 | log.error("Console outputs are in %s", self._tmp_dir) |
| 34 | raise |