~launchpad-pqm/launchpad/devel

809 by Canonical.com Patch Queue Manager
Nuke some arch-tags
1
#!/usr/bin/env python2.3
2
##############################################################################
3
#
4
# Copyright (c) 2004 Zope Corporation and Contributors.
5
# All Rights Reserved.
6
#
7
# This software is subject to the provisions of the Zope Public License,
8
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
9
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
10
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
11
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
12
# FOR A PARTICULAR PURPOSE.
13
#
14
##############################################################################
15
"""Test script
16
17
$Id: test.py 25177 2004-06-02 13:17:31Z jim $
18
"""
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
19
import sys, os, psycopg
809 by Canonical.com Patch Queue Manager
Nuke some arch-tags
20
21
here = os.path.dirname(os.path.realpath(__file__))
1806 by Canonical.com Patch Queue Manager
Always use sys.path.insert instead of sys.path.append to give precedence for launchpad libs that are inside our tree. r=stub
22
sys.path.insert(0, os.path.join(here, 'lib'))
809 by Canonical.com Patch Queue Manager
Nuke some arch-tags
23
24
# Set PYTHONPATH environment variable for spawned processes
25
os.environ['PYTHONPATH'] = ':'.join(sys.path)
26
1628 by Canonical.com Patch Queue Manager
Configuration, Librian and Librarian test harness work
27
# Tell canonical.config to use the test config file, not launchpad.conf
28
from canonical.config import config
29
config.setDefaultSection('testrunner')
30
1210 by Canonical.com Patch Queue Manager
Refactor and document test harnesses
31
# Turn on psycopg debugging wrapper
32
#import canonical.database.debug
33
#canonical.database.debug.install()
34
35
# Silence spurious warnings or turn them into errors
36
import warnings
37
# Our Z3 is still using whrandom
38
warnings.filterwarnings(
39
        "ignore",
40
        "the whrandom module is deprecated; please use the random module"
41
        )
42
# Some stuff got deprecated in 2.4 that we can clean up
43
warnings.filterwarnings(
44
        "error", category=DeprecationWarning, module="email"
45
        )
46
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
47
from canonical.ftests import pgsql
1617 by Canonical.com Patch Queue Manager
Refactor PostgreSQL harnesses to avoid bug found by ddaa. Add more tests
48
# If this is removed, make sure canonical.ftests.pgsql is updated
49
# because the test harness there relies on the Connection wrapper being
50
# installed.
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
51
pgsql.installFakeConnect()
52
809 by Canonical.com Patch Queue Manager
Nuke some arch-tags
53
# This is a terrible hack to divorce the FunctionalTestSetup from
54
# its assumptions about the ZODB.
55
from zope.app.tests.functional import FunctionalTestSetup
56
FunctionalTestSetup.__init__ = lambda *x: None
57
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
58
# Install our own test runner to to pre/post sanity checks
809 by Canonical.com Patch Queue Manager
Nuke some arch-tags
59
import zope.app.tests.test
1709 by Canonical.com Patch Queue Manager
Heap of constraints and data sanitization to the ?ProductSeries table. Web form updates and other drive by refactorings.
60
from canonical.database.sqlbase import SQLBase, ZopelessTransactionManager
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
61
class LaunchpadTestRunner(zope.app.tests.test.ImmediateTestRunner):
62
    def precheck(self, test):
63
        pass
64
65
    def postcheck(self, test):
1709 by Canonical.com Patch Queue Manager
Heap of constraints and data sanitization to the ?ProductSeries table. Web form updates and other drive by refactorings.
66
        '''Tests run at the conclusion of every top level test suite'''
67
        # Confirm Zopeless teardown has been called if necessary
68
        assert ZopelessTransactionManager._installed is None, \
69
                'Test used Zopeless but failed to tearDown correctly'
70
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
71
        # Confirm all database connections have been dropped
72
        assert len(pgsql.PgTestSetup.connections) == 0, \
73
                'Not all PostgreSQL connections closed'
74
1248 by Canonical.com Patch Queue Manager
Optimize tests by not dropping the db if we are sure no changes have been made
75
        # Disabled this check - we now optimize by only dropping the
76
        # db if necessary
77
        #
78
        #con = psycopg.connect('dbname=template1')
79
        #try:
80
        #    cur = con.cursor()
81
        #    cur.execute("""
82
        #        SELECT count(*) FROM pg_database
83
        #        WHERE datname='launchpad_ftest'
84
        #        """)
85
        #    r = cur.fetchone()[0]
86
        #    assert r == 0, 'launchpad_ftest database not dropped'
87
        #finally:
88
        #    con.close()
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
89
90
    def run(self, test):
91
        self.precheck(test)
92
        rv = super(LaunchpadTestRunner, self).run(test)
93
        self.postcheck(test)
94
        return rv
95
zope.app.tests.test.ImmediateTestRunner = LaunchpadTestRunner
809 by Canonical.com Patch Queue Manager
Nuke some arch-tags
96
97
if __name__ == '__main__':
98
    zope.app.tests.test.process_args()