24
24
# This will set the timeout to 10 minutes.
27
HERE = os.path.dirname(os.path.realpath(__file__))
29
31
"""Call bin/test with whatever arguments this script was run with.
31
If the tests ran ok (last line of stderr is 'OK<return>') then suppress
34
Otherwise, print output and exit(1).
36
here = os.path.dirname(os.path.realpath(__file__))
39
# NB. If tabnanny raises an exception, run
40
# python /usr/lib/python2.5/tabnanny.py -vv lib/canonical
41
# for more detailed output.
33
Prior to running the tests this script checks the project files with
34
Python2.5's tabnanny and sets up the test database.
36
Returns 1 on error, otherwise it returns the testrunner's exit code.
38
if run_tabnanny() != 0:
41
if setup_test_database() != 0:
44
return run_test_process()
48
"""Run the tabnanny, return its exit code.
50
If tabnanny raises an exception, run "python /usr/lib/python2.5/tabnanny.py
51
-vv lib/canonical for more detailed output.
54
# Tabnanny reports some of its errors on sys.stderr, so this code is
55
# already wrong. subprocess.Popen.communicate() would work better.
56
print "Checking the source tree with tabnanny..."
42
57
org_stdout = sys.stdout
43
58
sys.stdout = StringIO()
44
tabnanny.check(os.path.join(here, 'lib', 'canonical'))
59
tabnanny.check(os.path.join(HERE, 'lib', 'canonical'))
60
tabnanny.check(os.path.join(HERE, 'lib', 'lp'))
45
61
tabnanny_results = sys.stdout.getvalue()
46
62
sys.stdout = org_stdout
47
63
if len(tabnanny_results) > 0:
49
65
print tabnanny_results
50
66
print '---- end tabnanny bitching ----'
73
def setup_test_database():
74
"""Set up a test instance of our postgresql database.
76
Returns 0 for success, 1 for errors.
53
78
# Sanity check PostgreSQL version. No point in trying to create a test
54
79
# database when PostgreSQL is too old.
55
80
con = psycopg2.connect('dbname=template1')
95
120
# Build the template database. Tests duplicate this.
96
here = os.path.dirname(os.path.realpath(__file__))
97
schema_dir = os.path.join(here, 'database', 'schema')
121
schema_dir = os.path.join(HERE, 'database', 'schema')
98
122
if os.system('cd %s; make test > /dev/null' % (schema_dir)) != 0:
99
123
print 'Failed to create database or load sampledata.'
166
def run_test_process():
167
"""Start the testrunner process and return its exit code."""
168
# Fork a child process so that we get a new process ID that we can
169
# guarantee is not currently in use as a process group leader. This
170
# addresses the case where this script has been started directly in the
171
# shell using "python foo.py" or "./foo.py".
174
pid, exitstatus = os.waitpid(pid, os.P_WAIT)
139
177
print 'Running tests.'
142
180
# Play shenanigans with our process group. We want to kill off our child
143
181
# groups while at the same time not slaughtering ourselves!
158
196
"'-screen 0 1024x768x24'",
159
os.path.join(here, 'bin', 'test')] + sys.argv[1:]
197
os.path.join(HERE, 'bin', 'test')] + sys.argv[1:]
161
199
command_line = ' '.join(cmd)
162
200
print "Running command:", command_line