autoformat with pyupgrade

This commit is contained in:
Bastien Gerard
2020-12-08 23:14:33 +01:00
parent c00a378776
commit eabb8f60f5
36 changed files with 207 additions and 212 deletions

View File

@@ -231,7 +231,7 @@ class TestClassMethods(unittest.TestCase):
assert BlogPost.list_indexes() == [
[("_cls", 1), ("author", 1), ("tags", 1)],
[("_cls", 1), ("author", 1), ("tags", 1), ("extra_text", 1)],
[(u"_id", 1)],
[("_id", 1)],
[("_cls", 1)],
]
@@ -288,7 +288,7 @@ class TestClassMethods(unittest.TestCase):
assert "wibble" == InheritedAbstractNamingTest._get_collection_name()
# Mixin tests
class BaseMixin(object):
class BaseMixin:
meta = {"collection": lambda c: c.__name__.lower()}
class OldMixinNamingConvention(Document, BaseMixin):
@@ -299,7 +299,7 @@ class TestClassMethods(unittest.TestCase):
== OldMixinNamingConvention._get_collection_name()
)
class BaseMixin(object):
class BaseMixin:
meta = {"collection": lambda c: c.__name__.lower()}
class BaseDocument(Document, BaseMixin):

View File

@@ -8,7 +8,7 @@ from tests.utils import MongoDBTestCase
class TestDelta(MongoDBTestCase):
def setUp(self):
super(TestDelta, self).setUp()
super().setUp()
class Person(Document):
name = StringField()

View File

@@ -10,7 +10,7 @@ __all__ = ("TestDynamicDocument",)
class TestDynamicDocument(MongoDBTestCase):
def setUp(self):
super(TestDynamicDocument, self).setUp()
super().setUp()
class Person(DynamicDocument):
name = StringField()
@@ -118,17 +118,17 @@ class TestDynamicDocument(MongoDBTestCase):
p.save()
raw_p = Person.objects.as_pymongo().get(id=p.id)
assert raw_p == {"_cls": u"Person", "_id": p.id, "name": u"Dean"}
assert raw_p == {"_cls": "Person", "_id": p.id, "name": "Dean"}
p.name = "OldDean"
p.newattr = "garbage"
p.save()
raw_p = Person.objects.as_pymongo().get(id=p.id)
assert raw_p == {
"_cls": u"Person",
"_cls": "Person",
"_id": p.id,
"name": "OldDean",
"newattr": u"garbage",
"newattr": "garbage",
}
def test_fields_containing_underscore(self):
@@ -144,14 +144,14 @@ class TestDynamicDocument(MongoDBTestCase):
p.save()
raw_p = WeirdPerson.objects.as_pymongo().get(id=p.id)
assert raw_p == {"_id": p.id, "_name": u"Dean", "name": u"Dean"}
assert raw_p == {"_id": p.id, "_name": "Dean", "name": "Dean"}
p.name = "OldDean"
p._name = "NewDean"
p._newattr1 = "garbage" # Unknown fields won't be added
p.save()
raw_p = WeirdPerson.objects.as_pymongo().get(id=p.id)
assert raw_p == {"_id": p.id, "_name": u"NewDean", "name": u"OldDean"}
assert raw_p == {"_id": p.id, "_name": "NewDean", "name": "OldDean"}
def test_dynamic_document_queries(self):
"""Ensure we can query dynamic fields"""

View File

@@ -281,9 +281,7 @@ class TestInheritance(MongoDBTestCase):
assert sorted(
[idx["key"] for idx in C._get_collection().index_information().values()]
) == sorted(
[[(u"_cls", 1), (u"b", 1)], [(u"_id", 1)], [(u"_cls", 1), (u"a", 1)]]
)
) == sorted([[("_cls", 1), ("b", 1)], [("_id", 1)], [("_cls", 1), ("a", 1)]])
def test_polymorphic_queries(self):
"""Ensure that the correct subclasses are returned from a query"""

View File

