improve tests health (flake8 warnings)

This commit is contained in:
Bastien Gérard
2019-09-01 15:03:29 +03:00
parent c61c6a8525
commit bc0c55e49a
34 changed files with 97 additions and 111 deletions

View File

@@ -1,8 +1,9 @@
import unittest
import pytest
from mongoengine import *
from tests.utils import MongoDBTestCase
import pytest
__all__ = ("TestDynamicDocument",)

View File

@@ -5,11 +5,11 @@ from datetime import datetime
from nose.plugins.skip import SkipTest
from pymongo.collation import Collation
from pymongo.errors import OperationFailure
import pytest
from six import iteritems
from mongoengine import *
from mongoengine.connection import get_db
import pytest
class TestIndexes(unittest.TestCase):

View File

@@ -2,6 +2,7 @@
import unittest
import warnings
import pytest
from six import iteritems
from mongoengine import (
@@ -17,7 +18,6 @@ from mongoengine import (
from mongoengine.pymongo_support import list_collection_names
from tests.fixtures import Base
from tests.utils import MongoDBTestCase
import pytest
class TestInheritance(MongoDBTestCase):
@@ -335,9 +335,7 @@ class TestInheritance(MongoDBTestCase):
name = StringField()
# can't inherit because Animal didn't explicitly allow inheritance
with pytest.raises(
ValueError, match="Document Animal may not be subclassed"
) as exc_info:
with pytest.raises(ValueError, match="Document Animal may not be subclassed"):
class Dog(Animal):
pass
@@ -475,7 +473,7 @@ class TestInheritance(MongoDBTestCase):
meta = {"abstract": True, "allow_inheritance": False}
city = City(continent="asia")
assert None == city.pk
assert city.pk is None
# TODO: expected error? Shouldn't we create a new error type?
with pytest.raises(KeyError):
setattr(city, "pk", 1)

View File

@@ -9,6 +9,7 @@ from datetime import datetime
import bson
from bson import DBRef, ObjectId
from pymongo.errors import DuplicateKeyError
import pytest
from six import iteritems
from mongoengine import *
@@ -36,7 +37,6 @@ from tests.fixtures import (
PickleTest,
)
from tests.utils import MongoDBTestCase, get_as_pymongo
import pytest
TEST_IMAGE_PATH = os.path.join(os.path.dirname(__file__), "../fields/mongoengine.png")
@@ -96,7 +96,7 @@ class TestInstance(MongoDBTestCase):
assert Log.objects.count() == 10
options = Log.objects._collection.options()
assert options["capped"] == True
assert options["capped"] is True
assert options["max"] == 10
assert options["size"] == 4096
@@ -122,7 +122,7 @@ class TestInstance(MongoDBTestCase):
Log().save()
options = Log.objects._collection.options()
assert options["capped"] == True
assert options["capped"] is True
assert options["max"] == 10
assert options["size"] == 10 * 2 ** 20
@@ -150,7 +150,7 @@ class TestInstance(MongoDBTestCase):
Log().save()
options = Log.objects._collection.options()
assert options["capped"] == True
assert options["capped"] is True
assert options["size"] >= 10000
# Check that the document with odd max_size value can be recreated
@@ -350,7 +350,7 @@ class TestInstance(MongoDBTestCase):
name = StringField()
meta = {"allow_inheritance": True}
with pytest.raises(ValueError, match="Cannot override primary key field") as e:
with pytest.raises(ValueError, match="Cannot override primary key field"):
class EmailUser(User):
email = StringField(primary_key=True)
@@ -620,7 +620,7 @@ class TestInstance(MongoDBTestCase):
f.reload()
def test_reload_of_non_strict_with_special_field_name(self):
"""Ensures reloading works for documents with meta strict == False."""
"""Ensures reloading works for documents with meta strict is False."""
class Post(Document):
meta = {"strict": False}
@@ -832,13 +832,13 @@ class TestInstance(MongoDBTestCase):
t = TestDocument(status="published")
t.save(clean=False)
assert t.status == "published"
assert t.cleaned == False
assert t.cleaned is False
t = TestDocument(status="published")
assert t.cleaned == False
assert t.cleaned is False
t.save(clean=True)
assert t.status == "published"
assert t.cleaned == True
assert t.cleaned is True
raw_doc = get_as_pymongo(t)
# Make sure clean changes makes it to the db
assert raw_doc == {"status": "published", "cleaned": True, "_id": t.id}
@@ -1600,7 +1600,7 @@ class TestInstance(MongoDBTestCase):
person = self.Person.objects.get()
assert person.name == "User"
assert person.age == 21
assert person.active == False
assert person.active is False
def test__get_changed_fields_same_ids_reference_field_does_not_enters_infinite_loop_embedded_doc(
self,
@@ -2521,9 +2521,9 @@ class TestInstance(MongoDBTestCase):
assert all_user_dic.get(u1, False) == "OK"
assert all_user_dic.get(u2, False) == "OK"
assert all_user_dic.get(u3, False) == "OK"
assert all_user_dic.get(u4, False) == False # New object
assert all_user_dic.get(b1, False) == False # Other object
assert all_user_dic.get(b2, False) == False # Other object
assert all_user_dic.get(u4, False) is False # New object
assert all_user_dic.get(b1, False) is False # Other object
assert all_user_dic.get(b2, False) is False # Other object
# Make sure docs are properly identified in a set (__hash__ is used
# for hashing the docs).
@@ -3216,7 +3216,7 @@ class TestInstance(MongoDBTestCase):
def test_mixed_creation(self):
"""Document cannot be instantiated using mixed arguments."""
with pytest.raises(TypeError) as exc_info:
person = self.Person("Test User", age=42)
self.Person("Test User", age=42)
expected_msg = (
"Instantiating a document with positional arguments is not "
@@ -3227,7 +3227,7 @@ class TestInstance(MongoDBTestCase):
def test_positional_creation_embedded(self):
"""Embedded document cannot be created using positional arguments."""
with pytest.raises(TypeError) as exc_info:
job = self.Job("Test Job", 4)
self.Job("Test Job", 4)
expected_msg = (
"Instantiating a document with positional arguments is not "
@@ -3238,7 +3238,7 @@ class TestInstance(MongoDBTestCase):
def test_mixed_creation_embedded(self):
"""Embedded document cannot be created using mixed arguments."""
with pytest.raises(TypeError) as exc_info:
job = self.Job("Test Job", years=4)
self.Job("Test Job", years=4)
expected_msg = (
"Instantiating a document with positional arguments is not "
@@ -3432,7 +3432,7 @@ class TestInstance(MongoDBTestCase):
meta = {"shard_key": ("id", "name")}
p = Person.from_json('{"name": "name", "age": 27}', created=True)
assert p._created == True
assert p._created is True
p.name = "new name"
p.id = "12345"
assert p.name == "new name"
@@ -3450,7 +3450,7 @@ class TestInstance(MongoDBTestCase):
meta = {"shard_key": ("id", "name")}
p = Person._from_son({"name": "name", "age": 27}, created=True)
assert p._created == True
assert p._created is True
p.name = "new name"
p.id = "12345"
assert p.name == "new name"
@@ -3463,7 +3463,7 @@ class TestInstance(MongoDBTestCase):
Person.objects.delete()
p = Person.from_json('{"name": "name"}', created=False)
assert p._created == False
assert p._created is False
assert p.id is None
# Make sure the document is subsequently persisted correctly.
@@ -3483,7 +3483,7 @@ class TestInstance(MongoDBTestCase):
p = Person.from_json(
'{"_id": "5b85a8b04ec5dc2da388296e", "name": "name"}', created=False
)
assert p._created == False
assert p._created is False
assert p._changed_fields == []
assert p.name == "name"
assert p.id == ObjectId("5b85a8b04ec5dc2da388296e")

View File

@@ -2,9 +2,10 @@
import unittest
from datetime import datetime
import pytest
from mongoengine import *
from tests.utils import MongoDBTestCase
import pytest
class TestValidatorError(MongoDBTestCase):