~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__))
22
sys.path.append(os.path.join(here, 'lib'))
23
24
# Set PYTHONPATH environment variable for spawned processes
25
os.environ['PYTHONPATH'] = ':'.join(sys.path)
26
1210 by Canonical.com Patch Queue Manager
Refactor and document test harnesses
27
# Turn on psycopg debugging wrapper
28
#import canonical.database.debug
29
#canonical.database.debug.install()
30
31
# Silence spurious warnings or turn them into errors
32
import warnings
33
# Our Z3 is still using whrandom
34
warnings.filterwarnings(
35
        "ignore",
36
        "the whrandom module is deprecated; please use the random module"
37
        )
38
# Some stuff got deprecated in 2.4 that we can clean up
39
warnings.filterwarnings(
40
        "error", category=DeprecationWarning, module="email"
41
        )
42
881 by Canonical.com Patch Queue Manager
More popups - Person and BinaryPackageName
43
# This is a hack to use canonical.difflib instead of standard difflib
940 by Canonical.com Patch Queue Manager
Full text indexing, database schema patches
44
# so we can easily test it. Comment out and commit to rocketfuel if
45
# it causes grief -- StuartBishop 20041130
46
# Turned off - we need more context or linenumbers. eg. I'm being told I
47
# have an unexpected line, but no way to tell where.
48
def monkey_patch_doctest():
49
    import canonical.difflib
50
    sys.modules['difflib'] = canonical.difflib
51
    import difflib
52
    assert hasattr(difflib.Differ, 'fancy_compare'), \
53
            'Failed to monkey patch difflib'
54
    import zope.testing.doctest
55
    import canonical.doctest
56
    zope.testing.doctest.OutputChecker = canonical.doctest.OutputChecker
1025 by Canonical.com Patch Queue Manager
split full bug list into simple/advanced
57
#monkey_patch_doctest()
881 by Canonical.com Patch Queue Manager
More popups - Person and BinaryPackageName
58
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
59
from canonical.ftests import pgsql
60
pgsql.installFakeConnect()
61
809 by Canonical.com Patch Queue Manager
Nuke some arch-tags
62
# This is a terrible hack to divorce the FunctionalTestSetup from
63
# its assumptions about the ZODB.
64
from zope.app.tests.functional import FunctionalTestSetup
65
FunctionalTestSetup.__init__ = lambda *x: None
66
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
67
# Install our own test runner to to pre/post sanity checks
809 by Canonical.com Patch Queue Manager
Nuke some arch-tags
68
import zope.app.tests.test
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
69
class LaunchpadTestRunner(zope.app.tests.test.ImmediateTestRunner):
70
    def precheck(self, test):
71
        pass
72
73
    def postcheck(self, test):
74
        # Confirm all database connections have been dropped
75
        assert len(pgsql.PgTestSetup.connections) == 0, \
76
                'Not all PostgreSQL connections closed'
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()
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()