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

Tests broken with recent persistent #8

Closed
jamadden opened this Issue Sep 26, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@jamadden
Member

jamadden commented Sep 26, 2018

Part of this is the difference in module reprs of persistent objects, which also differs on CPython and PyPy. This shows up in Folder:

Expected:
    [<zope.site.folder.Folder object at 0x...>,]
Got:
    [<Folder object at 0x10e076320>,

This part still works on PyPy and is annoying to fix (see zopefoundation/persistent#92).

Part of this is simply the fact that Persistent gained __repr__ different from object. Take LocalSiteManager:

class LocalSiteManager(
        BTreeContainer,
        zope.component.persistentregistry.PersistentComponents,
):

Its MRO:

>>> from zope.site.site import LocalSiteManager
>>> LocalSiteManager.mro()
[<class 'zope.site.site.LocalSiteManager'>,
 <class 'zope.container.btree.BTreeContainer'>,
 <class 'zope.container.contained.Contained'>,
 <type 'persistent.Persistent'>,
 <class 'zope.component.persistentregistry.PersistentComponents'>,
 <class 'zope.interface.registry.Components'>,
 <type 'object'>]

It was expecting to inherit its __repr__ from zope.interface.registry.Components:

class Components(object):
    def __repr__(self):
        return "<%s %s>" % (self.__class__.__name__, self.__name__)

and so print like <LocalSiteManager ++etc++site>.

But now the repr from Persistent overrides that, and we get the standard <LocalSiteManager object at 0x10e068cf8>

This can be fixed by having LSM define _p_repr:

def _p_repr(self):
    return zope.component.persistentregistry.PersistentComponents.__repr__(self)
@vernans

This comment has been minimized.

Contributor

vernans commented Oct 6, 2018

The tests were fixed with PR #9. _p_repr was implemented (thanks @jamadden) and the inconsistent behaviour regarding CPython and Pypy was handled by ellipsis, as I found testing for "Folder" was concise enough. I chose this after seeing plone/plone.testing#53

@icemac icemac closed this Oct 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment