test.py 3.34 KB
Newer Older
1
#!/usr/bin/env python
2 3
##############################################################################
#
4
# Copyright (c) 2004 Zope Corporation and Contributors.
5 6 7
# All Rights Reserved.
#
# 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 10 11 12 13 14
# 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.
#
##############################################################################
15
"""Zope 2 test script
16

17
see zope.testing testrunner.txt
18

19
$Id: test.py 33303 2005-07-13 22:28:33Z jim $
20 21
"""

22
import os.path, sys
23

24 25 26
# Remove script directory from path:
scriptdir = os.path.realpath(os.path.dirname(sys.argv[0]))
sys.path[:] = [p for p in sys.path if os.path.realpath(p) != scriptdir]
27

28 29 30
shome = os.environ.get('SOFTWARE_HOME')
zhome = os.environ.get('ZOPE_HOME')
ihome = os.environ.get('INSTANCE_HOME')
31

32
if zhome:
33
    zhome = os.path.realpath(zhome)
34
    if shome:
35
        shome = os.path.realpath(shome)
36
    else:
37
        shome = os.path.join(zhome, 'lib', 'python')
38
elif shome:
39
    shome = os.path.realpath(shome)
Jim Fulton's avatar
Jim Fulton committed
40
    zhome = os.path.dirname(os.path.dirname(shome))
41 42 43 44 45 46
elif ihome:
    print >> sys.stderr, '''
    If INSTANCE_HOME is set, then at least one of SOFTWARE_HOME or ZOPE_HOME
    must be set
    '''
else:
47 48 49 50 51 52 53
    # No zope home, derive it from script directory:
    # (test.py lives in either ZOPE_HOME or ZOPE_HOME/bin)
    parentdir, lastpart = os.path.split(scriptdir)
    if lastpart == 'bin':
        zhome = parentdir
    else:
        zhome = scriptdir
54
    shome = os.path.join(zhome, 'lib', 'python')
55 56 57 58

sys.path.insert(0, shome)

defaults = '--tests-pattern ^tests$ -v'.split()
59 60 61 62 63 64
defaults += ['-m',
             '!^('
             'ZConfig'
             '|'
             'BTrees'
             '|'
65 66 67
             'persistent'
             '|'
             'ThreadedAsync'
68 69 70 71 72 73 74 75 76 77 78 79
             '|'
             'transaction'
             '|'
             'ZEO'
             '|'
             'ZODB'
             '|'
             'ZopeUndo'
             '|'
             'zdaemon'
             '|'
             'zope[.]testing'
80 81
             '|'
             'zope[.]app'
82
             ')[.]']
83 84
if ihome:
    ihome = os.path.abspath(ihome)
85 86 87 88
    defaults += ['--path', os.path.join(ihome, 'lib', 'python')]
    products = os.path.join(ihome, 'Products')
    if os.path.exists(products):
        defaults += ['--package-path', products, 'Products']
89 90 91 92 93 94 95 96 97 98 99 100
else:
    defaults += ['--test-path', shome]

from zope.testing import testrunner

def load_config_file(option, opt, config_file, *ignored):
    config_file = os.path.abspath(config_file)
    print "Parsing %s" % config_file
    import Zope2
    Zope2.configure(config_file)

testrunner.setup.add_option(
Jim Fulton's avatar
Jim Fulton committed
101
    '--config-file', action="callback", type="string", dest='config_file',
102 103
    callback=load_config_file,
    help="""\
Jim Fulton's avatar
Jim Fulton committed
104
Initialize Zope with the given configuration file.
105 106
""")

107 108 109 110 111 112 113 114 115 116
def filter_warnings(option, opt, *ignored):
    import warnings
    warnings.simplefilter('ignore', Warning, append=True)

testrunner.other.add_option(
    '--nowarnings', action="callback", callback=filter_warnings,
    help="""\
Install a filter to suppress warnings emitted by code.
""")

117
sys.exit(testrunner.run(defaults))