Skip to content

Commit

Permalink
Silence Py3k unittest deprecations.
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Feb 20, 2014
1 parent 3f9b5cb commit 3e12e6f
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 110 deletions.
8 changes: 4 additions & 4 deletions src/zope/container/tests/test_btree.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def testStoredLength(self):
bc = BTreeContainer()
self.assertEqual(bc.__dict__['_BTreeContainer__len'](), 0)
del bc.__dict__['_BTreeContainer__len']
self.failIf('_BTreeContainer__len' in bc.__dict__)
self.assertFalse('_BTreeContainer__len' in bc.__dict__)
bc['1'] = 1
self.assertEqual(len(bc), 1)
self.assertEqual(bc.__dict__['_BTreeContainer__len'](), 1)
Expand All @@ -51,7 +51,7 @@ def testStoredLength(self):

def testBTreeContainerInterface(self):
bc = BTreeContainer()
self.assert_(verifyObject(IBTreeContainer, bc))
self.assertTrue(verifyObject(IBTreeContainer, bc))
self.checkIterable(bc.items())
self.checkIterable(bc.keys())
self.checkIterable(bc.values())
Expand Down Expand Up @@ -154,8 +154,8 @@ def testCorrectLengthWhenAddingExistingItem(self):

def checkIterable(self, iterable):
it = iter(iterable)
self.assert_(callable(it.__iter__))
self.assert_(iter(it) is it)
self.assertTrue(callable(it.__iter__))
self.assertTrue(iter(it) is it)
# Exhaust the iterator:
first_time = list(it)
self.assertRaises(StopIteration, next, it)
Expand Down
7 changes: 4 additions & 3 deletions src/zope/container/tests/test_containertraversable.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ def testAttr(self):
c = Container({'foo': foo}, {'bar': bar, 'foo': baz})

T = ContainerTraversable(c)
self.failUnless(T.traverse('foo', []) is baz)
self.failUnless(T.traverse('bar', []) is bar)
self.assertTrue(T.traverse('foo', []) is baz)
self.assertTrue(T.traverse('bar', []) is bar)

self.assertRaises(TraversalError , T.traverse, 'morebar', [])
def test_unicode_attr(self):
# test traversal with unicode
voila = Container()
c = Container({}, {u'voil\xe0': voila})
self.failUnless(ContainerTraversable(c).traverse(u'voil\xe0', []) is voila)
self.assertTrue(ContainerTraversable(c).traverse(u'voil\xe0', [])
is voila)


def test_suite():
Expand Down
6 changes: 3 additions & 3 deletions src/zope/container/tests/test_containertraverser.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ def test_itemTraversal(self):
self.traverser.publishTraverse, self.request, 'morebar')

