diff options
author | Robert Collins <rbtcollins@hp.com> | 2014-03-13 17:34:51 +1300 |
---|---|---|
committer | Robert Collins <rbtcollins@hp.com> | 2014-03-13 18:02:45 +1300 |
commit | 6ffff7c95706e3a39e82fa0362e825aab21cbb26 (patch) | |
tree | 54286de581ce7b3622c320bc09020d5a90166c82 | |
parent | 9fdd06fcbb646861ff6c79107d9e7aa803b2f9d3 (diff) | |
download | pbr-6ffff7c95706e3a39e82fa0362e825aab21cbb26.tar.gz |
Factor run_cmd out of the base class.0.7.0
I want to reuse this for factoring out some fixtures, so make it
reusable.
Change-Id: I7035a514adf889a8ebaadff9ae873341804fe099
-rw-r--r-- | pbr/tests/base.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/pbr/tests/base.py b/pbr/tests/base.py index 778b026..f18dadc 100644 --- a/pbr/tests/base.py +++ b/pbr/tests/base.py @@ -122,12 +122,19 @@ class BaseTestCase(testtools.TestCase, testresources.ResourcedTestCase): working copy--returns the stdout and stderr streams and the exit code from the subprocess. """ + return _run_cmd([cmd] + list(args), cwd=self.package_dir) - os.chdir(self.package_dir) - p = subprocess.Popen([cmd] + list(args), stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - streams = tuple(s.decode('latin1').strip() for s in p.communicate()) - for line in streams: - print(line) - return (streams) + (p.returncode,) +def _run_cmd(args, cwd): + """Run the command args in cwd. + + :param args: The command to run e.g. ['git', 'status'] + :param cwd: The directory to run the comamnd in. + :return: ((stdout, stderr), returncode) + """ + p = subprocess.Popen( + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd) + streams = tuple(s.decode('latin1').strip() for s in p.communicate()) + for content in streams: + print(content) + return (streams) + (p.returncode,) |