Also decode strings in _DynamicStringTable.get_string() (#217)
[pyelftools.git] / test / utils.py
index 908cfcc529cd8912fd82dc4760c0df46f3aa246d..8eedacf563c98b5c3dd17fa5444d833c5ef31875 100644 (file)
@@ -6,20 +6,11 @@
 # Eli Bendersky (eliben@gmail.com)
 # This code is in the public domain
 #-------------------------------------------------------------------------------
+from __future__ import print_function
 import os, sys, subprocess, tempfile
 
-# This module should not import elftools before setup_syspath() is called!
-# See the Hacking Guide in the documentation for more details.
 
-def setup_syspath():
-    """ Setup sys.path so that tests pick up local pyelftools before the
-        installed one when run from development directory.
-    """
-    if sys.path[0] != '.':
-        sys.path.insert(0, '.')
-
-
-def run_exe(exe_path, args):
+def run_exe(exe_path, args=[], echo=False):
     """ Runs the given executable as a subprocess, given the
         list of arguments. Captures its return code (rc) and stdout and
         returns a pair: rc, stdout_str
@@ -27,7 +18,9 @@ def run_exe(exe_path, args):
     popen_cmd = [exe_path] + args
     if os.path.splitext(exe_path)[1] == '.py':
         popen_cmd.insert(0, sys.executable)
-    proc = subprocess.Popen(popen_cmd, stdout=subprocess.PIPE)
+    if echo:
+      print('[cmd]', ' '.join(popen_cmd))
+    proc = subprocess.Popen(popen_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     proc_stdout = proc.communicate()[0]
     from elftools.common.py3compat import bytes2str
     return proc.returncode, bytes2str(proc_stdout)
@@ -51,4 +44,3 @@ def dump_output_to_temp_files(testlog, *args):
         file.write(s)
         file.close()
         testlog.info('@@ Output #%s dumped to file: %s' % (i + 1, path))
-