Skip to content

Commit

Permalink
Merge pull request #5 from zopefoundation/cleanup-deprecated-things
Browse files Browse the repository at this point in the history
Cleanup deprecated things.
  • Loading branch information
dataflake committed May 18, 2018
2 parents 539e751 + 0921f18 commit dd715c9
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -8,10 +8,12 @@ python:
install:
- pip install -U setuptools==33.1.1
- pip install zc.buildout
- pip install flake8
- buildout bootstrap
- buildout
script:
- bin/test -v1
- flake8 --doctests src setup.py
notifications:
email: false
cache:
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -6,6 +6,8 @@ Changelog

- More PEP8 compliance.

- Avoid deprecation warnings by using current API.


4.0.0 (2017-05-23)
------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -4,7 +4,7 @@ ignore =
bootstrap.py

[flake8]
ignore = N801,N802,N803,N805,N806,N812,E301
ignore = N801,N802,N803,N805,N806,N812,E301,W503
exclude = bootstrap.py

[bdist_wheel]
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Expand Up @@ -21,8 +21,9 @@
description="A BTree based implementation for Zope 2's OFS.",
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
long_description=(open('README.rst').read() + '\n' +
open('CHANGES.rst').read()),
long_description=(open('README.rst').read()
+ '\n'
+ open('CHANGES.rst').read()),
packages=find_packages('src'),
namespace_packages=['Products'],
package_dir={'': 'src'},
Expand All @@ -48,6 +49,7 @@
'Acquisition',
'BTrees',
'ExtensionClass>=4.1a1',
'future', # for `cgi/html.escape()`
'Persistence',
'six',
'Zope2 >= 4.0a5',
Expand Down
12 changes: 6 additions & 6 deletions src/Products/BTreeFolder2/BTreeFolder2.py
Expand Up @@ -14,7 +14,7 @@
"""BTreeFolder2
"""

from cgi import escape
from html import escape
from logging import getLogger
from random import randint
import sys
Expand Down Expand Up @@ -177,8 +177,8 @@ def _cleanup(self):
check(self._mt_index)
keys = set(self._tree.keys())
for key, value in self._mt_index.items():
if (key not in self._mt_index or
self._mt_index[key] is not value):
if (key not in self._mt_index
or self._mt_index[key] is not value):
raise AssertionError(
"Missing or incorrect meta_type index: %s"
% repr(key))
Expand All @@ -190,8 +190,8 @@ def _cleanup(self):
% repr(key))
return 1
except AssertionError:
LOG.warn('Detected damage to %s. Fixing now.' % path,
exc_info=sys.exc_info())
LOG.warning('Detected damage to %s. Fixing now.' % path,
exc_info=sys.exc_info())
try:
self._tree = OOBTree(self._tree)
keys = set(self._tree.keys())
Expand All @@ -205,7 +205,7 @@ def _cleanup(self):
new = len(keys)
if self._count() != new:
self._count.set(new)
except:
except Exception:
LOG.error('Failed to fix %s.' % path,
exc_info=sys.exc_info())
raise
Expand Down
56 changes: 28 additions & 28 deletions src/Products/BTreeFolder2/tests/testBTreeFolder2.py
Expand Up @@ -102,7 +102,7 @@ def testObjectValues(self):
values = self.f.objectValues()
self.assertEqual(len(values), 1)
self.assertEqual(values[0].id, 'item')
self.assert_(values[0].aq_parent is self.f)
self.assertTrue(values[0].aq_parent is self.f)

def testValues(self):
values = self.f.values()
Expand All @@ -115,7 +115,7 @@ def testObjectItems(self):
id, val = items[0]
self.assertEqual(id, 'item')
self.assertEqual(val.id, 'item')
self.assert_(val.aq_parent is self.f)
self.assertTrue(val.aq_parent is self.f)

def testItems(self):
items = self.f.items()
Expand All @@ -125,11 +125,11 @@ def testItems(self):
self.assertEqual(val.id, 'item')

def testHasKey(self):
self.assert_(self.f.hasObject('item')) # Old spelling
self.assert_(self.f.has_key('item')) # NOQA, New spelling
self.assertTrue(self.f.hasObject('item')) # Old spelling
self.assertTrue(self.f.has_key('item')) # NOQA, New spelling

def testContains(self):
self.assert_('item' in self.f)
self.assertTrue('item' in self.f)

def testDelete(self):
self.f._delOb('item')
Expand All @@ -138,13 +138,13 @@ def testDelete(self):

def testDelItem(self):
del self.f['item']
self.assert_('item' not in self.f)
self.assertTrue('item' not in self.f)
self.assertEqual(len(self.f), 0)

def testIter(self):
iterator = iter(self.f)
first = six.next(iterator)
self.assertEquals(first, 'item')
self.assertEqual(first, 'item')
self.assertRaises(StopIteration, six.next, iterator)

