Skip to content

Commit

Permalink
fix comparaison between DictProperty and dict, and ListProperty and l…
Browse files Browse the repository at this point in the history
…ist. Also fix repr & str in DictProperty
  • Loading branch information
benoitc committed Apr 22, 2009
1 parent 53f1320 commit ab62aaa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
30 changes: 20 additions & 10 deletions couchdbkit/properties_proxy.py
Expand Up @@ -20,7 +20,8 @@

import couchdbkit
from couchdbkit.properties import Property
from couchdbkit.properties_map import value_to_json, value_to_python
from couchdbkit.properties_map import value_to_json, value_to_python, \
dict_to_python, list_to_python
from couchdbkit.schema import DocumentSchema, ALLOWED_PROPERTY_TYPES
from couchdbkit.exceptions import *

Expand Down Expand Up @@ -228,8 +229,17 @@ class DictProxy(dict):
def __init__(self, d):
self._dict = d

def __repr__(self):
return repr(dict_to_python(self._dict))

def __str__(self):
return str(dict_to_python(self._dict))

def __eq__(self, other):
return self._dict is other
return dict_to_python(self._dict) == other

def __ne__(self, other):
return dict_to_python(self._dict) != other

def __getitem__(self, key):
return value_to_python(self._dict[key])
Expand Down Expand Up @@ -386,28 +396,28 @@ def __init__(self, l):
self._list = l

def __lt__(self, other):
return self._list < other
return list_to_python(self._list) < other

def __le__(self, other):
return self._list <= other
return list_to_python(self._list) <= other

def __eq__(self, other):
return self._list == other
return list_to_python(self._list) == other

def __ne__(self, other):
return self._list != other
return list_to_python(self._list) != other

def __gt__(self, other):
return self._list > other
return list_to_python(self._list) > other

def __ge__(self, other):
return self._list >= other
return list_to_python(self._list) >= other

def __repr__(self):
return repr(list(self._list))
return repr(list_to_python(self._list))

def __str__(self):
return str(self._list)
return str(list_to_python(self._list))

def __unicode__(self):
return unicode(self._list)
Expand Down
3 changes: 1 addition & 2 deletions tests/test_schema.py
Expand Up @@ -933,8 +933,7 @@ class A(Document):
a.d.update({'d2': datetime(2009, 4, 16, 16, 5, 41)})
self.assert_(a._doc['d']['d2'] == '2009-04-16T16:05:41Z')
self.assert_(a.d['d2'] == datetime(2009, 4, 16, 16, 5, 41))


self.assert_(a.d == {'s2': 'test', 's': 'test', 'd2': datetime(2009, 4, 16, 16, 5, 41), 'created': datetime(2009, 4, 16, 16, 5, 41)})


if __name__ == '__main__':
Expand Down

0 comments on commit ab62aaa

Please sign in to comment.