Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctests don't run with PURE_PYTHON=1 on CPython #13

Closed
jamadden opened this issue Jul 27, 2017 · 1 comment
Closed

Doctests don't run with PURE_PYTHON=1 on CPython #13

jamadden opened this issue Jul 27, 2017 · 1 comment

Comments

@jamadden
Copy link
Member

There are a number of failures, many of them seem to have to do with IPersistent not being implemented anymore:

Failure in test DecoratorSpecificationDescriptor (zope.container.contained)
Failed doctest test for zope.container.contained.DecoratorSpecificationDescriptor
  File "//zope.container/src/zope/container/contained.py", line 864, in DecoratorSpecificationDescriptor

----------------------------------------------------------------------
File "//zope.container/src/zope/container/contained.py", line 901, in zope.container.contained.DecoratorSpecificationDescriptor
Failed example:
    [interface.getName() for interface in list(providedBy(D1(x)))]
Expected:
    ['I4', 'I3', 'I1', 'IContained', 'IPersistent']
Got:
    ['I4', 'I3', 'I1', 'IContained']
----------------------------------------------------------------------
File "//zope.container/src/zope/container/contained.py", line 904, in zope.container.contained.DecoratorSpecificationDescriptor
Failed example:
    [interface.getName() for interface in list(providedBy(D2(D1(x))))]
Expected:
    ['I4', 'I3', 'I1', 'IContained', 'IPersistent', 'I2']
Got:
    ['I4', 'I3', 'I1', 'IContained', 'I2']



Failure in test test_declarations_on_ContainedProxy (zope.container.tests.test_contained)
Failed doctest test for zope.container.tests.test_contained.test_declarations_on_ContainedProxy
  File "//zope.container/src/zope/container/tests/test_contained.py", line 61, in test_declarations_on_ContainedProxy

----------------------------------------------------------------------
File "//zope.container/src/zope/container/tests/test_contained.py", line 82, in zope.container.tests.test_contained.test_declarations_on_ContainedProxy
Failed example:
    tuple(zope.interface.implementedBy(ContainedProxy))
Expected:
    (<InterfaceClass zope.location.interfaces.IContained>,
     <InterfaceClass persistent.interfaces.IPersistent>)
Got:
    (<InterfaceClass zope.location.interfaces.IContained>,)
----------------------------------------------------------------------
File "//zope.container/src/zope/container/tests/test_contained.py", line 89, in zope.container.tests.test_contained.test_declarations_on_ContainedProxy
Failed example:
    tuple(zope.interface.providedBy(p))
Expected:
    (<InterfaceClass zope.container.tests.test_contained.I1>,
     <InterfaceClass zope.location.interfaces.IContained>,
     <InterfaceClass persistent.interfaces.IPersistent>)
Got:
    (<InterfaceClass zope.container.tests.test_contained.I1>, <InterfaceClass zope.location.interfaces.IContained>)
----------------------------------------------------------------------
File "//zope.container/src/zope/container/tests/test_contained.py", line 97, in zope.container.tests.test_contained.test_declarations_on_ContainedProxy
Failed example:
    tuple(zope.interface.providedBy(p))
Expected:
    (<InterfaceClass zope.container.tests.test_contained.I2>,
     <InterfaceClass zope.container.tests.test_contained.I1>,
     <InterfaceClass zope.location.interfaces.IContained>,
     <InterfaceClass persistent.interfaces.IPersistent>)
Got:
    (<InterfaceClass zope.container.tests.test_contained.I2>, <InterfaceClass zope.container.tests.test_contained.I1>, <InterfaceClass zope.location.interfaces.IContained>)
----------------------------------------------------------------------
File "//zope.container/src/zope/container/tests/test_contained.py", line 108, in zope.container.tests.test_contained.test_declarations_on_ContainedProxy
Failed example:
    tuple(zope.interface.providedBy(p))
Expected:
    (<InterfaceClass zope.container.tests.test_contained.I3>,
     <InterfaceClass zope.container.tests.test_contained.I1>,
     <InterfaceClass zope.location.interfaces.IContained>,
     <InterfaceClass persistent.interfaces.IPersistent>)
Got:
    (<InterfaceClass zope.container.tests.test_contained.I3>, <InterfaceClass zope.container.tests.test_contained.I1>, <InterfaceClass zope.location.interfaces.IContained>)

Another one possibly has to do with mixing C and Python implementations:

