diff options
author | Gilbert Ramirez <gram@alumni.rice.edu> | 2013-09-18 05:07:46 +0000 |
---|---|---|
committer | Gilbert Ramirez <gram@alumni.rice.edu> | 2013-09-18 05:07:46 +0000 |
commit | 4797eafddb99fd85d98944c6ccce04ea391951a3 (patch) | |
tree | bb3e38489329a99f43c10ea4aa29aa80e313d0fc /tools/dftestlib/util.py | |
parent | ab7d8cc87dbac5cfdd23d93b7b336fb60ac790b3 (diff) | |
download | wireshark-4797eafddb99fd85d98944c6ccce04ea391951a3.tar.gz |
Update dfilter-test.py to use a much more modern test harness,
the "unittest" module that comes with Python. Specifically, this
takes advantage of a couple of features in the "unittest" in
Python 2.7. The tests are all the same as before, but much
better managed.
This is in preparation for some work on the display filter code.
svn path=/trunk/; revision=52136
Diffstat (limited to 'tools/dftestlib/util.py')
-rw-r--r-- | tools/dftestlib/util.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/dftestlib/util.py b/tools/dftestlib/util.py new file mode 100644 index 0000000000..7c66385907 --- /dev/null +++ b/tools/dftestlib/util.py @@ -0,0 +1,29 @@ +# Copyright (c) 2013 by Gilbert Ramirez <gram@alumni.rice.edu> + +import subprocess + +SUCCESS = 0 +def exec_cmdv(cmdv, cwd=None, stdin=None): + """Run the commands in cmdv, returning (retval, output), + where output is stdout and stderr combined. + If cwd is given, the child process runs in that directory. + If a filehandle is passed as stdin, it is used as stdin. + If there is an OS-level error, None is the retval.""" + + try: + output = subprocess.check_output(cmdv, stderr=subprocess.STDOUT, + cwd=cwd, stdin=stdin) + retval = SUCCESS + + # If file isn't executable + except OSError, e: + output = str(e) + retval = None + + # If process returns non-zero + except subprocess.CalledProcessError, e: + output = e.output + retval = e.returncode + + return (retval, output) + |