File: core.py

package info (click to toggle)
python-pbcommand 2.1.1%2Bgit20231020.28d1635-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,016 kB
  • sloc: python: 7,676; makefile: 220; sh: 73
file content (34 lines) | stat: -rw-r--r-- 1,016 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import logging
import os
import subprocess
import tempfile

from .base_utils import (HAS_PBCORE,
                         pbcore_skip_msg,
                         get_temp_file,
                         get_temp_dir)

log = logging.getLogger(__name__)


class PbIntegrationBase:

    def setup_method(self, method):
        self._cwd = os.getcwd()
        self._tmp_dir = tempfile.mkdtemp()
        os.chdir(self._tmp_dir)

    def teardown_method(self, method):
        os.chdir(self._cwd)

    def _check_call(self, args):
        log.info("Writing logs to subprocess.std* in %s", self._tmp_dir)
        with open("subprocess.stdout", "w") as stdout:
            with open("subprocess.stderr", "w") as stderr:
                try:
                    return subprocess.check_call(
                        args, stdout=stdout, stderr=stderr)
                except Exception as e:
                    log.error(e)
                    log.error("Console outputs are in %s", self._tmp_dir)
                    raise