Skip to content

Commit

Permalink
Add linting and docs builds to CI (#850)
Browse files Browse the repository at this point in the history
* Add lint testenv, run with isort in CI

* Remove universal wheel config

* Fix linter errors

* Add '__all__' to rest_framework subpackage

* Add docs build to CI
  • Loading branch information
Ryan P Kilby authored and carltongibson committed Jul 13, 2018
1 parent dbbae86 commit f982f85
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ script:
matrix:
include:
- python: 3.6
env: TOXENV=isort
env: TOXENV=isort,lint,docs
- python: 3.6
env: TOXENV=warnings
allow_failures:
Expand Down
3 changes: 2 additions & 1 deletion django_filters/filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ def filter_for_field(cls, field, field_name, lookup_expr='exact'):
assert filter_class is not None, (
"%s resolved field '%s' with '%s' lookup to an unrecognized field "
"type %s. Try adding an override to 'Meta.filter_overrides'. See: "
"https://django-filter.readthedocs.io/en/master/ref/filterset.html#customise-filter-generation-with-filter-overrides"
"https://django-filter.readthedocs.io/en/master/ref/filterset.html"
"#customise-filter-generation-with-filter-overrides"
) % (cls.__name__, field_name, lookup_expr, field.__class__.__name__)

return filter_class(**default)
Expand Down
4 changes: 3 additions & 1 deletion django_filters/rest_framework/filters.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

from ..filters import BooleanFilter as _BooleanFilter
from ..filters import *
from ..filters import * # noqa
from ..widgets import BooleanWidget

__all__ = filters.__all__


class BooleanFilter(_BooleanFilter):
def __init__(self, *args, **kwargs):
Expand Down
7 changes: 4 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[metadata]
license-file = LICENSE

[wheel]
universal=1

[isort]
skip=.tox
atomic=true
multi_line_output=3
known_standard_library=mock
known_third_party=django,pytz,rest_framework
known_first_party=django_filters

[flake8]
max_line_length = 120
max_complexity = 10
23 changes: 23 additions & 0 deletions tests/rest_framework/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
import inspect

from django.test import TestCase

from django_filters.rest_framework import filters
from django_filters.widgets import BooleanWidget


class ModuleImportTests(TestCase):
def is_filter(self, name, value):
return (
isinstance(value, type) and issubclass(value, filters.Filter)
)

def test_imports(self):
# msg = "Expected `filters.%s` to be imported in `filters.__all__`"
filter_classes = [
key for key, value
in inspect.getmembers(filters)
if isinstance(value, type) and issubclass(value, filters.Filter)
]

# sanity check
self.assertIn('Filter', filter_classes)
self.assertIn('BooleanFilter', filter_classes)

for f in filter_classes:
self.assertIn(f, filters.__all__)


class BooleanFilterTests(TestCase):

def test_widget(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ def test_field_labels_descending(self):

def test_normalize_fields(self):
f = OrderingFilter.normalize_fields
O = OrderedDict
O = OrderedDict # noqa

self.assertIn('a', f({'a': 'b'}))

Expand Down
1 change: 1 addition & 0 deletions tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
def _foo():
return 'bar'


urlpatterns = [
url(r'^books-legacy/$', object_filter, {'model': Book, 'extra_context': {'foo': _foo, 'bar': 'foo'}}),
url(r'^books/$', FilterView.as_view(model=Book)),
Expand Down
13 changes: 12 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ envlist =
{py27,py34,py35,py36}-django111,
{py34,py35,py36}-django20,
{py35,py36}-latest,
isort, warnings,
isort,lint,docs,warnings,


[latest]
deps =
Expand All @@ -27,6 +28,16 @@ deps =
commands = isort --check-only --recursive django_filters tests {posargs}
deps = isort

[testenv:lint]
commands = flake8 django_filters tests {posargs}
deps = flake8

[testenv:docs]
commands = sphinx-build -WE docs _docs
deps =
sphinx
sphinx-rtd-theme

[testenv:warnings]
ignore_outcome = True
unignore_outcomes = True
Expand Down

0 comments on commit f982f85

Please sign in to comment.