def test_viewTraversal(self):
self.assertEquals(
self.assertEqual(
self.traverser.publishTraverse(self.request, 'viewfoo').__class__,
View)
self.assertEquals(
self.assertEqual(
self.traverser.publishTraverse(self.request, 'Foo'),
self.container)
self.assertRaises(
Expand All @@ -95,7 +95,7 @@ def test_browserDefault(self):
component.provideAdapter(
'myDefaultView', (Interface, IDefaultBrowserLayer),
IDefaultViewName)
self.assertEquals((self.subcontainer, ('@@myDefaultView',)),
self.assertEqual((self.subcontainer, ('@@myDefaultView',)),
self.traverser.browserDefault(self.request))


Expand Down
8 changes: 4 additions & 4 deletions src/zope/container/tests/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class SampleItemContainer(object):
sampleitemcontainer = SampleItemContainer()
res = zope.component.getMultiAdapter(
(sampleitemcontainer, request), IBrowserPublisher)
self.failUnless(isinstance(res, ItemTraverser))
self.failUnless(res.context is sampleitemcontainer)
self.assertTrue(isinstance(res, ItemTraverser))
self.assertTrue(res.context is sampleitemcontainer)

@implementer(ISimpleReadContainer)
class SampleSimpleReadContainer(object):
Expand All @@ -39,8 +39,8 @@ class SampleSimpleReadContainer(object):
samplesimplereadcontainer = SampleSimpleReadContainer()
res = zope.component.getMultiAdapter(
(samplesimplereadcontainer, request), IBrowserPublisher)
self.failUnless(isinstance(res, ItemTraverser))
self.failUnless(res.context is samplesimplereadcontainer)
self.assertTrue(isinstance(res, ItemTraverser))
self.assertTrue(res.context is samplesimplereadcontainer)

def test_suite():
suite = unittest.TestSuite()
Expand Down
2 changes: 1 addition & 1 deletion src/zope/container/tests/test_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_Cloner(self):
d = Directory()
d.a = 1
clone = zope.container.directory.Cloner(d)('foo')
self.assert_(clone != d)
self.assertTrue(clone != d)
self.assertEqual(clone.__class__, d.__class__)

def test_suite():
Expand Down
28 changes: 14 additions & 14 deletions src/zope/container/tests/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,30 @@ def test_idFind(self):
find = FindAdapter(tree)
# some simple searches
result = find.find([SimpleIdFindFilter(['beta'])])
self.assertEquals([beta], result)
self.assertEqual([beta], result)
result = find.find([SimpleIdFindFilter(['gamma'])])
self.assertEquals([gamma], result)
self.assertEqual([gamma], result)
result = find.find([SimpleIdFindFilter(['delta'])])
self.assertEquals([delta], result)
self.assertEqual([delta], result)
# we should not find the container we search on
result = find.find([SimpleIdFindFilter(['tree'])])
self.assertEquals([], result)
self.assertEqual([], result)
# search for multiple ids
result = find.find([SimpleIdFindFilter(['alpha', 'beta'])])
self.assertEquals([alpha, beta], result)
self.assertEqual([alpha, beta], result)
result = find.find([SimpleIdFindFilter(['beta', 'delta'])])
self.assertEquals([beta, delta], result)
self.assertEqual([beta, delta], result)
# search without any filters, find everything
result = find.find([])
self.assertEquals([alpha, beta, delta, gamma], result)
self.assertEqual([alpha, beta, delta, gamma], result)
# search for something that doesn't exist
result = find.find([SimpleIdFindFilter(['foo'])])
self.assertEquals([], result)
self.assertEqual([], result)
# find for something that has two ids at the same time,
# can't ever be the case
result = find.find([SimpleIdFindFilter(['alpha']),
SimpleIdFindFilter(['beta'])])
self.assertEquals([], result)
self.assertEqual([], result)

def test_objectFind(self):
alpha = FakeContainer('alpha', [])
Expand All @@ -126,11 +126,11 @@ def test_objectFind(self):
[alpha, beta, gamma])
find = FindAdapter(tree)
result = find.find(object_filters=[TestObjectFindFilter(0)])
self.assertEquals([alpha, delta, gamma], result)
self.assertEqual([alpha, delta, gamma], result)
result = find.find(object_filters=[TestObjectFindFilter(1)])
self.assertEquals([beta], result)
self.assertEqual([beta], result)
result = find.find(object_filters=[TestObjectFindFilter(2)])
self.assertEquals([], result)
self.assertEqual([], result)

def test_combinedFind(self):
alpha = FakeContainer('alpha', [])
Expand All @@ -143,11 +143,11 @@ def test_combinedFind(self):
find = FindAdapter(tree)
result = find.find(id_filters=[SimpleIdFindFilter(['alpha'])],
object_filters=[TestObjectFindFilter(0)])
self.assertEquals([alpha], result)
self.assertEqual([alpha], result)

result = find.find(id_filters=[SimpleIdFindFilter(['alpha'])],
object_filters=[TestObjectFindFilter(1)])
self.assertEquals([], result)
self.assertEqual([], result)

def test_interfaceFind(self):
alpha = FakeContainer('alpha', [])
Expand Down
160 changes: 80 additions & 80 deletions src/zope/container/tests/test_icontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ def test_delObject(self):
def testEmpty(self):
folder = self.makeTestObject()
data = self.makeTestData()
self.failIf(folder.keys())
self.failIf(folder.values())
self.failIf(folder.items())
self.failIf(len(folder))
self.failIf(data[6][0] in folder)
self.assertFalse(folder.keys())
self.assertFalse(folder.values())
self.assertFalse(folder.items())
self.assertFalse(len(folder))
self.assertFalse(data[6][0] in folder)

self.assertEquals(folder.get(data[6][0], None), None)
self.assertEqual(folder.get(data[6][0], None), None)
self.assertRaises(KeyError, folder.__getitem__, data[6][0])

self.assertRaises(KeyError, folder.__delitem__, data[6][0])
Expand All @@ -173,21 +173,21 @@ def testOneItem(self):
name = data[0][0]
folder[name] = foo

self.assertEquals(len(folder.keys()), 1)
self.assertEquals(list(folder.keys())[0], name)
self.assertEquals(len(folder.values()), 1)
self.assertEquals(list(folder.values())[0], foo)
self.assertEquals(len(folder.items()), 1)
self.assertEquals(list(folder.items())[0], (name, foo))
self.assertEquals(len(folder), 1)
self.assertEqual(len(folder.keys()), 1)
self.assertEqual(list(folder.keys())[0], name)
self.assertEqual(len(folder.values()), 1)
self.assertEqual(list(folder.values())[0], foo)
self.assertEqual(len(folder.items()), 1)
self.assertEqual(list(folder.items())[0], (name, foo))
self.assertEqual(len(folder), 1)

self.failUnless(name in folder)
self.assertTrue(name in folder)
# Use an arbitrary id frpm the data set; don;t just use any id, since
# there might be restrictions on their form
self.failIf(data[6][0] in folder)
self.assertFalse(data[6][0] in folder)

self.assertEquals(folder.get(name, None), foo)
self.assertEquals(folder[name], foo)
self.assertEqual(folder.get(name, None), foo)
self.assertEqual(folder[name], foo)

self.assertRaises(KeyError, folder.__getitem__, data[6][0])

Expand All @@ -196,25 +196,25 @@ def testOneItem(self):
name2 = data[1][0]
folder[name2] = foo2

self.assertEquals(len(folder.keys()), 2)
self.assertEquals(not not name2 in folder.keys(), True)
self.assertEquals(len(folder.values()), 2)
self.assertEquals(not not foo2 in folder.values(), True)
self.assertEquals(len(folder.items()), 2)
self.assertEquals(not not (name2, foo2) in folder.items(), True)
self.assertEquals(len(folder), 2)
self.assertEqual(len(folder.keys()), 2)
self.assertEqual(not not name2 in folder.keys(), True)
self.assertEqual(len(folder.values()), 2)
self.assertEqual(not not foo2 in folder.values(), True)
self.assertEqual(len(folder.items()), 2)
self.assertEqual(not not (name2, foo2) in folder.items(), True)
self.assertEqual(len(folder), 2)

del folder[name]
del folder[name2]

self.failIf(folder.keys())
self.failIf(folder.values())
self.failIf(folder.items())
self.failIf(len(folder))
self.failIf(name in folder)
self.assertFalse(folder.keys())
self.assertFalse(folder.values())
self.assertFalse(folder.items())
self.assertFalse(len(folder))
self.assertFalse(name in folder)

self.assertRaises(KeyError, folder.__getitem__, name)
self.assertEquals(folder.get(name, None), None)
self.assertEqual(folder.get(name, None), None)
self.assertRaises(KeyError, folder.__delitem__, name)

def testManyItems(self):
Expand All @@ -230,53 +230,53 @@ def testManyItems(self):
folder[name2] = objects[2]
folder[name3] = objects[3]

self.assertEquals(len(folder.keys()), len(objects))
self.failUnless(name0 in folder.keys())
self.failUnless(name1 in folder.keys())
self.failUnless(name2 in folder.keys())
self.failUnless(name3 in folder.keys())

self.assertEquals(len(folder.values()), len(objects))
self.failUnless(objects[0] in folder.values())
self.failUnless(objects[1] in folder.values())
self.failUnless(objects[2] in folder.values())
self.failUnless(objects[3] in folder.values())

self.assertEquals(len(folder.items()), len(objects))
self.failUnless((name0, objects[0]) in folder.items())
self.failUnless((name1, objects[1]) in folder.items())
self.failUnless((name2, objects[2]) in folder.items())
self.failUnless((name3, objects[3]) in folder.items())

self.assertEquals(len(folder), len(objects))

self.failUnless(name0 in folder)
self.failUnless(name1 in folder)
self.failUnless(name2 in folder)
self.failUnless(name3 in folder)
self.failIf(data[5][0] in folder)

self.assertEquals(folder.get(name0, None), objects[0])
self.assertEquals(folder[name0], objects[0])
self.assertEquals(folder.get(name1, None), objects[1])
self.assertEquals(folder[name1], objects[1])
self.assertEquals(folder.get(name2, None), objects[2])
self.assertEquals(folder[name2], objects[2])
self.assertEquals(folder.get(name3, None), objects[3])
self.assertEquals(folder[name3], objects[3])

self.assertEquals(folder.get(data[5][0], None), None)
self.assertEqual(len(folder.keys()), len(objects))
self.assertTrue(name0 in folder.keys())
self.assertTrue(name1 in folder.keys())
self.assertTrue(name2 in folder.keys())
self.assertTrue(name3 in folder.keys())

self.assertEqual(len(folder.values()), len(objects))
self.assertTrue(objects[0] in folder.values())
self.assertTrue(objects[1] in folder.values())
self.assertTrue(objects[2] in folder.values())
self.assertTrue(objects[3] in folder.values())

self.assertEqual(len(folder.items()), len(objects))
self.assertTrue((name0, objects[0]) in folder.items())
self.assertTrue((name1, objects[1]) in folder.items())
self.assertTrue((name2, objects[2]) in folder.items())
self.assertTrue((name3, objects[3]) in folder.items())

self.assertEqual(len(folder), len(objects))

self.assertTrue(name0 in folder)
self.assertTrue(name1 in folder)
self.assertTrue(name2 in folder)
self.assertTrue(name3 in folder)
self.assertFalse(data[5][0] in folder)

self.assertEqual(folder.get(name0, None), objects[0])
self.assertEqual(folder[name0], objects[0])
self.assertEqual(folder.get(name1, None), objects[1])
self.assertEqual(folder[name1], objects[1])
self.assertEqual(folder.get(name2, None), objects[2])
self.assertEqual(folder[name2], objects[2])
self.assertEqual(folder.get(name3, None), objects[3])
self.assertEqual(folder[name3], objects[3])

self.assertEqual(folder.get(data[5][0], None), None)
self.assertRaises(KeyError, folder.__getitem__, data[5][0])

del folder[name0]
self.assertEquals(len(folder), len(objects) - 1)
self.failIf(name0 in folder)
self.failIf(name0 in folder.keys())
self.assertEqual(len(folder), len(objects) - 1)
self.assertFalse(name0 in folder)
self.assertFalse(name0 in folder.keys())

self.failIf(objects[0] in folder.values())
self.failIf((name0, objects[0]) in folder.items())
self.assertFalse(objects[0] in folder.values())
self.assertFalse((name0, objects[0]) in folder.items())

self.assertEquals(folder.get(name0, None), None)
self.assertEqual(folder.get(name0, None), None)
self.assertRaises(KeyError, folder.__getitem__, name0)

self.assertRaises(KeyError, folder.__delitem__, name0)
Expand All @@ -285,14 +285,14 @@ def testManyItems(self):
del folder[name2]
del folder[name3]

self.failIf(folder.keys())
self.failIf(folder.values())
self.failIf(folder.items())
self.failIf(len(folder))
self.failIf(name0 in folder)
self.failIf(name1 in folder)
self.failIf(name2 in folder)
self.failIf(name3 in folder)
self.assertFalse(folder.keys())
self.assertFalse(folder.values())
self.assertFalse(folder.items())
self.assertFalse(len(folder))
self.assertFalse(name0 in folder)
self.assertFalse(name1 in folder)
self.assertFalse(name2 in folder)
self.assertFalse(name3 in folder)


class TestSampleContainer(BaseTestIContainer, TestCase):
Expand Down
2 changes: 1 addition & 1 deletion src/zope/container/tests/test_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Test(unittest.TestCase):
def testImplementsISized(self):
from zope.container.size import ContainerSized
sized = ContainerSized(DummyContainer(23))
self.assert_(ISized.providedBy(sized))
self.assertTrue(ISized.providedBy(sized))

def testEmptyContainer(self):
from zope.container.size import ContainerSized
Expand Down

0 comments on commit 3e12e6f

Please sign in to comment.