Commit 2908ae74 authored by Jason Madden's avatar Jason Madden

Fix __all__

Add unit tests for it and run the documentation tests that originaly caught the problem in CI.

Fixes #132
parent 3f3736b9
...@@ -18,3 +18,4 @@ dist ...@@ -18,3 +18,4 @@ dist
.eggs/ .eggs/
.dir-locals.el .dir-locals.el
pip-wheel-metadata/ pip-wheel-metadata/
htmlcov/
...@@ -17,6 +17,14 @@ python: ...@@ -17,6 +17,14 @@ python:
jobs: jobs:
include: include:
- name: Documentation
python: 3.8
install:
- pip install -U -e .[docs]
script:
- sphinx-build -b html -d docs/_build/doctrees docs docs/_build/html
- sphinx-build -b doctest -d docs/_build/doctrees docs docs/_build/doctest
after_success:
# Special Linux builds # Special Linux builds
- name: "Python: 2.7, pure (no C extensions)" - name: "Python: 2.7, pure (no C extensions)"
......
...@@ -127,8 +127,15 @@ def populate_module(mod_globals, ...@@ -127,8 +127,15 @@ def populate_module(mod_globals,
from ._base import _fix_pickle from ._base import _fix_pickle
module_name = mod_globals['__name__'] module_name = mod_globals['__name__']
# Define the Python implementations
mod_globals.update(_create_globals(module_name, key_datatype, value_datatype)) mod_globals.update(_create_globals(module_name, key_datatype, value_datatype))
# Import the C versions, if possible. Whether or not this is possible,
# this currently makes the non-`Py' suffixed names available. This should change
# if we start defining the Python classes with their natural name, only aliased
# to the 'Py` suffix (which simplifies pickling)
import_c_extension(mod_globals)
# Next, define __all__ after all the name aliasing is done.
# XXX: Maybe derive this from the values we create. # XXX: Maybe derive this from the values we create.
mod_all = ( mod_all = (
'Bucket', 'Set', 'BTree', 'TreeSet', 'Bucket', 'Set', 'BTree', 'TreeSet',
...@@ -143,10 +150,9 @@ def populate_module(mod_globals, ...@@ -143,10 +150,9 @@ def populate_module(mod_globals,
mod_globals['using64bits'] = key_datatype.using64bits or value_datatype.using64bits mod_globals['using64bits'] = key_datatype.using64bits or value_datatype.using64bits
import_c_extension(mod_globals)
# XXX: We can probably do better than fix_pickle now; # XXX: We can probably do better than fix_pickle now;
# we can know if we're going to be renaming classes # we can know if we're going to be renaming classes
# ahead of time. # ahead of time. See above.
_fix_pickle(mod_globals, module_name) _fix_pickle(mod_globals, module_name)
directlyProvides(module or sys.modules[module_name], interface) directlyProvides(module or sys.modules[module_name], interface)
......
...@@ -1972,17 +1972,23 @@ class ModuleTest(object): ...@@ -1972,17 +1972,23 @@ class ModuleTest(object):
value_type = None value_type = None
def _getModule(self): def _getModule(self):
pass pass
def testNames(self): def testNames(self):
names = ['Bucket', 'BTree', 'Set', 'TreeSet'] names = ['Bucket', 'BTree', 'Set', 'TreeSet']
mod = self._getModule()
mod_all = mod.__all__
for name in names: for name in names:
klass = getattr(self._getModule(), name) klass = getattr(mod, name)
self.assertEqual(klass.__module__, self._getModule().__name__) self.assertEqual(klass.__module__, mod.__name__)
self.assertIs(klass, getattr(self._getModule(), self.assertIs(klass, getattr(mod,
self.prefix + name)) self.prefix + name))
self.assertIn(name, mod_all)
self.assertIn(self.prefix + name, mod_all)
# BBB for zope.app.security ZCML :( # BBB for zope.app.security ZCML :(
pfx_iter = self.prefix + 'TreeIterator' pfx_iter = self.prefix + 'TreeIterator'
klass = getattr(self._getModule(), pfx_iter) klass = getattr(mod, pfx_iter)
self.assertEqual(klass.__module__, self._getModule().__name__) self.assertEqual(klass.__module__, mod.__name__)
def testModuleProvides(self): def testModuleProvides(self):
from zope.interface.verify import verifyObject from zope.interface.verify import verifyObject
...@@ -1998,25 +2004,29 @@ class ModuleTest(object): ...@@ -1998,25 +2004,29 @@ class ModuleTest(object):
elif 'I' in self.prefix: elif 'I' in self.prefix:
self.assertTrue(self._getModule().family is BTrees.family32) self.assertTrue(self._getModule().family is BTrees.family32)
def _check_union_presence(self, datatype, name):
mod = self._getModule()
if datatype.supports_value_union():
in_ = self.assertIn
has = self.assertTrue
else:
in_ = self.assertNotIn
has = self.assertFalse
in_(name, dir(mod))
has(hasattr(mod, name))
in_(name, mod.__all__)
# The weighted* functions require the value type to support unions. # The weighted* functions require the value type to support unions.
def test_weightedUnion_presence(self): def test_weightedUnion_presence(self):
if self.value_type.supports_value_union(): self._check_union_presence(self.value_type, 'weightedUnion')
self.assertTrue(hasattr(self._getModule(), 'weightedUnion'))
else:
self.assertFalse(hasattr(self._getModule(), 'weightedUnion'))
def test_weightedIntersection_presence(self): def test_weightedIntersection_presence(self):
if self.value_type.supports_value_union(): self._check_union_presence(self.value_type, 'weightedIntersection')
self.assertTrue(hasattr(self._getModule(), 'weightedIntersection'))
else:
self.assertFalse(hasattr(self._getModule(), 'weightedIntersection'))
# The multiunion function requires the key type to support unions # The multiunion function requires the key type to support unions
def test_multiunion_presence(self): def test_multiunion_presence(self):
if self.key_type.supports_value_union(): self._check_union_presence(self.key_type, 'multiunion')
self.assertTrue(hasattr(self._getModule(), 'multiunion'))
else:
self.assertFalse(hasattr(self._getModule(), 'multiunion'))
class I_SetsBase(object): class I_SetsBase(object):
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
4.7.1 (unreleased) 4.7.1 (unreleased)
================== ==================
- Nothing changed yet. - Fix the definitions of ``__all__`` in modules. In 4.7.0, they
incorrectly left out names. See `PR 132
<https://github.com/zopefoundation/BTrees/pull/132>`_.
4.7.0 (2020-03-17) 4.7.0 (2020-03-17)
...@@ -23,7 +25,6 @@ ...@@ -23,7 +25,6 @@
consistent between Python 2 and Python 3 and between 32-bit and consistent between Python 2 and Python 3 and between 32-bit and
64-bit variants. 64-bit variants.
- Make the Bucket types consistent with the BTree types as updated in - Make the Bucket types consistent with the BTree types as updated in
versions 4.3.2: Querying for keys with default comparisons or that versions 4.3.2: Querying for keys with default comparisons or that
are not integers no longer raises ``TypeError``. are not integers no longer raises ``TypeError``.
......
...@@ -223,6 +223,7 @@ setup(name='BTrees', ...@@ -223,6 +223,7 @@ setup(name='BTrees',
'docs': [ 'docs': [
'Sphinx', 'Sphinx',
'repoze.sphinx.autointerface', 'repoze.sphinx.autointerface',
'sphinx_rtd_theme',
], ],
}, },
test_suite="BTrees.tests", test_suite="BTrees.tests",
......
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