fix from code review regarding py2py3 compat

This commit is contained in:
Bastien Gérard 2019-07-19 21:50:47 +02:00
parent 82af5e4a19
commit 64c0cace85
3 changed files with 10 additions and 9 deletions

View File

@ -28,8 +28,8 @@ Python 2/3 compatibility
The codebase is written in a compatible manner for python 2 & 3 so it The codebase is written in a compatible manner for python 2 & 3 so it
is important that this is taken into account when it comes to discrepencies is important that this is taken into account when it comes to discrepencies
between the 2 versions (check this https://python-future.org/compatible_idioms.html). between the two versions (see https://python-future.org/compatible_idioms.html).
Travis runs run the tests against the different versions as a safety net. Travis runs the tests against different Python versions as a safety net.
Style Guide Style Guide

View File

@ -1,6 +1,7 @@
import weakref import weakref
from bson import DBRef from bson import DBRef
from future.utils import listitems
import six import six
from six import iteritems from six import iteritems
@ -422,10 +423,10 @@ class StrictDict(object):
return len(list(iteritems(self))) return len(list(iteritems(self)))
def __eq__(self, other): def __eq__(self, other):
return list(self.items()) == list(other.items()) return listitems(self) == listitems(other)
def __ne__(self, other): def __ne__(self, other):
return list(self.items()) != list(other.items()) return not(self == other)
@classmethod @classmethod
def create(cls, allowed_keys): def create(cls, allowed_keys):

View File

@ -267,12 +267,12 @@ class TestSequenceField(MongoDBTestCase):
foo = Foo(name="Foo") foo = Foo(name="Foo")
foo.save() foo.save()
assert not ( assert (
"base.counter" in self.db["mongoengine.counters"].find().distinct("_id") "base.counter" not in self.db["mongoengine.counters"].find().distinct("_id")
) )
assert ("foo.counter" and "bar.counter") in self.db[ existing_counters = self.db["mongoengine.counters"].find().distinct("_id")
"mongoengine.counters" assert "foo.counter" in existing_counters
].find().distinct("_id") assert "bar.counter" in existing_counters
assert foo.counter == bar.counter assert foo.counter == bar.counter
assert foo._fields["counter"].owner_document == Foo assert foo._fields["counter"].owner_document == Foo
assert bar._fields["counter"].owner_document == Bar assert bar._fields["counter"].owner_document == Bar