def testObjectMap(self):
Expand All @@ -166,16 +166,16 @@ def testCheckId(self):
def testSetObject(self):
f2 = BTreeFolder2('item2')
self.f._setObject(f2.id, f2)
self.assert_('item2' in self.f)
self.assertTrue('item2' in self.f)
self.assertEqual(self.f.objectCount(), 2)

def testWrapped(self):
# Verify that the folder returns wrapped versions of objects.
base = self.getBase(self.f._getOb('item'))
self.assert_(self.f._getOb('item') is not base)
self.assert_(self.f['item'] is not base)
self.assert_(self.f.get('item') is not base)
self.assert_(self.getBase(self.f._getOb('item')) is base)
self.assertTrue(self.f._getOb('item') is not base)
self.assertTrue(self.f['item'] is not base)
self.assertTrue(self.f.get('item') is not base)
self.assertTrue(self.getBase(self.f._getOb('item')) is base)

def testGenerateId(self):
ids = {}
Expand All @@ -201,7 +201,7 @@ def testReplace(self):
old_f._setObject(inner_f.id, inner_f)
self.ff._populateFromFolder(old_f)
self.assertEqual(self.ff.objectCount(), 1)
self.assert_('inner' in self.ff)
self.assertTrue('inner' in self.ff)
self.assertEqual(self.getBase(self.ff._getOb('inner')), inner_f)

def testObjectListing(self):
Expand All @@ -214,26 +214,26 @@ def testObjectListing(self):
self.assertEqual(info['b_end'], 2)
self.assertEqual(info['prev_batch_url'], '')
self.assertEqual(info['next_batch_url'], '')
self.assert_(info['formatted_list'].find('</select>') > 0)
self.assert_(info['formatted_list'].find('item') > 0)
self.assert_(info['formatted_list'].find('somefolder') > 0)
self.assertTrue(info['formatted_list'].find('</select>') > 0)
self.assertTrue(info['formatted_list'].find('item') > 0)
self.assertTrue(info['formatted_list'].find('somefolder') > 0)

# Ensure batching is working.
info = self.f.getBatchObjectListing({'b_count': 1})
self.assertEqual(info['b_start'], 1)
self.assertEqual(info['b_end'], 1)
self.assertEqual(info['prev_batch_url'], '')
self.assert_(info['next_batch_url'] != '')
self.assert_(info['formatted_list'].find('item') > 0)
self.assert_(info['formatted_list'].find('somefolder') < 0)
self.assertTrue(info['next_batch_url'] != '')
self.assertTrue(info['formatted_list'].find('item') > 0)
self.assertTrue(info['formatted_list'].find('somefolder') < 0)

info = self.f.getBatchObjectListing({'b_start': 2})
self.assertEqual(info['b_start'], 2)
self.assertEqual(info['b_end'], 2)
self.assert_(info['prev_batch_url'] != '')
self.assertTrue(info['prev_batch_url'] != '')
self.assertEqual(info['next_batch_url'], '')
self.assert_(info['formatted_list'].find('item') < 0)
self.assert_(info['formatted_list'].find('somefolder') > 0)
self.assertTrue(info['formatted_list'].find('item') < 0)
self.assertTrue(info['formatted_list'].find('somefolder') > 0)

def testObjectListingWithSpaces(self):
# The option list must use value attributes to preserve spaces.
Expand All @@ -243,24 +243,24 @@ def testObjectListingWithSpaces(self):
self.f.absolute_url = lambda: ''
info = self.f.getBatchObjectListing()
expect = '<option value="%s">%s</option>' % (name, name)
self.assert_(info['formatted_list'].find(expect) > 0)
self.assertTrue(info['formatted_list'].find(expect) > 0)

def testCleanup(self):
self.assert_(self.f._cleanup())
self.assertTrue(self.f._cleanup())
key = TrojanKey('a')
self.f._tree[key] = 'b'
self.assert_(self.f._cleanup())
self.assertTrue(self.f._cleanup())
key.value = 'z'

# With a key in the wrong place, there should now be damage.
self.assert_(not self.f._cleanup())
self.assertTrue(not self.f._cleanup())
# Now it's fixed.
self.assert_(self.f._cleanup())
self.assertTrue(self.f._cleanup())

from BTrees.OIBTree import OIBTree
tree = self.f._mt_index['d'] = OIBTree()
tree['e'] = 1
self.assert_(not self.f._cleanup())
self.assertTrue(not self.f._cleanup())

# Verify the management interface also works,
# but don't test return values.
Expand Down
8 changes: 7 additions & 1 deletion tox.ini
Expand Up @@ -3,7 +3,8 @@ envlist =
py27,
py34,
py35,
py36
py36,
flake8,

[testenv]
commands =
Expand All @@ -14,3 +15,8 @@ skip_install = true
deps =
setuptools==33.1.1
zc.buildout

[testenv:flake8]
basepython = python3.6
deps = flake8
commands = flake8 --doctests src tests setup.py

0 comments on commit dd715c9

Please sign in to comment.