Failed doctest test for zope.container.tests.test_contained_zodb.test_basic_persistent_w_persistent_proxied
  File "//zope.container/src/zope/container/tests/test_contained_zodb.py", line 74, in test_basic_persistent_w_persistent_proxied

----------------------------------------------------------------------
File "//zope.container/src/zope/container/tests/test_contained_zodb.py", line 115, in zope.container.tests.test_contained_zodb.test_basic_persistent_w_persistent_proxied
Failed example:
    p2.ob.__parent__ is p2
Exception raised:
    Traceback (most recent call last):
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest zope.container.tests.test_contained_zodb.test_basic_persistent_w_persistent_proxied[15]>", line 1, in <module>
        p2.ob.__parent__ is p2
      File "//zope.container/.tox/coverage/lib/python2.7/site-packages/persistent/persistence.py", line 266, in __getattribute__
        oga(self, '_p_activate')()
      File "//zope.container/.tox/coverage/lib/python2.7/site-packages/persistent/persistence.py", line 386, in _p_activate
        jar.setstate(self)
      File "//zope.container/.tox/coverage/lib/python2.7/site-packages/ZODB/Connection.py", line 800, in setstate
        self._reader.setGhostState(obj, p)
      File "//zope.container/.tox/coverage/lib/python2.7/site-packages/ZODB/serialize.py", line 622, in setGhostState
        state = self.getState(pickle)
      File "//zope.container/.tox/coverage/lib/python2.7/site-packages/ZODB/serialize.py", line 615, in getState
        return unpickler.load()
      File "//zope.container/.tox/coverage/lib/python2.7/site-packages/zodbpickle/pickle_2.py", line 881, in load
        dispatch[key](self)
      File "//zope.container/.tox/coverage/lib/python2.7/site-packages/zodbpickle/pickle_2.py", line 938, in load_binpersid
        self.append(self.persistent_load(pid))
      File "//zope.container/.tox/coverage/lib/python2.7/site-packages/ZODB/serialize.py", line 483, in _persistent_load
        return self.load_oid(reference)
      File "//zope.container/.tox/coverage/lib/python2.7/site-packages/ZODB/serialize.py", line 565, in load_oid
        return self._conn.get(oid)
      File "//zope.container/.tox/coverage/lib/python2.7/site-packages/ZODB/Connection.py", line 255, in get
        self._cache.new_ghost(oid, obj)
      File "//zope.container/.tox/coverage/lib/python2.7/site-packages/persistent/picklecache.py", line 249, in new_ghost
        obj._p_invalidate_deactivate_helper(False)
    AttributeError: 'ContainedProxy' object has no attribute '_p_invalidate_deactivate_helper'
jamadden added a commit that referenced this issue Jul 27, 2017
Also convert test_contained.py doctests to real tests for ease of addition and debugging #13.
@jamadden jamadden mentioned this issue Jul 27, 2017
@jamadden
Copy link
Member Author

What's happening is that persistent respects the PURE_PYTHON environment variable even after it's installed:

# persistent/__init__.py
PURE_PYTHON = os.environ.get('PURE_PYTHON')
if not PURE_PYTHON:
    try:
        from persistent.cPersistence import Persistent

zope.container.contained, however, did not, only at build time:

try:
    from zope.container._zope_container_contained import ContainedProxyBase
    from zope.container._zope_container_contained import getProxiedObject
    from zope.container._zope_container_contained import setProxiedObject
except ImportError: # PyPy
    from zope.container._proxy import py_getProxiedObject as getProxiedObject
    from zope.container._proxy import py_setProxiedObject as setProxiedObject
    from zope.container._proxy import PyContainedProxyBase as ContainedProxyBase

With the usedevelop = true that's needed for coverage to work, if you happened to have a _zope_container_contained.so (platform specific) laying around in src/zope/container/ then that would still be imported...leading to a mismatch. (I happened to have one from October 2016 still for some reason.)

Distributing binary wheels on PyPI probably exacerbates this sort of problem.

This can be fixed pretty easily in contained.py by doing the same thing that persistent does:

from zope.container._proxy import py_getProxiedObject as getProxiedObject
from zope.container._proxy import py_setProxiedObject as setProxiedObject
from zope.container._proxy import PyContainedProxyBase as ContainedProxyBase
if not os.getenv('PURE_PYTHON'):
    try:
        from zope.container._zope_container_contained import ContainedProxyBase
    except ImportError: # PyPy
        pass
    else:
        from zope.container._zope_container_contained import getProxiedObject
        from zope.container._zope_container_contained import setProxiedObject

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant