Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pre-commit, add isort and fix imports #77

Merged
merged 8 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
repos:
- repo: [email protected]:pre-commit/pre-commit-hooks
rev: v2.1.0
rev: v3.1.0
hooks:
- id: check-added-large-files
- id: debug-statements
- id: end-of-file-fixer
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.6
rev: 3.8.3
hooks:
- id: flake8
- repo: https://gitlab.com/pycqa/pydocstyle
rev: 4.0.1
- repo: https://github.com/timothycrosley/isort
rev: 4.3.21
hooks:
- id: isort
- repo: https://github.com/PyCQA/pydocstyle
rev: 5.0.2
hooks:
- id: pydocstyle
- repo: https://github.com/ambv/black
rev: stable
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased](https://github.com/model-bakers/model_bakery/tree/master)

### Added
- Add isort and fix imports [PR #77](https://github.com/model-bakers/model_bakery/pull/77)

### Changed
- Enable `seq` to be imported from `baker` [PR #76](https://github.com/model-bakers/model_bakery/pull/76)
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ release:
@twine upload dist/*

.PHONY: test release

2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
21 changes: 10 additions & 11 deletions model_bakery/baker.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
from os.path import dirname, join

from django.apps import apps
from django.conf import settings
from django.contrib import contenttypes
from django.apps import apps

from django.db.models.base import ModelBase
from django.db.models import (
ForeignKey,
ManyToManyField,
OneToOneField,
Field,
AutoField,
BooleanField,
Field,
FileField,
ForeignKey,
ManyToManyField,
OneToOneField,
)
from django.db.models.base import ModelBase
from django.db.models.fields.proxy import OrderWrt
from django.db.models.fields.related import (
ReverseManyToOneDescriptor as ForeignRelatedObjectsDescriptor,
)
from django.db.models.fields.proxy import OrderWrt

from . import generators, random_gen
from .exceptions import (
ModelNotFound,
AmbiguousModelName,
InvalidQuantityException,
RecipeIteratorEmpty,
CustomBakerNotFound,
InvalidCustomBaker,
InvalidQuantityException,
ModelNotFound,
RecipeIteratorEmpty,
)
from .utils import import_from_str

Expand Down
1 change: 1 addition & 0 deletions model_bakery/gis.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import absolute_import

from django.apps import apps

BAKER_GIS = apps.is_installed("django.contrib.gis")
Expand Down
5 changes: 2 additions & 3 deletions model_bakery/random_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
import string
import warnings
from decimal import Decimal
from os.path import abspath, join, dirname
from random import randint, choice, random, uniform
from os.path import abspath, dirname, join
from random import choice, randint, random, uniform

from model_bakery.timezone import now


MAX_LENGTH = 300
# Using sys.maxint here breaks a bunch of tests when running against a
# Postgres database.
Expand Down
6 changes: 2 additions & 4 deletions model_bakery/recipe.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import inspect
import itertools

from . import baker
from .exceptions import RecipeNotFound

# Enable seq to be imported from recipes
from .utils import seq # NoQA

from .utils import seq # NoQA: Enable seq to be imported from recipes

finder = baker.ModelFinder()

Expand Down
2 changes: 1 addition & 1 deletion model_bakery/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import importlib
import datetime
import importlib
import itertools
import warnings

Expand Down
11 changes: 11 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ exclude = docs/*

[tool:pytest]
addopts = --tb=short -rxs --nomigrations

[isort]
multi_line_output=3
include_trailing_comma=True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

force_grid_wrap=0
use_parentheses=True
line_length=88

[pydocstyle]
add_ignore = D1
match-dir = (?!test|docs|\.).*
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from os.path import dirname, join

import setuptools
from os.path import join, dirname

import model_bakery


setuptools.setup(
name="model_bakery",
version=model_bakery.__version__,
Expand Down
9 changes: 4 additions & 5 deletions tests/generic/baker_recipes.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# ATTENTION: Recipes defined for testing purposes only
from datetime import timedelta
from decimal import Decimal
from model_bakery.recipe import Recipe, foreign_key, seq
from model_bakery.recipe import related

from model_bakery.recipe import Recipe, foreign_key, related, seq
from model_bakery.timezone import now
from tests.generic.models import (
TEST_TIME,
Person,
Dog,
DummyDefaultFieldsModel,
DummyUniqueIntegerFieldModel,
Person,
)

from datetime import timedelta

person = Recipe(
Person,
name="John Doe",
Expand Down
2 changes: 0 additions & 2 deletions tests/generic/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from django.forms import ModelForm


from tests.generic.models import DummyGenericIPAddressFieldModel


Expand Down
21 changes: 10 additions & 11 deletions tests/generic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
from decimal import Decimal
from tempfile import gettempdir

from model_bakery.gis import BAKER_GIS

from django.core.files.storage import FileSystemStorage

from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericRelation, GenericForeignKey
from django.core.files.storage import FileSystemStorage
from model_bakery.gis import BAKER_GIS
from model_bakery.timezone import smart_datetime as datetime

from .fields import (
CustomFieldViaSettings,
CustomFieldWithGenerator,
CustomFieldWithoutGenerator,
CustomFieldViaSettings,
FakeListField,
CustomForeignKey,
FakeListField,
)
from model_bakery.timezone import smart_datetime as datetime

# check whether or not PIL is installed
try:
Expand Down Expand Up @@ -70,7 +68,7 @@ class PaymentBill(models.Model):

class Person(models.Model):
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
# jards macalé is an amazing brazilian musician! =]
# Jards Macalé is an amazing brazilian musician! =]
enjoy_jards_macale = models.BooleanField(default=True)
like_metal_music = models.BooleanField(default=False)
name = models.CharField(max_length=30)
Expand Down Expand Up @@ -328,10 +326,11 @@ class Movie(models.Model):

class MovieManager(models.Manager):
def get_queryset(self):
"""Annotate queryset with an alias field 'name'.
"""
Annotate queryset with an alias field 'name'.

We want to test whether this annotation has been run after
calling baker.make().
calling `baker.make()`.
"""
return super(MovieManager, self).get_queryset().annotate(name=models.F("title"))

Expand Down
4 changes: 2 additions & 2 deletions tests/generic/tests/sub_package/baker_recipes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from datetime import date, datetime

from model_bakery.recipe import Recipe
from tests.generic.models import Person

from datetime import date, datetime

person = Recipe(
Person,
name="John Deeper",
Expand Down
29 changes: 12 additions & 17 deletions tests/test_baker.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import pytest
import datetime
import itertools
from decimal import Decimal
from unittest.mock import patch

import pytest
from django.db.models import Manager
from django.db.models.signals import m2m_changed

from model_bakery import baker
from model_bakery import random_gen
from model_bakery import baker, random_gen
from model_bakery.exceptions import (
ModelNotFound,
AmbiguousModelName,
InvalidQuantityException,
ModelNotFound,
)
from model_bakery.timezone import smart_datetime

from tests.generic import models
from tests.generic.forms import DummyGenericIPAddressFieldForm

Expand Down Expand Up @@ -113,7 +110,7 @@ def test_multiple_inheritance_creation(self):
@pytest.mark.django_db
class TestsBakerRepeatedCreatesSimpleModel:
def test_make_should_create_objects_respecting_quantity_parameter(self):
people = baker.make(models.Person, _quantity=5)
baker.make(models.Person, _quantity=5)
assert models.Person.objects.count() == 5

people = baker.make(models.Person, _quantity=5, name="George Washington")
Expand Down Expand Up @@ -144,7 +141,7 @@ def test_prepare_raises_correct_exception_if_invalid_quantity(self):
baker.prepare(_model=models.Person, _quantity=0)

def test_accepts_generators_with_quantity(self):
people = baker.make(
baker.make(
models.Person,
name=itertools.cycle(["a", "b", "c"]),
id_document=itertools.cycle(["d1", "d2", "d3", "d4", "d5"]),
Expand All @@ -164,7 +161,7 @@ def test_accepts_generators_with_quantity(self):
assert "d5" == p5.id_document

def test_accepts_generators_with_quantity_for_unique_fields(self):
people = baker.make(
baker.make(
models.DummyUniqueIntegerFieldModel,
value=itertools.cycle([1, 2, 3]),
_quantity=3,
Expand All @@ -179,9 +176,7 @@ def test_generators_work_with_user_model(self):
from django.contrib.auth import get_user_model

User = get_user_model()
people = baker.make(
User, username=itertools.cycle(["a", "b", "c"]), _quantity=3
)
baker.make(User, username=itertools.cycle(["a", "b", "c"]), _quantity=3)
assert User.objects.count() == 3
u1, u2, u3 = User.objects.all()
assert "a" == u1.username
Expand All @@ -197,28 +192,28 @@ def test_default_behaviour_for_and_fk(self):
assert dog.pk is None
assert dog.owner.pk is None
with pytest.raises(ValueError):
dog.friends_with
assert dog.friends_with

def test_create_fk_instances(self):
dog = baker.prepare(models.Dog, _save_related=True)

assert dog.pk is None
assert dog.owner.pk
with pytest.raises(ValueError):
dog.friends_with
assert dog.friends_with

def test_create_fk_instances_with_quantity(self):
dog1, dog2 = baker.prepare(models.Dog, _save_related=True, _quantity=2)

assert dog1.pk is None
assert dog1.owner.pk
with pytest.raises(ValueError):
dog1.friends_with
assert dog1.friends_with

assert dog2.pk is None
assert dog2.owner.pk
with pytest.raises(ValueError):
dog2.friends_with
assert dog2.friends_with

def test_create_one_to_one(self):
lonely_person = baker.prepare(models.LonelyPerson, _save_related=True)
Expand Down Expand Up @@ -651,7 +646,7 @@ def test_annotation_within_manager_get_queryset_are_run_on_make(self):
"""
movie = baker.make(models.MovieWithAnnotation)
with pytest.raises(AttributeError):
movie.name
assert movie.name

movie = baker.make(
models.MovieWithAnnotation, title="Old Boy", _from_manager="objects",
Expand Down
3 changes: 1 addition & 2 deletions tests/test_extending_bakery.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import pytest

from model_bakery import baker
from model_bakery.random_gen import gen_from_list
from model_bakery.exceptions import CustomBakerNotFound, InvalidCustomBaker
from model_bakery.random_gen import gen_from_list
from tests.generic.models import Person


Expand Down
Loading