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