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
|
#!/usr/bin/env python2.3
##############################################################################
#
# 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
here = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(here, 'lib'))
# Set PYTHONPATH environment variable for spawned processes
os.environ['PYTHONPATH'] = ':'.join(sys.path)
# 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"
)
# This is a hack to use canonical.difflib instead of standard difflib
# so we can easily test it. Comment out and commit to rocketfuel if
# it causes grief -- StuartBishop 20041130
# Turned off - we need more context or linenumbers. eg. I'm being told I
# have an unexpected line, but no way to tell where.
def monkey_patch_doctest():
import canonical.difflib
sys.modules['difflib'] = canonical.difflib
import difflib
assert hasattr(difflib.Differ, 'fancy_compare'), \
'Failed to monkey patch difflib'
import zope.testing.doctest
import canonical.doctest
zope.testing.doctest.OutputChecker = canonical.doctest.OutputChecker
#monkey_patch_doctest()
from canonical.ftests import pgsql
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
class LaunchpadTestRunner(zope.app.tests.test.ImmediateTestRunner):
def precheck(self, test):
pass
def postcheck(self, test):
# 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()
|