aboutsummaryrefslogtreecommitdiffstats
path: root/tests/install_test.py
blob: 56ab13cc19621dbf36e5e35f154526ee7c128708 (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
61
62
63
64
65
66
67
68
69
70
import urllib2
import sys
import os

if os.path.exists('bootstrap.py'):
    print 'bootstrap.py exists in the current dir, aborting'
    sys.exit(2)

print '**** Starting Test'
print '\n\n'

is_jython = sys.platform.startswith('java')
if is_jython:
    import subprocess

print 'Downloading bootstrap'
file = urllib2.urlopen('http://nightly.ziade.org/bootstrap.py')
f = open('bootstrap.py', 'w')
f.write(file.read())
f.close()

# running it
args = [sys.executable]  + ['bootstrap.py']
if is_jython:
    subprocess.Popen([sys.executable] + args).wait()
else:
    os.spawnv(os.P_WAIT, sys.executable, args)

# now checking if Distribute is installed
script = """\
import sys
try:
    import setuptools
except ImportError:
    sys.exit(0)

sys.exit(hasattr(setuptools, "_distribute"))
"""

root = 'script'
seed = 0
script_name = '%s%d.py' % (root, seed)

while os.path.exists(script_name):
    seed += 1
    script_name = '%s%d.py' % (root, seed)

f = open(script_name, 'w')
try:
    f.write(script)
finally:
    f.close()

try:
    args = [sys.executable]  + ['script.py']
    if is_jython:
        res = subprocess.call([sys.executable] + args)
    else:
        res = os.spawnv(os.P_WAIT, sys.executable, args)

    print '\n\n'
    if res:
        print '**** Test is OK'
    else:
        print '**** Test failed, please send me the output at tarek@ziade.org'
finally:
    if os.path.exists(script_name):
        os.remove(script_name)
    os.remove('bootstrap.py')