Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Override equality to not use builtin cmp
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrusv committed Nov 21, 2014
1 parent 45788ee commit 17ea9cd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/mongopersist/serialize.py
Expand Up @@ -66,6 +66,12 @@ def __getitem__(self, key):
# slower. So let's not do that.
return self.data[key]

def __eq__(self, other):
return self.data == other

def __ne__(self, other):
return not self.__eq__(other)


class PersistentList(persistent.list.PersistentList):
_p_mongo_sub_object = True
Expand Down
26 changes: 26 additions & 0 deletions src/mongopersist/tests/test_serialize.py
Expand Up @@ -1039,6 +1039,32 @@ def doctest_deserialize_persistent_references():
"""


def doctest_PersistentDict_equality():
"""Test basic functions if PersistentDicts
>>> import datetime
>>> obj1 = serialize.PersistentDict({'key':'value'})
>>> obj2 = serialize.PersistentDict({'key':'value'})
>>> obj3 = serialize.PersistentDict({'key':None})
>>> obj4 = serialize.PersistentDict({'key':datetime.datetime.now()})
>>> obj1 == obj1 and obj2 == obj2 and obj3 == obj3 and obj4 == obj4
True
>>> obj1 == obj2
True
>>> obj1 == obj3
False
>>> obj1 == obj4
False
>>> obj3 == obj4
False
"""


def test_suite():
return doctest.DocTestSuite(
setUp=testing.setUp, tearDown=testing.tearDown,
Expand Down
2 changes: 1 addition & 1 deletion versions.cfg
Expand Up @@ -229,4 +229,4 @@ distribute = 0.6.36
# zope.interface==4.0.2
# zope.testing==4.1.1
# zope.testrunner==4.0.4
setuptools = 0.8
setuptools = 3.3

0 comments on commit 17ea9cd

Please sign in to comment.