1import os.path
2import sys
3import unittest
4
5
6POSSIBLE_TEST_BINARIES = [
7    'libreadline.so.5',
8    'libreadline.so.6',
9]
10
11POSSIBLE_TEST_BINARY_PATHS = [
12    '/usr/lib/debug',
13    '/lib',
14    '/usr/lib',
15    '/usr/local/lib',
16    '/lib/i386-linux-gnu',
17]
18
19class TestBase(unittest.TestCase):
20    if sys.version_info.major == 2:
21        assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
22
23    def get_test_binary(self):
24        """Helper to obtain a test binary for object file testing.
25
26        FIXME Support additional, highly-likely targets or create one
27        ourselves.
28        """
29        for d in POSSIBLE_TEST_BINARY_PATHS:
30            for lib in POSSIBLE_TEST_BINARIES:
31                path = os.path.join(d, lib)
32
33                if os.path.exists(path):
34                    return path
35
36        raise Exception('No suitable test binaries available!')
37    get_test_binary.__test__ = False
38
39    def get_test_file(self):
40        return os.path.join(os.path.dirname(os.path.abspath(__file__)), "test_file")
41
42    def get_test_bc(self):
43        return os.path.join(os.path.dirname(os.path.abspath(__file__)), "test.bc")
44