Update pre-commit and fix existing flake8 warnings once for all
This commit is contained in:
parent
1312100bc7
commit
ef7da36ac6
@ -1,13 +1,13 @@
|
|||||||
|
fail_fast: false
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/ambv/black
|
- repo: https://github.com/ambv/black
|
||||||
rev: 19.3b0
|
rev: 19.10b0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
language_version: python3
|
# language_version: python3
|
||||||
|
- repo: https://gitlab.com/pycqa/flake8
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
rev: 3.8.0a2
|
||||||
rev: v2.2.3
|
|
||||||
hooks:
|
hooks:
|
||||||
- id: trailing-whitespace
|
|
||||||
- id: end-of-file-fixer
|
|
||||||
- id: flake8
|
- id: flake8
|
||||||
|
additional_dependencies:
|
||||||
|
- flake8-import-order
|
||||||
|
@ -59,18 +59,16 @@ install:
|
|||||||
# Install Python dependencies.
|
# Install Python dependencies.
|
||||||
- pip install --upgrade pip
|
- pip install --upgrade pip
|
||||||
- pip install coveralls
|
- pip install coveralls
|
||||||
- pip install flake8 flake8-import-order
|
- pip install pre-commit
|
||||||
- pip install tox
|
- pip install tox
|
||||||
# tox dryrun to setup the tox venv (we run a mock test).
|
# tox dryrun to setup the tox venv (we run a mock test).
|
||||||
- tox -e $(echo py$TRAVIS_PYTHON_VERSION-mg$PYMONGO | tr -d . | sed -e 's/pypypy/pypy/') -- -a "-k=test_ci_placeholder"
|
- tox -e $(echo py$TRAVIS_PYTHON_VERSION-mg$PYMONGO | tr -d . | sed -e 's/pypypy/pypy/') -- -a "-k=test_ci_placeholder"
|
||||||
# Install black for Python v3.7 only.
|
|
||||||
- if [[ $TRAVIS_PYTHON_VERSION == $MAIN_PYTHON_VERSION ]]; then pip install black; fi
|
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- mkdir ${PWD}/mongodb-linux-x86_64-${MONGODB}/data
|
- mkdir ${PWD}/mongodb-linux-x86_64-${MONGODB}/data
|
||||||
- ${PWD}/mongodb-linux-x86_64-${MONGODB}/bin/mongod --dbpath ${PWD}/mongodb-linux-x86_64-${MONGODB}/data --logpath ${PWD}/mongodb-linux-x86_64-${MONGODB}/mongodb.log --fork
|
- ${PWD}/mongodb-linux-x86_64-${MONGODB}/bin/mongod --dbpath ${PWD}/mongodb-linux-x86_64-${MONGODB}/data --logpath ${PWD}/mongodb-linux-x86_64-${MONGODB}/mongodb.log --fork
|
||||||
- if [[ $TRAVIS_PYTHON_VERSION == $MAIN_PYTHON_VERSION ]]; then flake8 .; else echo "flake8 only runs on py37"; fi
|
# Run pre-commit hooks (black, flake8, etc) on entire codebase
|
||||||
- if [[ $TRAVIS_PYTHON_VERSION == $MAIN_PYTHON_VERSION ]]; then black --check .; else echo "black only runs on py37"; fi
|
- if [[ $TRAVIS_PYTHON_VERSION == $MAIN_PYTHON_VERSION ]]; then pre-commit run -a; else echo "pre-commit checks only runs on py37"; fi
|
||||||
- mongo --eval 'db.version();' # Make sure mongo is awake
|
- mongo --eval 'db.version();' # Make sure mongo is awake
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
@ -1414,7 +1414,7 @@ class TestDocumentInstance(MongoDBTestCase):
|
|||||||
assert raw_doc["first_name"] == "John"
|
assert raw_doc["first_name"] == "John"
|
||||||
|
|
||||||
def test_inserts_if_you_set_the_pk(self):
|
def test_inserts_if_you_set_the_pk(self):
|
||||||
p1 = self.Person(name="p1", id=bson.ObjectId()).save()
|
_ = self.Person(name="p1", id=bson.ObjectId()).save()
|
||||||
p2 = self.Person(name="p2")
|
p2 = self.Person(name="p2")
|
||||||
p2.id = bson.ObjectId()
|
p2.id = bson.ObjectId()
|
||||||
p2.save()
|
p2.save()
|
||||||
@ -2195,7 +2195,7 @@ class TestDocumentInstance(MongoDBTestCase):
|
|||||||
|
|
||||||
user = User(name="Mike").save()
|
user = User(name="Mike").save()
|
||||||
reviewer = User(name="John").save()
|
reviewer = User(name="John").save()
|
||||||
book = Book(author=user, reviewer=reviewer).save()
|
_ = Book(author=user, reviewer=reviewer).save()
|
||||||
|
|
||||||
reviewer.delete()
|
reviewer.delete()
|
||||||
assert Book.objects.count() == 1
|
assert Book.objects.count() == 1
|
||||||
@ -2221,7 +2221,7 @@ class TestDocumentInstance(MongoDBTestCase):
|
|||||||
|
|
||||||
user_1 = User(id=1).save()
|
user_1 = User(id=1).save()
|
||||||
user_2 = User(id=2).save()
|
user_2 = User(id=2).save()
|
||||||
book_1 = Book(id=1, author=user_2).save()
|
_ = Book(id=1, author=user_2).save()
|
||||||
book_2 = Book(id=2, author=user_1).save()
|
book_2 = Book(id=2, author=user_1).save()
|
||||||
|
|
||||||
user_2.delete()
|
user_2.delete()
|
||||||
@ -2230,7 +2230,7 @@ class TestDocumentInstance(MongoDBTestCase):
|
|||||||
assert Book.objects.get() == book_2
|
assert Book.objects.get() == book_2
|
||||||
|
|
||||||
user_3 = User(id=3).save()
|
user_3 = User(id=3).save()
|
||||||
book_3 = Book(id=3, author=user_3).save()
|
_ = Book(id=3, author=user_3).save()
|
||||||
|
|
||||||
user_3.delete()
|
user_3.delete()
|
||||||
# Deleting user_3 should also delete book_3
|
# Deleting user_3 should also delete book_3
|
||||||
@ -3204,7 +3204,7 @@ class TestDocumentInstance(MongoDBTestCase):
|
|||||||
def test_positional_creation(self):
|
def test_positional_creation(self):
|
||||||
"""Document cannot be instantiated using positional arguments."""
|
"""Document cannot be instantiated using positional arguments."""
|
||||||
with pytest.raises(TypeError) as exc_info:
|
with pytest.raises(TypeError) as exc_info:
|
||||||
person = self.Person("Test User", 42)
|
self.Person("Test User", 42)
|
||||||
|
|
||||||
expected_msg = (
|
expected_msg = (
|
||||||
"Instantiating a document with positional arguments is not "
|
"Instantiating a document with positional arguments is not "
|
||||||
@ -3606,13 +3606,13 @@ class TestDocumentInstance(MongoDBTestCase):
|
|||||||
v = StringField()
|
v = StringField()
|
||||||
|
|
||||||
class A(Document):
|
class A(Document):
|
||||||
l = ListField(EmbeddedDocumentField(B))
|
array = ListField(EmbeddedDocumentField(B))
|
||||||
|
|
||||||
A.objects.delete()
|
A.objects.delete()
|
||||||
A(l=[B(v="1"), B(v="2"), B(v="3")]).save()
|
A(array=[B(v="1"), B(v="2"), B(v="3")]).save()
|
||||||
a = A.objects.get()
|
a = A.objects.get()
|
||||||
assert a.l._instance == a
|
assert a.array._instance == a
|
||||||
for idx, b in enumerate(a.l):
|
for idx, b in enumerate(a.array):
|
||||||
assert b._instance == a
|
assert b._instance == a
|
||||||
assert idx == 2
|
assert idx == 2
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import pytest
|
|
||||||
from bson import InvalidDocument
|
from bson import InvalidDocument
|
||||||
|
import pytest
|
||||||
|
|
||||||
from mongoengine import *
|
from mongoengine import *
|
||||||
from mongoengine.base import BaseDict
|
from mongoengine.base import BaseDict
|
||||||
|
@ -152,7 +152,7 @@ class TestLazyReferenceField(MongoDBTestCase):
|
|||||||
LazyReference(BadDoc, animal.pk),
|
LazyReference(BadDoc, animal.pk),
|
||||||
):
|
):
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
p = Ocurrence(person="test", animal=bad).save()
|
Ocurrence(person="test", animal=bad).save()
|
||||||
|
|
||||||
def test_lazy_reference_query_conversion(self):
|
def test_lazy_reference_query_conversion(self):
|
||||||
"""Ensure that LazyReferenceFields can be queried using objects and values
|
"""Ensure that LazyReferenceFields can be queried using objects and values
|
||||||
@ -386,7 +386,7 @@ class TestGenericLazyReferenceField(MongoDBTestCase):
|
|||||||
mineral = Mineral(name="Granite").save()
|
mineral = Mineral(name="Granite").save()
|
||||||
|
|
||||||
occ_animal = Ocurrence(living_thing=animal, thing=animal).save()
|
occ_animal = Ocurrence(living_thing=animal, thing=animal).save()
|
||||||
occ_vegetal = Ocurrence(living_thing=vegetal, thing=vegetal).save()
|
_ = Ocurrence(living_thing=vegetal, thing=vegetal).save()
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
Ocurrence(living_thing=mineral).save()
|
Ocurrence(living_thing=mineral).save()
|
||||||
|
|
||||||
@ -458,7 +458,7 @@ class TestGenericLazyReferenceField(MongoDBTestCase):
|
|||||||
baddoc = BadDoc().save()
|
baddoc = BadDoc().save()
|
||||||
for bad in (42, "foo", baddoc, LazyReference(BadDoc, animal.pk)):
|
for bad in (42, "foo", baddoc, LazyReference(BadDoc, animal.pk)):
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
p = Ocurrence(person="test", animal=bad).save()
|
Ocurrence(person="test", animal=bad).save()
|
||||||
|
|
||||||
def test_generic_lazy_reference_query_conversion(self):
|
def test_generic_lazy_reference_query_conversion(self):
|
||||||
class Member(Document):
|
class Member(Document):
|
||||||
|
@ -116,7 +116,7 @@ class TestQueryset(unittest.TestCase):
|
|||||||
def test_limit(self):
|
def test_limit(self):
|
||||||
"""Ensure that QuerySet.limit works as expected."""
|
"""Ensure that QuerySet.limit works as expected."""
|
||||||
user_a = self.Person.objects.create(name="User A", age=20)
|
user_a = self.Person.objects.create(name="User A", age=20)
|
||||||
user_b = self.Person.objects.create(name="User B", age=30)
|
_ = self.Person.objects.create(name="User B", age=30)
|
||||||
|
|
||||||
# Test limit on a new queryset
|
# Test limit on a new queryset
|
||||||
people = list(self.Person.objects.limit(1))
|
people = list(self.Person.objects.limit(1))
|
||||||
@ -148,6 +148,11 @@ class TestQueryset(unittest.TestCase):
|
|||||||
user_b = self.Person.objects.create(name="User B", age=30)
|
user_b = self.Person.objects.create(name="User B", age=30)
|
||||||
|
|
||||||
# Test skip on a new queryset
|
# Test skip on a new queryset
|
||||||
|
people = list(self.Person.objects.skip(0))
|
||||||
|
assert len(people) == 2
|
||||||
|
assert people[0] == user_a
|
||||||
|
assert people[1] == user_b
|
||||||
|
|
||||||
people = list(self.Person.objects.skip(1))
|
people = list(self.Person.objects.skip(1))
|
||||||
assert len(people) == 1
|
assert len(people) == 1
|
||||||
assert people[0] == user_b
|
assert people[0] == user_b
|
||||||
@ -2586,13 +2591,8 @@ class TestQueryset(unittest.TestCase):
|
|||||||
age = IntField()
|
age = IntField()
|
||||||
|
|
||||||
with db_ops_tracker() as q:
|
with db_ops_tracker() as q:
|
||||||
adult1 = (
|
|
||||||
User.objects.filter(age__gte=18).comment("looking for an adult").first()
|
User.objects.filter(age__gte=18).comment("looking for an adult").first()
|
||||||
)
|
|
||||||
|
|
||||||
adult2 = (
|
|
||||||
User.objects.comment("looking for an adult").filter(age__gte=18).first()
|
User.objects.comment("looking for an adult").filter(age__gte=18).first()
|
||||||
)
|
|
||||||
|
|
||||||
ops = q.get_ops()
|
ops = q.get_ops()
|
||||||
assert len(ops) == 2
|
assert len(ops) == 2
|
||||||
@ -4518,7 +4518,7 @@ class TestQueryset(unittest.TestCase):
|
|||||||
|
|
||||||
foos_without_y = list(Foo.objects.order_by("y").fields(y=0))
|
foos_without_y = list(Foo.objects.order_by("y").fields(y=0))
|
||||||
|
|
||||||
assert all(o.y is None for o in foos_with_x)
|
assert all(o.y is None for o in foos_without_y)
|
||||||
|
|
||||||
foos_with_sliced_items = list(Foo.objects.order_by("y").fields(slice__items=1))
|
foos_with_sliced_items = list(Foo.objects.order_by("y").fields(slice__items=1))
|
||||||
|
|
||||||
@ -5595,7 +5595,7 @@ class TestQueryset(unittest.TestCase):
|
|||||||
self.Person.objects.create(name="Baz")
|
self.Person.objects.create(name="Baz")
|
||||||
assert self.Person.objects.count(with_limit_and_skip=True) == 3
|
assert self.Person.objects.count(with_limit_and_skip=True) == 3
|
||||||
|
|
||||||
newPerson = self.Person.objects.create(name="Foo_1")
|
self.Person.objects.create(name="Foo_1")
|
||||||
assert self.Person.objects.count(with_limit_and_skip=True) == 4
|
assert self.Person.objects.count(with_limit_and_skip=True) == 4
|
||||||
|
|
||||||
def test_no_cursor_timeout(self):
|
def test_no_cursor_timeout(self):
|
||||||
|
@ -348,7 +348,7 @@ class ConnectionTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_disconnect_cleans_cached_collection_attribute_in_document(self):
|
def test_disconnect_cleans_cached_collection_attribute_in_document(self):
|
||||||
"""Ensure that the disconnect() method works properly"""
|
"""Ensure that the disconnect() method works properly"""
|
||||||
conn1 = connect("mongoenginetest")
|
connect("mongoenginetest")
|
||||||
|
|
||||||
class History(Document):
|
class History(Document):
|
||||||
pass
|
pass
|
||||||
@ -518,7 +518,7 @@ class ConnectionTest(unittest.TestCase):
|
|||||||
"""Ensure connect() uses the username & password params if the URI
|
"""Ensure connect() uses the username & password params if the URI
|
||||||
doesn't explicitly specify them.
|
doesn't explicitly specify them.
|
||||||
"""
|
"""
|
||||||
c = connect(
|
connect(
|
||||||
host="mongodb://localhost/mongoenginetest", username="user", password="pass"
|
host="mongodb://localhost/mongoenginetest", username="user", password="pass"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -632,7 +632,7 @@ class ConnectionTest(unittest.TestCase):
|
|||||||
"""Ensure connect() works when specifying a replicaSet via the
|
"""Ensure connect() works when specifying a replicaSet via the
|
||||||
MongoDB URI.
|
MongoDB URI.
|
||||||
"""
|
"""
|
||||||
c = connect(host="mongodb://localhost/test?replicaSet=local-rs")
|
connect(host="mongodb://localhost/test?replicaSet=local-rs")
|
||||||
db = get_db()
|
db = get_db()
|
||||||
assert isinstance(db, pymongo.database.Database)
|
assert isinstance(db, pymongo.database.Database)
|
||||||
assert db.name == "test"
|
assert db.name == "test"
|
||||||
|
@ -216,7 +216,7 @@ class TestContextManagers:
|
|||||||
|
|
||||||
def test_query_counter_does_not_swallow_exception(self):
|
def test_query_counter_does_not_swallow_exception(self):
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
with query_counter() as q:
|
with query_counter():
|
||||||
raise TypeError()
|
raise TypeError()
|
||||||
|
|
||||||
def test_query_counter_temporarily_modifies_profiling_level(self):
|
def test_query_counter_temporarily_modifies_profiling_level(self):
|
||||||
@ -226,12 +226,12 @@ class TestContextManagers:
|
|||||||
initial_profiling_level = db.profiling_level()
|
initial_profiling_level = db.profiling_level()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
NEW_LEVEL = 1
|
new_level = 1
|
||||||
db.set_profiling_level(NEW_LEVEL)
|
db.set_profiling_level(new_level)
|
||||||
assert db.profiling_level() == NEW_LEVEL
|
assert db.profiling_level() == new_level
|
||||||
with query_counter() as q:
|
with query_counter():
|
||||||
assert db.profiling_level() == 2
|
assert db.profiling_level() == 2
|
||||||
assert db.profiling_level() == NEW_LEVEL
|
assert db.profiling_level() == new_level
|
||||||
except Exception:
|
except Exception:
|
||||||
db.set_profiling_level(
|
db.set_profiling_level(
|
||||||
initial_profiling_level
|
initial_profiling_level
|
||||||
|
@ -267,7 +267,7 @@ class TestSignal(unittest.TestCase):
|
|||||||
a = self.Author(name="Bill Shakespeare")
|
a = self.Author(name="Bill Shakespeare")
|
||||||
a.save()
|
a.save()
|
||||||
self.get_signal_output(lambda: None) # eliminate signal output
|
self.get_signal_output(lambda: None) # eliminate signal output
|
||||||
a1 = self.Author.objects(name="Bill Shakespeare")[0]
|
_ = self.Author.objects(name="Bill Shakespeare")[0]
|
||||||
|
|
||||||
assert self.get_signal_output(create_author) == [
|
assert self.get_signal_output(create_author) == [
|
||||||
"pre_init signal, Author",
|
"pre_init signal, Author",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user