@@ -168,7 +168,7 @@ class TestDocumentInstance(MongoDBTestCase):
def __unicode__(self):
return self.title
doc = Article(title=u"привет мир")
doc = Article(title="привет мир")
assert "<Article: привет мир>" == repr(doc)
@@ -181,7 +181,7 @@ class TestDocumentInstance(MongoDBTestCase):
def __str__(self):
return None
doc = Article(title=u"привет мир")
doc = Article(title="привет мир")
assert "<Article: None>" == repr(doc)
def test_queryset_resurrects_dropped_collection(self):
@@ -521,9 +521,9 @@ class TestDocumentInstance(MongoDBTestCase):
query_op = q.db.system.profile.find({"ns": "mongoenginetest.animal"})[0]
assert query_op["op"] == "update"
if mongo_db <= MONGODB_34:
assert set(query_op["query"].keys()) == set(["_id", "is_mammal"])
assert set(query_op["query"].keys()) == {"_id", "is_mammal"}
else:
assert set(query_op["command"]["q"].keys()) == set(["_id", "is_mammal"])
assert set(query_op["command"]["q"].keys()) == {"_id", "is_mammal"}
Animal.drop_collection()
@@ -546,7 +546,7 @@ class TestDocumentInstance(MongoDBTestCase):
query_op = q.db.system.profile.find({"ns": "mongoenginetest.animal"})[0]
assert query_op["op"] == "command"
assert query_op["command"]["findAndModify"] == "animal"
assert set(query_op["command"]["query"].keys()) == set(["_id", "is_mammal"])
assert set(query_op["command"]["query"].keys()) == {"_id", "is_mammal"}
Animal.drop_collection()
@@ -1428,11 +1428,11 @@ class TestDocumentInstance(MongoDBTestCase):
coll = self.Person._get_collection()
doc = self.Person(name="John").save()
raw_doc = coll.find_one({"_id": doc.pk})
assert set(raw_doc.keys()) == set(["_id", "_cls", "name"])
assert set(raw_doc.keys()) == {"_id", "_cls", "name"}
doc.update(rename__name="first_name")
raw_doc = coll.find_one({"_id": doc.pk})
assert set(raw_doc.keys()) == set(["_id", "_cls", "first_name"])
assert set(raw_doc.keys()) == {"_id", "_cls", "first_name"}
assert raw_doc["first_name"] == "John"
def test_inserts_if_you_set_the_pk(self):
@@ -2041,7 +2041,7 @@ class TestDocumentInstance(MongoDBTestCase):
assert promoted_employee.details is None
def test_object_mixins(self):
class NameMixin(object):
class NameMixin:
name = StringField()
class Foo(EmbeddedDocument, NameMixin):
@@ -2055,7 +2055,7 @@ class TestDocumentInstance(MongoDBTestCase):
assert ["id", "name", "widgets"] == sorted(Bar._fields.keys())
def test_mixin_inheritance(self):
class BaseMixIn(object):
class BaseMixIn:
count = IntField()
data = StringField()
@@ -2929,7 +2929,7 @@ class TestDocumentInstance(MongoDBTestCase):
# $Where
assert (
u",".join(
",".join(
[
str(b)
for b in Book.objects.filter(
@@ -3303,7 +3303,7 @@ class TestDocumentInstance(MongoDBTestCase):
for node_name, node in self.nodes.items():
node.expand()
node.save(*args, **kwargs)
super(NodesSystem, self).save(*args, **kwargs)
super().save(*args, **kwargs)
NodesSystem.drop_collection()
Node.drop_collection()
@@ -3752,7 +3752,7 @@ class TestDocumentInstance(MongoDBTestCase):
_ = list(Jedi.objects) # Ensure a proper document loads without errors
# Forces a document with a wrong shape (may occur in case of migration)
value = u"I_should_be_a_dict"
value = "I_should_be_a_dict"
coll.insert_one({"light_saber": value})
with pytest.raises(InvalidDocumentError) as exc_info:
@@ -3819,7 +3819,7 @@ class ObjectKeyTestCase(MongoDBTestCase):
class DBFieldMappingTest(MongoDBTestCase):
def setUp(self):
class Fields(object):
class Fields:
w1 = BooleanField(db_field="w2")
x1 = BooleanField(db_field="x2")