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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#!/usr/bin/env python2.4
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test script
$Id: test.py 25177 2004-06-02 13:17:31Z jim $
"""
import sys, os, psycopg, time
os.setpgrp() # So test_on_merge.py can reap its children
# Make tests run in a timezone no launchpad developers live in.
# Our tests need to run in any timezone.
# (No longer actually required, as PQM does this)
os.environ['TZ'] = 'Asia/Calcutta'
time.tzset()
here = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.join(here, 'lib'))
# Set PYTHONPATH environment variable for spawned processes
os.environ['PYTHONPATH'] = ':'.join(sys.path)
# Install the import fascist import hook and atexit handler.
import importfascist
importfascist.install_import_fascist()
# Install the warning handler hook and atexit handler.
import warninghandler
warninghandler.install_warning_handler()
# Tell canonical.config to use the test config section in launchpad.conf
from canonical.config import config
config.setDefaultSection('testrunner')
# Turn on psycopg debugging wrapper
#import canonical.database.debug
#canonical.database.debug.install()
# Silence spurious warnings or turn them into errors
import warnings
# Our Z3 is still using whrandom
warnings.filterwarnings(
"ignore",
"the whrandom module is deprecated; please use the random module"
)
# Some stuff got deprecated in 2.4 that we can clean up
warnings.filterwarnings(
"error", category=DeprecationWarning, module="email"
)
from canonical.ftests import pgsql
# If this is removed, make sure canonical.ftests.pgsql is updated
# because the test harness there relies on the Connection wrapper being
# installed.
pgsql.installFakeConnect()
# This is a terrible hack to divorce the FunctionalTestSetup from
# its assumptions about the ZODB.
from zope.app.tests.functional import FunctionalTestSetup
FunctionalTestSetup.__init__ = lambda *x: None
# Install our own test runner to to pre/post sanity checks
import zope.app.tests.test
from canonical.database.sqlbase import SQLBase, ZopelessTransactionManager
class LaunchpadTestRunner(zope.app.tests.test.ImmediateTestRunner):
def precheck(self, test):
pass
def postcheck(self, test):
'''Tests run at the conclusion of every top level test suite'''
# Confirm Zopeless teardown has been called if necessary
assert ZopelessTransactionManager._installed is None, \
'Test used Zopeless but failed to tearDown correctly'
# Confirm all database connections have been dropped
assert len(pgsql.PgTestSetup.connections) == 0, \
'Not all PostgreSQL connections closed'
# Disabled this check - we now optimize by only dropping the
# db if necessary
#
#con = psycopg.connect('dbname=template1')
#try:
# cur = con.cursor()
# cur.execute("""
# SELECT count(*) FROM pg_database
# WHERE datname='launchpad_ftest'
# """)
# r = cur.fetchone()[0]
# assert r == 0, 'launchpad_ftest database not dropped'
#finally:
# con.close()
def run(self, test):
self.precheck(test)
rv = super(LaunchpadTestRunner, self).run(test)
self.postcheck(test)
return rv
zope.app.tests.test.ImmediateTestRunner = LaunchpadTestRunner
if __name__ == '__main__':
zope.app.tests.test.process_args()
|