Skip to content

Commit

Permalink
Tests are passing in Py3
Browse files Browse the repository at this point in the history
  • Loading branch information
ale-rt committed Mar 30, 2018
1 parent 015f6ed commit f8aabab
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/zc/relation/tokens.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,28 @@ object, similar to an intid utility. [#faux_intid]_
>>> class Reference(object): # see zope.app.keyreference
... def __init__(self, obj):
... self.object = obj
... def __cmp__(self, other):
... def _get_sorting_key(self):
... # this doesn't work during conflict resolution. See
... # zope.app.keyreference.persistent, 3.5 release, for current
... # best practice.
... if not isinstance(other, Reference):
... raise ValueError('can only compare with Reference objects')
... if self.object._p_jar is None or other.object._p_jar is None:
... if self.object._p_jar is None:
... raise ValueError(
... 'can only compare when both objects have connections')
... _self = (self.object._p_jar.db().database_name, self.object._p_oid)
... _other = (other.object._p_jar.db().database_name, other.object._p_oid)
... return (_self > _other) - (_self < _other)
... return self.object._p_oid or ''
... def __lt__(self, other):
... # this doesn't work during conflict resolution. See
... # zope.app.keyreference.persistent, 3.5 release, for current
... # best practice.
... if not isinstance(other, Reference):
... raise ValueError('can only compare with Reference objects')
... return self._get_sorting_key() < other._get_sorting_key()
... def __eq__(self, other):
... # this doesn't work during conflict resolution. See
... # zope.app.keyreference.persistent, 3.5 release, for current
... # best practice.
... if not isinstance(other, Reference):
... raise ValueError('can only compare with Reference objects')
... return self._get_sorting_key() == other._get_sorting_key()

Here's a simple integer identifier tool.

Expand Down Expand Up @@ -814,14 +824,15 @@ values.
... # we only want custom behavior if this is an organization
... if 'principal_id' in source or index.catalog.getValueTokens(
... 'principal_id', token):
... return
... return ''
... orgs = set((token,))
... orgs.update(index.catalog.findRelationTokens(
... {'part': token}))
... return set(index.catalog.findValueTokens(
... 'principal_id', {
... 'organization': zc.relation.catalog.Any(orgs)}))
...

>>> index = zc.relation.searchindex.Intransitive(
... ('organization', 'principal_id'), 'role_id', factory2,
... getValueTokens,
Expand Down Expand Up @@ -986,7 +997,7 @@ make the role_catalog have a .org_catalog attribute, and rely on that.
... return set(index.catalog.findValueTokens(
... 'principal_id', {
... 'organization': zc.relation.catalog.Any(orgs)}))
...
... return ''

If you are following along in the code and comparing to the originals, you may
see that this approach is a bit cleaner than the one when the relations were
Expand Down Expand Up @@ -1016,10 +1027,10 @@ Now we will fix up the the organization catalog [#compare_copy]_.
good
>>> org_names = set(dir(org_catalog))
>>> role_names = set(dir(role_catalog))
>>> org_names - role_names
set([])
>>> role_names - org_names
set(['org_catalog'])
>>> sorted(org_names - role_names)
[]
>>> sorted(role_names - org_names)
['org_catalog']

>>> def checkYnodDevsParts(catalog):
... res = sorted(catalog.findRelations(t({None: orgs['Ynod Devs']})))
Expand Down Expand Up @@ -1093,7 +1104,6 @@ Now we will fix up the the organization catalog [#compare_copy]_.
...
>>> checkAbeRolesInZookdNbd(org_catalog)
>>> checkAbeRolesInZookdNbd(role_catalog)

>>> org_catalog.removeDefaultQueryFactory(None) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
Expand Down

0 comments on commit f8aabab

Please sign in to comment.