Commit 206bd882 authored by Hanno Schlichting's avatar Hanno Schlichting

Updated the remaining test assertions

parent 6220f215
......@@ -15,8 +15,8 @@ Bugs Fixed
Features Added
++++++++++++++
- Replaced failUnless with assertTrue and failIf with assertFalse in tests.
- Updated test assertions to use unittest's ``assert*`` methods in favor of
their deprecated `fail*` aliases.
2.13.0a3 (2010-08-04)
---------------------
......
......@@ -195,10 +195,10 @@ class FileTests(unittest.TestCase):
# From a file
s = "a" * (1 << 16) * 3
data, size = self.file._read_data(StringIO(s))
self.failIfEqual(data.next, None)
self.assertNotEqual(data.next, None)
# From a string
data, size = self.file._read_data(s)
self.failIfEqual(data.next, None)
self.assertNotEqual(data.next, None)
def testManageEditWithFileData(self):
self.file.manage_edit('foobar', 'text/plain', filedata='ASD')
......
......@@ -54,10 +54,10 @@ class TestOrderSupport(unittest.TestCase):
f = self._makeOne()
method = getattr(f, methodname)
if rval == 'ValueError':
self.failUnlessRaises( ValueError, method, *args )
self.assertRaises( ValueError, method, *args )
else:
self.failUnlessEqual( method(*args), rval )
self.failUnlessEqual( f.objectIds(), order )
self.assertEqual( method(*args), rval )
self.assertEqual( f.objectIds(), order )
def test_moveObjectsUp(self):
self._doCanonTest( 'moveObjectsUp',
......@@ -157,13 +157,13 @@ class TestOrderSupport(unittest.TestCase):
f.o2.isPrincipiaFolderish = True
f.o3.isPrincipiaFolderish = True
f.o4.isPrincipiaFolderish = True
self.failUnlessEqual( f.tpValues(), [f.o2, f.o3, f.o4] )
self.assertEqual( f.tpValues(), [f.o2, f.o3, f.o4] )
f.setDefaultSorting('meta_type', False)
self.failUnlessEqual( f.tpValues(), [f.o3, f.o2, f.o4] )
self.assertEqual( f.tpValues(), [f.o3, f.o2, f.o4] )
f.setDefaultSorting('position', True)
self.failUnlessEqual( f.tpValues(), [f.o4, f.o3, f.o2] )
self.assertEqual( f.tpValues(), [f.o4, f.o3, f.o2] )
def test_suite():
......
......@@ -248,12 +248,12 @@ class TestTraverse( unittest.TestCase ):
self.assertTrue(self.folder1.unrestrictedTraverse( '/folder1/'))
def testTraverseToNone( self ):
self.failUnlessRaises(
self.assertRaises(
KeyError,
self.folder1.unrestrictedTraverse, ('', 'folder1', 'file2' ) )
self.failUnlessRaises(
self.assertRaises(
KeyError, self.folder1.unrestrictedTraverse, '/folder1/file2' )
self.failUnlessRaises(
self.assertRaises(
KeyError, self.folder1.unrestrictedTraverse, '/folder1/file2/' )
def testTraverseMethodRestricted(self):
......@@ -272,7 +272,7 @@ class TestTraverse( unittest.TestCase ):
# Zope security policy.
self._setupSecurity()
bb = self._makeBoboTraversable()
self.failUnlessRaises(KeyError, bb.restrictedTraverse, 'notfound')
self.assertRaises(KeyError, bb.restrictedTraverse, 'notfound')
bb.restrictedTraverse('bb_subitem')
def testBoboTraverseToMethod(self):
......@@ -323,7 +323,7 @@ class TestTraverse( unittest.TestCase ):
folder.manage_permission(access_contents_information, [], 0)
bb = self._makeBoboTraversableWithAcquisition()
bb = bb.__of__(self.root)
self.failUnlessRaises(Unauthorized,
self.assertRaises(Unauthorized,
bb.restrictedTraverse, 'folder1')
def testBoboTraverseToAcquiredAttribute(self):
......@@ -349,7 +349,7 @@ class TestTraverse( unittest.TestCase ):
folder.stuff = 'stuff here'
bb = self._makeBoboTraversableWithAcquisition()
bb = bb.__of__(folder)
self.failUnlessRaises(Unauthorized,
self.assertRaises(Unauthorized,
self.root.folder1.restrictedTraverse, 'stuff')
def testBoboTraverseTraversalDefault(self):
......@@ -389,7 +389,7 @@ class TestTraverse( unittest.TestCase ):
self._setupSecurity(CruelSecurityPolicy())
newSecurityManager( None, self._makeUser().__of__( self.root ) )
self.root.stuff = 'stuff here'
self.failUnlessRaises(Unauthorized,
self.assertRaises(Unauthorized,
self.app.folder1.restrictedTraverse, 'stuff')
def testDefaultValueWhenUnathorized(self):
......
......@@ -123,7 +123,7 @@ class UserFolderTests(unittest.TestCase):
uf = self._makeOne(app)
user = uf.validate(app.REQUEST, self._makeBasicAuthToken(),
['role1'])
self.failIfEqual(user, None)
self.assertNotEqual(user, None)
self.assertEqual(user.getUserName(), 'user1')
def testNotValidateWithoutAuth(self):
......
......@@ -135,7 +135,7 @@ class TypeSniffingTestCase(unittest.TestCase):
f.close()
pt = PageTemplateFile(self.TEMPFILENAME)
pt_id = pt.getId()
self.failUnlessEqual(
self.assertEqual(
pt_id, desired_id,
'getId() returned %r. Expecting %r' % (pt_id, desired_id)
)
......@@ -148,7 +148,7 @@ class TypeSniffingTestCase(unittest.TestCase):
f.close()
pt = PageTemplateFile(self.TEMPFILENAME)
pt_path = pt.getPhysicalPath()
self.failUnlessEqual(
self.assertEqual(
pt_path, desired_path,
'getPhysicalPath() returned %r. Expecting %r' % (
desired_path, pt_path,
......
......@@ -136,8 +136,8 @@ class DI_Tests(unittest.TestCase):
result, used = index._apply_index(req)
if hasattr(result, 'keys'):
result = result.keys()
self.failUnlessEqual(used, ('date',))
self.failUnlessEqual(len(result), len(expectedValues),
self.assertEqual(used, ('date',))
self.assertEqual(len(result), len(expectedValues),
'%s | %s' % (result, expectedValues))
for k, v in expectedValues:
self.assertTrue(k in result)
......@@ -175,8 +175,8 @@ class DI_Tests(unittest.TestCase):
from DateTime import DateTime
index = self._makeOne()
self.failUnlessEqual(len(index), 0)
self.failUnlessEqual(len(index.referencedObjects()), 0)
self.assertEqual(len(index), 0)
self.assertEqual(len(index.referencedObjects()), 0)
self.assertTrue(index.getEntryForObject(1234) is None)
marker = []
......@@ -185,7 +185,7 @@ class DI_Tests(unittest.TestCase):
self.assertTrue(index.hasUniqueValuesFor('date'))
self.assertFalse(index.hasUniqueValuesFor('foo'))
self.failUnlessEqual(len(index.uniqueValues('date')), 0)
self.assertEqual(len(index.uniqueValues('date')), 0)
self.assertTrue(index._apply_index({'zed': 12345}) is None)
......@@ -211,8 +211,8 @@ class DI_Tests(unittest.TestCase):
self._populateIndex(index)
values = self._getValues()
self.failUnlessEqual(len(index), len(values) - 2) # One dupe, one empty
self.failUnlessEqual(len(index.referencedObjects()), len(values) - 1)
self.assertEqual(len(index), len(values) - 2) # One dupe, one empty
self.assertEqual(len(index.referencedObjects()), len(values) - 1)
# One empty
self.assertTrue(index.getEntryForObject(1234) is None)
......@@ -222,10 +222,10 @@ class DI_Tests(unittest.TestCase):
for k, v in values:
if v.date():
self.failUnlessEqual(index.getEntryForObject(k),
self.assertEqual(index.getEntryForObject(k),
self._convert(v.date()))
self.failUnlessEqual(len(index.uniqueValues('date')), len(values) - 2)
self.assertEqual(len(index.uniqueValues('date')), len(values) - 2)
self.assertTrue(index._apply_index({'bar': 123}) is None)
self._checkApply(index,
......@@ -258,7 +258,7 @@ class DI_Tests(unittest.TestCase):
# and still correct for item 10
yr, mo, dy, hr, mn = v.date().utctimetuple()[:5]
val = (((yr * 12 + mo) * 31 + dy) * 24 + hr) * 60 + mn
self.failUnlessEqual(index.getEntryForObject(k), val)
self.assertEqual(index.getEntryForObject(k), val)
def test_removal(self):
""" DateIndex would hand back spurious entries when used as a
......
......@@ -36,7 +36,7 @@ class TestTransientObject(TestCase):
def test_id(self):
t = self.t.new('xyzzy')
self.failIfEqual(t.getId(), 'xyzzy') # dont acquire
self.assertNotEqual(t.getId(), 'xyzzy') # dont acquire
self.assertEqual(t.getContainerKey(), 'xyzzy')
def test_validate(self):
......@@ -62,12 +62,12 @@ class TestTransientObject(TestCase):
def test_getLastModifiedSet(self):
t = self.t.new('xyzzy')
t['a'] = 1
self.failIfEqual(t.getLastModified(), None)
self.assertNotEqual(t.getLastModified(), None)
def testSetLastModified(self):
t = self.t.new('xyzzy')
t.setLastModified()
self.failIfEqual(t.getLastModified(), None)
self.assertNotEqual(t.getLastModified(), None)
def test_setLastAccessed(self):
t = self.t.new('xyzzy')
......
......@@ -372,17 +372,17 @@ class TestRequestVariables(base.TestCase):
def testRequestVariables(self):
request = self.app.REQUEST
self.failIfEqual(request.get('SERVER_NAME', ''), '')
self.failIfEqual(request.get('SERVER_PORT', ''), '')
self.failIfEqual(request.get('REQUEST_METHOD', ''), '')
self.failIfEqual(request.get('URL', ''), '')
self.failIfEqual(request.get('SERVER_URL', ''), '')
self.failIfEqual(request.get('URL0', ''), '')
self.failIfEqual(request.get('URL1', ''), '')
self.failIfEqual(request.get('BASE0', ''), '')
self.failIfEqual(request.get('BASE1', ''), '')
self.failIfEqual(request.get('BASE2', ''), '')
self.failIfEqual(request.get('ACTUAL_URL', ''), '')
self.assertNotEqual(request.get('SERVER_NAME', ''), '')
self.assertNotEqual(request.get('SERVER_PORT', ''), '')
self.assertNotEqual(request.get('REQUEST_METHOD', ''), '')
self.assertNotEqual(request.get('URL', ''), '')
self.assertNotEqual(request.get('SERVER_URL', ''), '')
self.assertNotEqual(request.get('URL0', ''), '')
self.assertNotEqual(request.get('URL1', ''), '')
self.assertNotEqual(request.get('BASE0', ''), '')
self.assertNotEqual(request.get('BASE1', ''), '')
self.assertNotEqual(request.get('BASE2', ''), '')
self.assertNotEqual(request.get('ACTUAL_URL', ''), '')
import gc
......
......@@ -70,7 +70,7 @@ class TestCopyPaste(ZopeTestCase.ZopeTestCase):
# _p_oids are None until we commit a subtransaction
self.assertEqual(self.folder._p_oid, None)
transaction.savepoint(optimistic=True)
self.failIfEqual(self.folder._p_oid, None)
self.assertNotEqual(self.folder._p_oid, None)
def testCutPaste(self):
cb = self.folder.manage_cutObjects(['doc'])
......@@ -121,7 +121,7 @@ class TestImportExport(ZopeTestCase.ZopeTestCase):
# _p_oids are None until we commit a subtransaction
self.assertEqual(self.folder._p_oid, None)
transaction.savepoint(optimistic=True)
self.failIfEqual(self.folder._p_oid, None)
self.assertNotEqual(self.folder._p_oid, None)
def testExport(self):
self.folder.manage_exportObject('doc')
......
......@@ -260,7 +260,7 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
folder._setObject('objWithBD', self._makeObjectWithBD())
folder.objWithBD._default_path = ['']
r = self._makeOne(root)
self.failUnlessRaises(NotFound, r.traverse, 'folder/objWithBD')
self.assertRaises(NotFound, r.traverse, 'folder/objWithBD')
def test_traverse_withBBT_handles_AttributeError(self):
# Test that if __bobo_traverse__ raises AttributeError
......@@ -273,7 +273,7 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
obj.__bobo_traverse__ = _faux___bobo_traverse__
folder._setObject('objWithBBT', obj)
r = self._makeOne(root)
self.failUnlessRaises(NotFound, r.traverse,
self.assertRaises(NotFound, r.traverse,
'folder/objWithBBT/bbt_foo')
def test_traverse_UseTraversalDefault(self):
......@@ -309,7 +309,7 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
folder._setObject('objWithBDBBT', self._makeObjectWithBDBBT())
folder.objWithBDBBT._default_path = ['xxx']
r = self._makeOne(root)
self.failUnlessRaises(NotFound, r.traverse, 'folder/objWithBDBBT')
self.assertRaises(NotFound, r.traverse, 'folder/objWithBDBBT')
def test_traverse_slash(self):
root, folder = self._makeRootAndFolder()
......
......@@ -25,10 +25,10 @@ class MapplyTests(unittest.TestCase):
return '%d%d%d' % (a, b, c)
values = {'a':2, 'b':3, 'c':5}
v = mapply(compute, (), values)
self.failUnlessEqual(v, '235')
self.assertEqual(v, '235')
v = mapply(compute, (7,), values)
self.failUnlessEqual(v, '735')
self.assertEqual(v, '735')
def testClass(self):
values = {'a':2, 'b':3, 'c':5}
......@@ -39,11 +39,11 @@ class MapplyTests(unittest.TestCase):
compute = __call__
cc = c()
v = mapply(cc, (), values)
self.failUnlessEqual(v, '335')
self.assertEqual(v, '335')
del values['c']
v = mapply(cc.compute, (), values)
self.failUnlessEqual(v, '334')
self.assertEqual(v, '334')
class c2:
"""Must be a classic class."""
......@@ -51,7 +51,7 @@ class MapplyTests(unittest.TestCase):
c2inst = c2()
c2inst.__call__ = cc
v = mapply(c2inst, (), values)
self.failUnlessEqual(v, '334')
self.assertEqual(v, '334')
def testObjectWithCall(self):
# Make sure that the __call__ of an object can also be another
......
......@@ -156,7 +156,7 @@ class ZopeStarterTestCase(test_logger.LoggingTestBase):
# XXX need to check that log messages get written to
# sys.stderr, not that the stream identity for the startup
# handler matches
#self.failUnlessEqual(starter.startup_handler.stream, sys.stderr)
#self.assertEqual(starter.startup_handler.stream, sys.stderr)
conf = self.load_config_text("""
instancehome <<INSTANCE_HOME>>
debug-mode off
......@@ -172,7 +172,7 @@ class ZopeStarterTestCase(test_logger.LoggingTestBase):
# XXX need to check that log messages get written to
# sys.stderr, not that the stream identity for the startup
# handler matches
#self.failIfEqual(starter.startup_handler.stream, sys.stderr)
#self.assertNotEqual(starter.startup_handler.stream, sys.stderr)
def testSetupZServerThreads(self):
conf = self.load_config_text("""
......@@ -361,7 +361,7 @@ class ZopeStarterTestCase(test_logger.LoggingTestBase):
try:
starter = self.get_starter(conf)
starter.setupInterpreter()
self.failUnlessEqual( sys.getcheckinterval() , newcheckinterval )
self.assertEqual( sys.getcheckinterval() , newcheckinterval )
finally:
sys.setcheckinterval(oldcheckinterval)
......@@ -385,7 +385,7 @@ class ZopeStarterTestCase(test_logger.LoggingTestBase):
f.close()
configure(fname)
new_config = getConfiguration()
self.failUnlessEqual(new_config.zserver_threads, 100)
self.assertEqual(new_config.zserver_threads, 100)
finally:
sys.argv = old_argv
try:
......
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