and allow running only from the root directory.
--- /dev/null
+All tests should be run from the root development directory of pyelftools
#-------------------------------------------------------------------------------
import os, sys
import logging
-sys.path.insert(0, '.')
+
from test.utils import run_exe, is_in_rootdir, dump_output_to_temp_files
if rc != 0:
testlog.info('.......ERROR - example returned error code %s' % rc)
return False
-
+
# Comparison is done as lists of lines, to avoid EOL problems
if example_out.split() == ref_str.split():
return True
from optparse import OptionParser
import logging
import platform
-sys.path.insert(0, '.') # to load *our* test, not Python's test
from test.utils import run_exe, is_in_rootdir, dump_output_to_temp_files
import unittest2 as unittest
except ImportError:
import unittest
-import sys
import os
-sys.path.extend(['.', '..'])
+from test.utils import setup_syspath; setup_syspath()
from elftools.elf.elffile import ELFFile
class TestARMSupport(unittest.TestCase):
def test_hello(self):
- with open(os.path.join('test', 'testfiles', 'simple_gcc.elf.arm'), 'rb') as f:
+ with open(os.path.join('test', 'testfiles',
+ 'simple_gcc.elf.arm'), 'rb') as f:
elf = ELFFile(f)
self.assertEqual(elf.get_machine_arch(), 'ARM')
self.assertEqual(elf.num_segments(), 2)
if __name__ == '__main__':
- sys.exit(unittest.main())
+ unittest.main()
import unittest2 as unittest
except ImportError:
import unittest
-import sys
-sys.path.extend(['.', '..'])
+from test.utils import setup_syspath; setup_syspath()
from elftools.common.py3compat import BytesIO
from elftools.dwarf.callframe import (
CallFrameInfo, CIE, FDE, instruction_name, CallFrameInstruction,
import unittest2 as unittest
except ImportError:
import unittest
-import sys
-sys.path.extend(('..', '.'))
+from test.utils import setup_syspath; setup_syspath()
from elftools.dwarf.descriptions import ExprDumper, set_global_machine_arch
from elftools.dwarf.structs import DWARFStructs
import unittest2 as unittest
except ImportError:
import unittest
-import sys
-sys.path.extend(['.', '..'])
+from test.utils import setup_syspath; setup_syspath()
from elftools.common.py3compat import BytesIO, iteritems
from elftools.dwarf.lineprogram import LineProgram, LineState, LineProgramEntry
from elftools.dwarf.structs import DWARFStructs
import unittest2 as unittest
except ImportError:
import unittest
-import sys
-sys.path.extend(['.', '..'])
+from test.utils import setup_syspath; setup_syspath()
from elftools.dwarf.structs import DWARFStructs
import unittest2 as unittest
except ImportError:
import unittest
-import sys
from random import randint
-sys.path.extend(['.', '..'])
+from test.utils import setup_syspath; setup_syspath()
from elftools.common.py3compat import int2byte, BytesIO
from elftools.common.utils import (parse_cstring_from_stream,
preserve_stream_pos)
from elftools.common.py3compat import bytes2str
+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):
""" Runs the given executable as a subprocess, given the
list of arguments. Captures its return code (rc) and stdout and
proc = subprocess.Popen(popen_cmd, stdout=subprocess.PIPE)
proc_stdout = proc.communicate()[0]
return proc.returncode, bytes2str(proc_stdout)
-
+
def is_in_rootdir():
""" Check whether the current dir is the root dir of pyelftools
"""
dirstuff = os.listdir('.')
return 'test' in dirstuff and 'elftools' in dirstuff
-
+
def dump_output_to_temp_files(testlog, *args):
""" Dumps the output strings given in 'args' to temp files: one for each
file.write(s)
file.close()
testlog.info('@@ Output #%s dumped to file: %s' % (i + 1, path))
-
+