[1] | 1 | ############################################################################## |
---|
| 2 | # |
---|
| 3 | # ZopeTestCase |
---|
| 4 | # |
---|
| 5 | # COPY THIS FILE TO YOUR 'tests' DIRECTORY. |
---|
| 6 | # |
---|
| 7 | # This version of framework.py will use the SOFTWARE_HOME |
---|
| 8 | # environment variable to locate Zope and the Testing package. |
---|
| 9 | # |
---|
| 10 | # If the tests are run in an INSTANCE_HOME installation of Zope, |
---|
| 11 | # Products.__path__ and sys.path with be adjusted to include the |
---|
| 12 | # instance's Products and lib/python directories respectively. |
---|
| 13 | # |
---|
| 14 | # If you explicitly set INSTANCE_HOME prior to running the tests, |
---|
| 15 | # auto-detection is disabled and the specified path will be used |
---|
| 16 | # instead. |
---|
| 17 | # |
---|
| 18 | # If the 'tests' directory contains a custom_zodb.py file, INSTANCE_HOME |
---|
| 19 | # will be adjusted to use it. |
---|
| 20 | # |
---|
| 21 | # If you set the ZEO_INSTANCE_HOME environment variable a ZEO setup |
---|
| 22 | # is assumed, and you can attach to a running ZEO server (via the |
---|
| 23 | # instance's custom_zodb.py). |
---|
| 24 | # |
---|
| 25 | ############################################################################## |
---|
| 26 | # |
---|
| 27 | # The following code should be at the top of every test module: |
---|
| 28 | # |
---|
| 29 | # import os, sys |
---|
| 30 | # if __name__ == '__main__': |
---|
| 31 | # execfile(os.path.join(sys.path[0], 'framework.py')) |
---|
| 32 | # |
---|
| 33 | # ...and the following at the bottom: |
---|
| 34 | # |
---|
| 35 | # if __name__ == '__main__': |
---|
| 36 | # framework() |
---|
| 37 | # |
---|
| 38 | ############################################################################## |
---|
| 39 | |
---|
| 40 | __version__ = '0.2.3' |
---|
| 41 | |
---|
| 42 | # Save start state |
---|
| 43 | # |
---|
| 44 | __SOFTWARE_HOME = os.environ.get('SOFTWARE_HOME', '') |
---|
| 45 | __INSTANCE_HOME = os.environ.get('INSTANCE_HOME', '') |
---|
| 46 | |
---|
| 47 | if __SOFTWARE_HOME.endswith(os.sep): |
---|
| 48 | __SOFTWARE_HOME = os.path.dirname(__SOFTWARE_HOME) |
---|
| 49 | |
---|
| 50 | if __INSTANCE_HOME.endswith(os.sep): |
---|
| 51 | __INSTANCE_HOME = os.path.dirname(__INSTANCE_HOME) |
---|
| 52 | |
---|
| 53 | # Find and import the Testing package |
---|
| 54 | # |
---|
| 55 | if not sys.modules.has_key('Testing'): |
---|
| 56 | p0 = sys.path[0] |
---|
| 57 | if p0 and __name__ == '__main__': |
---|
| 58 | os.chdir(p0) |
---|
| 59 | p0 = '' |
---|
| 60 | s = __SOFTWARE_HOME |
---|
| 61 | p = d = s and s or os.getcwd() |
---|
| 62 | while d: |
---|
| 63 | if os.path.isdir(os.path.join(p, 'Testing')): |
---|
| 64 | zope_home = os.path.dirname(os.path.dirname(p)) |
---|
| 65 | sys.path[:1] = [p0, p, zope_home] |
---|
| 66 | break |
---|
| 67 | p, d = s and ('','') or os.path.split(p) |
---|
| 68 | else: |
---|
| 69 | print 'Unable to locate Testing package.', |
---|
| 70 | print 'You might need to set SOFTWARE_HOME.' |
---|
| 71 | sys.exit(1) |
---|
| 72 | |
---|
| 73 | import Testing, unittest |
---|
| 74 | execfile(os.path.join(os.path.dirname(Testing.__file__), 'common.py')) |
---|
| 75 | |
---|
| 76 | # Include ZopeTestCase support |
---|
| 77 | # |
---|
| 78 | if 1: # Create a new scope |
---|
| 79 | |
---|
| 80 | p = os.path.join(os.path.dirname(Testing.__file__), 'ZopeTestCase') |
---|
| 81 | |
---|
| 82 | if not os.path.isdir(p): |
---|
| 83 | print 'Unable to locate ZopeTestCase package.', |
---|
| 84 | print 'You might need to install ZopeTestCase.' |
---|
| 85 | sys.exit(1) |
---|
| 86 | |
---|
| 87 | ztc_common = 'ztc_common.py' |
---|
| 88 | ztc_common_global = os.path.join(p, ztc_common) |
---|
| 89 | |
---|
| 90 | f = 0 |
---|
| 91 | if os.path.exists(ztc_common_global): |
---|
| 92 | execfile(ztc_common_global) |
---|
| 93 | f = 1 |
---|
| 94 | if os.path.exists(ztc_common): |
---|
| 95 | execfile(ztc_common) |
---|
| 96 | f = 1 |
---|
| 97 | |
---|
| 98 | if not f: |
---|
| 99 | print 'Unable to locate %s.' % ztc_common |
---|
| 100 | sys.exit(1) |
---|
| 101 | |
---|
| 102 | # Debug |
---|
| 103 | # |
---|
| 104 | print 'SOFTWARE_HOME: %s' % os.environ.get('SOFTWARE_HOME', 'Not set') |
---|
| 105 | print 'INSTANCE_HOME: %s' % os.environ.get('INSTANCE_HOME', 'Not set') |
---|
| 106 | sys.stdout.flush() |
---|