Commit 8743e46f authored by Shane Hathaway's avatar Shane Hathaway

It's really not safe for unit test modules to change sys.path. Doing

so makes the full suite brittle.  Cleaned out all the places where unit
tests change sys.path.  (Use the PYTHONPATH environment variable instead.)

Also brought SearchIndex tests up to date, which I didn't really need to do
since SearchIndex is deprecated, but I did it as part of figuring out the
failed Interface tests, so I might as well check in my work. ;-)  One of the
test modules in SearchIndex forgets to define a global named "Dummy",
actually, so all the tests were failing before this checkin anyway.
parent bb5fbf58
...@@ -19,12 +19,11 @@ from AccessControl.SecurityManagement import noSecurityManager ...@@ -19,12 +19,11 @@ from AccessControl.SecurityManagement import noSecurityManager
if __name__=='__main__': if __name__=='__main__':
sys.path.append(os.path.join(os.pardir, os.pardir, os.pardir)) here = os.getcwd()
here = os.curdir
else: else:
from Products.PythonScripts import tests here = os.path.dirname(__file__)
from App.Common import package_home if not here:
here = package_home(tests.__dict__) here = os.getcwd()
# Test Classes # Test Classes
......
...@@ -13,14 +13,11 @@ ...@@ -13,14 +13,11 @@
""" """
Test suite for session id manager. Test suite for session id manager.
$Id: testBrowserIdManager.py,v 1.7 2001/11/28 15:51:08 matt Exp $ $Id: testBrowserIdManager.py,v 1.8 2002/06/12 20:39:18 shane Exp $
""" """
__version__ = "$Revision: 1.7 $"[11:-2] __version__ = "$Revision: 1.8 $"[11:-2]
import sys import sys
if __name__ == "__main__":
sys.path.insert(0, '../../..')
sys.path.insert(0, '..')
import ZODB import ZODB
from Products.Sessions.BrowserIdManager import BrowserIdManager, BrowserIdManagerErr from Products.Sessions.BrowserIdManager import BrowserIdManager, BrowserIdManagerErr
from unittest import TestCase, TestSuite, TextTestRunner, makeSuite from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
# #
############################################################################## ##############################################################################
import sys, os, time import sys, os, time
if __name__ == "__main__":
sys.path.insert(0, '../../..')
from Testing import makerequest from Testing import makerequest
import ZODB # in order to get Persistence.Persistent working import ZODB # in order to get Persistence.Persistent working
......
if __name__=='__main__':
import sys
sys.path.insert(0, '../../..')
sys.path.insert(0, '..')
import ZODB import ZODB
from ZODB.tests.MinPO import MinPO from ZODB.tests.MinPO import MinPO
......
import sys, os, time, unittest import sys, os, time, unittest
if __name__=='__main__':
sys.path.insert(0, '..')
sys.path.insert(0, '../../..')
import ZODB # in order to get Persistence.Persistent working import ZODB # in order to get Persistence.Persistent working
from Testing import makerequest from Testing import makerequest
import Acquisition import Acquisition
......
...@@ -12,9 +12,6 @@ ...@@ -12,9 +12,6 @@
############################################################################## ##############################################################################
import sys, os, unittest import sys, os, unittest
if __name__ == "__main__":
sys.path.insert(0, '../../..')
import ZODB import ZODB
from Products.Transience.Transience import TransientObjectContainer from Products.Transience.Transience import TransientObjectContainer
from Products.Transience.TransientObject import TransientObject from Products.Transience.TransientObject import TransientObject
......
...@@ -12,9 +12,6 @@ ...@@ -12,9 +12,6 @@
############################################################################## ##############################################################################
import sys, os, time, random, unittest import sys, os, time, random, unittest
if __name__ == "__main__":
sys.path.insert(0, '../../..')
import ZODB import ZODB
from Products.Transience.Transience import TransientObjectContainer,\ from Products.Transience.Transience import TransientObjectContainer,\
MaxTransientObjectsExceeded MaxTransientObjectsExceeded
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
from string import rfind from string import rfind
import sys, os import sys, os
if __name__=='__main__':
sys.path.append(os.path.join(os.pardir, os.pardir))
import unittest import unittest
from RestrictedPython import compile_restricted, PrintCollector from RestrictedPython import compile_restricted, PrintCollector
from RestrictedPython.Eval import RestrictionCapableEval from RestrictedPython.Eval import RestrictionCapableEval
...@@ -12,12 +9,11 @@ from RestrictedPython.tests import restricted_module, security_in_syntax ...@@ -12,12 +9,11 @@ from RestrictedPython.tests import restricted_module, security_in_syntax
from types import FunctionType from types import FunctionType
if __name__=='__main__': if __name__=='__main__':
sys.path.append(os.path.join(os.pardir, os.pardir)) here = os.getcwd()
here = os.curdir
else: else:
from App.Common import package_home here = os.path.dirname(__file__)
from RestrictedPython import tests if not here:
here = package_home(tests.__dict__) here = os.getcwd()
def _getindent(line): def _getindent(line):
"""Returns the indentation level of the given line.""" """Returns the indentation level of the given line."""
......
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# 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
#
##############################################################################
######################################################################
# Set up unit testing framework
#
# The following code should be at the top of every test module:
#
# import os, sys
# execfile(os.path.join(sys.path[0], 'framework.py'))
#
# ...and the following at the bottom:
#
# framework()
# Find the Testing package
if not sys.modules.has_key('Testing'):
p0 = sys.path[0]
if p0 and __name__ == '__main__':
os.chdir(p0)
p0 = ''
p = d = os.path.abspath(os.curdir)
while d:
if os.path.isdir(os.path.join(p, 'Testing')):
sys.path[:1] = [p0, os.pardir, p]
break
p, d = os.path.split(p)
else:
print 'Unable to locate Testing package.'
sys.exit(1)
import Testing, unittest
execfile(os.path.join(os.path.split(Testing.__file__)[0], 'common.py'))
...@@ -10,12 +10,11 @@ ...@@ -10,12 +10,11 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
import os, sys import unittest
execfile(os.path.join(sys.path[0], 'framework.py'))
from SearchIndex.Splitter import Splitter from SearchIndex.Splitter import Splitter
class TestSplitter(unittest.TestCase): class Tests(unittest.TestCase):
def testSplitNormalText(self): def testSplitNormalText(self):
text = 'this is a long string of words' text = 'this is a long string of words'
a = Splitter(text) a = Splitter(text)
...@@ -40,4 +39,10 @@ class TestSplitter(unittest.TestCase): ...@@ -40,4 +39,10 @@ class TestSplitter(unittest.TestCase):
r = map(None, a) r = map(None, a)
assert r == ['without', 'you', 'nothing'], r assert r == ['without', 'you', 'nothing'], r
framework() def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Tests),
))
if __name__=='__main__':
unittest.main(defaultTest='test_suite')
...@@ -10,8 +10,7 @@ ...@@ -10,8 +10,7 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
import os, sys import unittest
execfile(os.path.join(sys.path[0], 'framework.py'))
import ZODB import ZODB
from SearchIndex.UnKeywordIndex import UnKeywordIndex from SearchIndex.UnKeywordIndex import UnKeywordIndex
...@@ -29,7 +28,7 @@ class Dummy: ...@@ -29,7 +28,7 @@ class Dummy:
__repr__ = __str__ __repr__ = __str__
class TestCase( unittest.TestCase ): class Tests( unittest.TestCase ):
""" """
Test KeywordIndex objects. Test KeywordIndex objects.
""" """
...@@ -172,4 +171,10 @@ class TestCase( unittest.TestCase ): ...@@ -172,4 +171,10 @@ class TestCase( unittest.TestCase ):
assert len(result) == 1 assert len(result) == 1
assert result[0] == 8 assert result[0] == 8
framework() def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Tests),
))
if __name__=='__main__':
unittest.main(defaultTest='test_suite')
...@@ -11,8 +11,7 @@ ...@@ -11,8 +11,7 @@
# #
############################################################################## ##############################################################################
import os, sys import unittest
execfile(os.path.join(sys.path[0], 'framework.py'))
from Testing.ZODButil import makeDB, cleanDB from Testing.ZODButil import makeDB, cleanDB
...@@ -205,4 +204,10 @@ class Tests(unittest.TestCase): ...@@ -205,4 +204,10 @@ class Tests(unittest.TestCase):
self.globTest({'text':'((?ount* or get) and not wait) ' self.globTest({'text':'((?ount* or get) and not wait) '
'"been *ert*"'}, [0, 1, 5, 6]) '"been *ert*"'}, [0, 1, 5, 6])
framework() def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Tests),
))
if __name__=='__main__':
unittest.main(defaultTest='test_suite')
...@@ -11,8 +11,7 @@ ...@@ -11,8 +11,7 @@
# #
############################################################################## ##############################################################################
import os, sys import unittest
execfile(os.path.join(sys.path[0], 'framework.py'))
import ZODB import ZODB
from SearchIndex.UnIndex import UnIndex from SearchIndex.UnIndex import UnIndex
...@@ -30,7 +29,7 @@ class Dummy: ...@@ -30,7 +29,7 @@ class Dummy:
__repr__ = __str__ __repr__ = __str__
class TestCase( unittest.TestCase ): class Tests( unittest.TestCase ):
""" """
Test FieldIndex objects. Test FieldIndex objects.
""" """
...@@ -171,4 +170,10 @@ class TestCase( unittest.TestCase ): ...@@ -171,4 +170,10 @@ class TestCase( unittest.TestCase ):
assert r==expect, r assert r==expect, r
framework() def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Tests),
))
if __name__=='__main__':
unittest.main(defaultTest='test_suite')
...@@ -12,12 +12,7 @@ ...@@ -12,12 +12,7 @@
############################################################################## ##############################################################################
import sys import sys
sys.path.insert(0, '.') from ZPublisher.HTTPRangeSupport import parseRange, optimizeRanges
try:
from ZPublisher.HTTPRangeSupport import parseRange, optimizeRanges
except ImportError:
sys.path[0]='../..'
from ZPublisher.HTTPRangeSupport import parseRange, optimizeRanges
import unittest import unittest
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment