File: test_engine_runner.py

package info (click to toggle)
python-pbcommand 0.2.17-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 556 kB
  • sloc: python: 3,451; makefile: 200
file content (31 lines) | stat: -rw-r--r-- 992 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
import logging
import unittest

from pbcommand.engine import run_cmd

from .base_utils import get_temp_file, get_temp_dir

log = logging.getLogger(__name__)


class RunnerSmokeTest(unittest.TestCase):

    def test_simple_run_cmd(self):
        d = get_temp_dir("simple-cmd")
        txt_in = get_temp_file(".txt", d)
        txt_out = get_temp_file("*.txt", d)
        exe = "cat {i} > {o}".format(i=txt_in, o=txt_out)

        # this could all be bundled into a context manager
        # with RunCommand('/path/stdout', '/path/to/stderr') as r:
        #   r.exe("echo 'exe1')
        #   r.exe("echo 'exe2')
        #   result = r.get_result() # close the file handles
        stdout = get_temp_file("-stdout", d)
        stderr = get_temp_file("-stderr", d)
        with open(stdout, 'w') as fo:
            with open(stderr, 'w') as fe:
                result = run_cmd(exe, fo, fe)

        emgs = "Command {e} failed".format(e=exe)
        self.assertEquals(result.exit_code, 0, emgs)