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
if __name__=='__main__':
sys.path.append(os.path.join(os.pardir, os.pardir, os.pardir))
here = os.curdir
here = os.getcwd()
else:
from Products.PythonScripts import tests
from App.Common import package_home
here = package_home(tests.__dict__)
here = os.path.dirname(__file__)
if not here:
here = os.getcwd()
# Test Classes
......
......@@ -13,14 +13,11 @@
"""
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
if __name__ == "__main__":
sys.path.insert(0, '../../..')
sys.path.insert(0, '..')
import ZODB
from Products.Sessions.BrowserIdManager import BrowserIdManager, BrowserIdManagerErr
from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
......
......@@ -11,8 +11,6 @@
#
##############################################################################
import sys, os, time
if __name__ == "__main__":
sys.path.insert(0, '../../..')
from Testing import makerequest
import ZODB # in order to get Persistence.Persistent working
......
if __name__=='__main__':
import sys
sys.path.insert(0, '../../..')
sys.path.insert(0, '..')
import ZODB
from ZODB.tests.MinPO import MinPO
......
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
from Testing import makerequest
import Acquisition
......
......@@ -12,9 +12,6 @@
##############################################################################
import sys, os, unittest
if __name__ == "__main__":
sys.path.insert(0, '../../..')
import ZODB
from Products.Transience.Transience import TransientObjectContainer
from Products.Transience.TransientObject import TransientObject
......
......@@ -12,9 +12,6 @@
##############################################################################
import sys, os, time, random, unittest
if __name__ == "__main__":
sys.path.insert(0, '../../..')
import ZODB
from Products.Transience.Transience import TransientObjectContainer,\
MaxTransientObjectsExceeded
......
......@@ -2,9 +2,6 @@
from string import rfind
import sys, os
if __name__=='__main__':
sys.path.append(os.path.join(os.pardir, os.pardir))
import unittest
from RestrictedPython import compile_restricted, PrintCollector
from RestrictedPython.Eval import RestrictionCapableEval
......@@ -12,12 +9,11 @@ from RestrictedPython.tests import restricted_module, security_in_syntax
from types import FunctionType
if __name__=='__main__':
sys.path.append(os.path.join(os.pardir, os.pardir))
here = os.curdir
here = os.getcwd()
else:
from App.Common import package_home
from RestrictedPython import tests
here = package_home(tests.__dict__)
here = os.path.dirname(__file__)
if not here:
here = os.getcwd()
def _getindent(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 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import os, sys
execfile(os.path.join(sys.path[0], 'framework.py'))
import unittest
from SearchIndex.Splitter import Splitter
class TestSplitter(unittest.TestCase):
class Tests(unittest.TestCase):
def testSplitNormalText(self):
text = 'this is a long string of words'
a = Splitter(text)
......@@ -40,4 +39,10 @@ class TestSplitter(unittest.TestCase):
r = map(None, a)
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 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import os, sys
execfile(os.path.join(sys.path[0], 'framework.py'))
import unittest
import ZODB
from SearchIndex.UnKeywordIndex import UnKeywordIndex
......@@ -29,7 +28,7 @@ class Dummy:
__repr__ = __str__
class TestCase( unittest.TestCase ):
class Tests( unittest.TestCase ):
"""
Test KeywordIndex objects.
"""
......@@ -172,4 +171,10 @@ class TestCase( unittest.TestCase ):
assert len(result) == 1
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 @@
#
##############################################################################
import os, sys
execfile(os.path.join(sys.path[0], 'framework.py'))
import unittest
from Testing.ZODButil import makeDB, cleanDB
......@@ -205,4 +204,10 @@ class Tests(unittest.TestCase):
self.globTest({'text':'((?ount* or get) and not wait) '
'"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 @@
#
##############################################################################
import os, sys
execfile(os.path.join(sys.path[0], 'framework.py'))
import unittest
import ZODB
from SearchIndex.UnIndex import UnIndex
......@@ -30,7 +29,7 @@ class Dummy:
__repr__ = __str__
class TestCase( unittest.TestCase ):
class Tests( unittest.TestCase ):
"""
Test FieldIndex objects.
"""
......@@ -171,4 +170,10 @@ class TestCase( unittest.TestCase ):
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 @@
##############################################################################
import sys
sys.path.insert(0, '.')
try:
from ZPublisher.HTTPRangeSupport import parseRange, optimizeRanges
except ImportError:
sys.path[0]='../..'
from ZPublisher.HTTPRangeSupport import parseRange, optimizeRanges
from ZPublisher.HTTPRangeSupport import parseRange, optimizeRanges
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