source: trunk/tests/framework.py @ 1930

Revision 1930, 3.8 KB checked in by jukka, 12 years ago (diff)

Fixed tests and other stuff, fixed #1376, closed #1420.

  • Property svn:eol-style set to native
Line 
1# Copyright 2006 by the LeMill Team (see AUTHORS)
2#
3# This file is part of LeMill.
4#
5# LeMill is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# LeMill is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with LeMill; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19##############################################################################
20#
21# ZopeTestCase
22#
23# COPY THIS FILE TO YOUR 'tests' DIRECTORY.
24#
25# This version of framework.py will use the SOFTWARE_HOME
26# environment variable to locate Zope and the Testing package.
27#
28# If the tests are run in an INSTANCE_HOME installation of Zope,
29# Products.__path__ and sys.path with be adjusted to include the
30# instance's Products and lib/python directories respectively.
31#
32# If you explicitly set INSTANCE_HOME prior to running the tests,
33# auto-detection is disabled and the specified path will be used
34# instead.
35#
36# If the 'tests' directory contains a custom_zodb.py file, INSTANCE_HOME
37# will be adjusted to use it.
38#
39# If you set the ZEO_INSTANCE_HOME environment variable a ZEO setup
40# is assumed, and you can attach to a running ZEO server (via the
41# instance's custom_zodb.py).
42#
43##############################################################################
44#
45# The following code should be at the top of every test module:
46#
47# import os, sys
48# if __name__ == '__main__':
49#     execfile(os.path.join(sys.path[0], 'framework.py'))
50#
51# ...and the following at the bottom:
52#
53# if __name__ == '__main__':
54#     framework()
55#
56##############################################################################
57
58__version__ = '0.2.3'
59
60# Save start state
61#
62__SOFTWARE_HOME = os.environ.get('SOFTWARE_HOME', '')
63__INSTANCE_HOME = os.environ.get('INSTANCE_HOME', '')
64
65if __SOFTWARE_HOME.endswith(os.sep):
66    __SOFTWARE_HOME = os.path.dirname(__SOFTWARE_HOME)
67
68if __INSTANCE_HOME.endswith(os.sep):
69    __INSTANCE_HOME = os.path.dirname(__INSTANCE_HOME)
70
71# Find and import the Testing package
72#
73if not sys.modules.has_key('Testing'):
74    p0 = sys.path[0]
75    if p0 and __name__ == '__main__':
76        os.chdir(p0)
77        p0 = ''
78    s = __SOFTWARE_HOME
79    p = d = s and s or os.getcwd()
80    while d:
81        if os.path.isdir(os.path.join(p, 'Testing')):
82            zope_home = os.path.dirname(os.path.dirname(p))
83            sys.path[:1] = [p0, p, zope_home]
84            break
85        p, d = s and ('','') or os.path.split(p)
86    else:
87        print 'Unable to locate Testing package.',
88        print 'You might need to set SOFTWARE_HOME.'
89        sys.exit(1)
90
91import Testing, unittest
92execfile(os.path.join(os.path.dirname(Testing.__file__), 'common.py'))
93
94# Include ZopeTestCase support
95#
96if 1:   # Create a new scope
97
98    p = os.path.join(os.path.dirname(Testing.__file__), 'ZopeTestCase')
99
100    if not os.path.isdir(p):
101        print 'Unable to locate ZopeTestCase package.',
102        print 'You might need to install ZopeTestCase.'
103        sys.exit(1)
104
105    ztc_common = 'ztc_common.py'
106    ztc_common_global = os.path.join(p, ztc_common)
107
108    f = 0
109    if os.path.exists(ztc_common_global):
110        execfile(ztc_common_global)
111        f = 1
112    if os.path.exists(ztc_common):
113        execfile(ztc_common)
114        f = 1
115
116    if not f:
117        print 'Unable to locate %s.' % ztc_common
118        sys.exit(1)
119
120# Debug
121#
122print 'SOFTWARE_HOME: %s' % os.environ.get('SOFTWARE_HOME', 'Not set')
123print 'INSTANCE_HOME: %s' % os.environ.get('INSTANCE_HOME', 'Not set')
124sys.stdout.flush()
Note: See TracBrowser for help on using the repository browser.