summaryrefslogtreecommitdiffstats
path: root/tests/common.py
blob: bd7951cb41dde90e01be93fa9c053a2492342a1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import sys

def importModules(buildDir, srcDir):
    # Be very careful when you change this code, it's
    # fragile and the order is really significant

    sys.path.insert(0, srcDir)
    sys.path.insert(0, buildDir)
    sys.path.insert(0, os.path.join(buildDir, 'glib'))
    sys.path.insert(0, os.path.join(buildDir, 'gobject'))
    sys.path.insert(0, os.path.join(buildDir, 'gio'))

    # testhelper
    sys.path.insert(0, os.path.join(buildDir, 'tests'))
    sys.argv.append('--g-fatal-warnings')

    testhelper = importModule('testhelper', '.')
    glib = importModule('glib', buildDir, 'glib')
    gobject = importModule('gobject', buildDir, 'gobject')
    gio = importModule('gio', buildDir, 'gio')

    globals().update(locals())

    os.environ['PYGTK_USE_GIL_STATE_API'] = ''
    gobject.threads_init()

def importModule(module, directory, name=None):
    global isDistCheck

    origName = module
    if not name:
        name = module + '.la'

    try:
        obj = __import__(module, {}, {}, '')
    except ImportError:
        raise
        e = sys.exc_info()[1]
        raise SystemExit('%s could not be imported: %s' % (origName, e))

    location = obj.__file__

    current = os.getcwd()
    expected = os.path.abspath(os.path.join(current, location))
    current = os.path.abspath(location)
    if current != expected:
        raise AssertionError('module %s imported from wrong location. Expected %s, got %s' % (
                                 module, expected, current))
    return obj

try:
    _bytes = bytes
except NameError:
    _bytes = str

try:
    _unicode = unicode
except NameError:
    _unicode = str