~launchpad-pqm/launchpad/devel

2048 by Canonical.com Patch Queue Manager
debbugssync, hct enabling, and ui fixes. r=jamesh
1
#!/usr/bin/env python2.4
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
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
"""
2083 by Canonical.com Patch Queue Manager
[r=jamesh] testrunner improvements (?)
19
import sys, os, psycopg, time
809 by Canonical.com Patch Queue Manager
Nuke some arch-tags
20
2083 by Canonical.com Patch Queue Manager
[r=jamesh] testrunner improvements (?)
21
os.setpgrp() # So test_on_merge.py can reap its children
22
23
# Make tests run in a timezone no launchpad developers live in.
24
# Our tests need to run in any timezone.
25
# (No longer actually required, as PQM does this)
26
os.environ['TZ'] = 'Asia/Calcutta'
27
time.tzset()
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
28
29
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
30
sys.path.insert(0, os.path.join(here, 'lib'))
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
31
32
# Set PYTHONPATH environment variable for spawned processes
33
os.environ['PYTHONPATH'] = ':'.join(sys.path)
34
2097 by Canonical.com Patch Queue Manager
[trivial] more import fascist improvements
35
# Install the import fascist import hook and atexit handler.
36
import importfascist
37
importfascist.install_import_fascist()
1968 by Canonical.com Patch Queue Manager
DatabaseCodeImportFascist: warn about database imports in browser code after running tests. [r=SteveA]
38
2103 by Canonical.com Patch Queue Manager
[trivial] improved warning output for tests, and fixed a bunch of ambiguous use of select results warnings. some xxx comments left in person code. one untested codepath in hct backend.
39
# Install the warning handler hook and atexit handler.
40
import warninghandler
41
warninghandler.install_warning_handler()
42
43
2083 by Canonical.com Patch Queue Manager
[r=jamesh] testrunner improvements (?)
44
# Tell canonical.config to use the test config section in launchpad.conf
1628 by Canonical.com Patch Queue Manager
Configuration, Librian and Librarian test harness work
45
from canonical.config import config
46
config.setDefaultSection('testrunner')
47
1210 by Canonical.com Patch Queue Manager
Refactor and document test harnesses
48
# Turn on psycopg debugging wrapper
49
#import canonical.database.debug
50
#canonical.database.debug.install()
51
2770.1.30 by Guilherme Salgado
Clean up the http_proxy env var before running tests, as we don't want the requests we make to localhost to be proxied
52
# Unset the http_proxy environment variable, because we're going to make
53
# requests to localhost and we don't wand this to be proxied.
54
try:
55
    os.environ.pop('http_proxy')
56
except KeyError:
57
    pass
58
1210 by Canonical.com Patch Queue Manager
Refactor and document test harnesses
59
# Silence spurious warnings or turn them into errors
60
import warnings
61
# Our Z3 is still using whrandom
62
warnings.filterwarnings(
63
        "ignore",
64
        "the whrandom module is deprecated; please use the random module"
65
        )
66
# Some stuff got deprecated in 2.4 that we can clean up
67
warnings.filterwarnings(
68
        "error", category=DeprecationWarning, module="email"
69
        )
70
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
71
from canonical.ftests import pgsql
1617 by Canonical.com Patch Queue Manager
Refactor PostgreSQL harnesses to avoid bug found by ddaa. Add more tests
72
# If this is removed, make sure canonical.ftests.pgsql is updated
73
# because the test harness there relies on the Connection wrapper being
74
# installed.
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
75
pgsql.installFakeConnect()
76
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
77
# This is a terrible hack to divorce the FunctionalTestSetup from
78
# its assumptions about the ZODB.
79
from zope.app.tests.functional import FunctionalTestSetup
80
FunctionalTestSetup.__init__ = lambda *x: None
81
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
82
# Install our own test runner to to pre/post sanity checks
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
83
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.
84
from canonical.database.sqlbase import SQLBase, ZopelessTransactionManager
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
85
class LaunchpadTestRunner(zope.app.tests.test.ImmediateTestRunner):
86
    def precheck(self, test):
87
        pass
88
89
    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.
90
        '''Tests run at the conclusion of every top level test suite'''
91
        # Confirm Zopeless teardown has been called if necessary
92
        assert ZopelessTransactionManager._installed is None, \
93
                'Test used Zopeless but failed to tearDown correctly'
94
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
95
        # Confirm all database connections have been dropped
96
        assert len(pgsql.PgTestSetup.connections) == 0, \
97
                'Not all PostgreSQL connections closed'
98
1248 by Canonical.com Patch Queue Manager
Optimize tests by not dropping the db if we are sure no changes have been made
99
        # Disabled this check - we now optimize by only dropping the
100
        # db if necessary
101
        #
102
        #con = psycopg.connect('dbname=template1')
103
        #try:
104
        #    cur = con.cursor()
105
        #    cur.execute("""
106
        #        SELECT count(*) FROM pg_database
107
        #        WHERE datname='launchpad_ftest'
108
        #        """)
109
        #    r = cur.fetchone()[0]
110
        #    assert r == 0, 'launchpad_ftest database not dropped'
111
        #finally:
112
        #    con.close()
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
113
114
    def run(self, test):
115
        self.precheck(test)
116
        rv = super(LaunchpadTestRunner, self).run(test)
117
        self.postcheck(test)
118
        return rv
119
zope.app.tests.test.ImmediateTestRunner = LaunchpadTestRunner
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
120
121
if __name__ == '__main__':
122
    zope.app.tests.test.process_args()