Add flake8 tests, and fix all flake8 errors we don't ignore
This commit is contained in:
parent
cbb769b8cb
commit
9663f1d4ca
15 changed files with 66 additions and 33 deletions
|
@ -56,10 +56,11 @@ matrix:
|
|||
|
||||
install:
|
||||
- pip install -q $DJANGO_VERSION
|
||||
- pip install tox coveralls
|
||||
- pip install tox coveralls flake8
|
||||
|
||||
script:
|
||||
- coverage erase
|
||||
- if [[ $(python -c 'import sys; print("0" if sys.version_info < (2, 7) else "1")') == "1" ]]; then flake8 --ignore=E501; fi
|
||||
- PYTHONPATH=. coverage run -p example/run_tests.py
|
||||
- PYTHONPATH=. coverage run -p example/run_tests.py example.settings_no_debug
|
||||
after_success:
|
||||
|
|
|
@ -22,4 +22,5 @@ from .models import Book
|
|||
class BookAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
admin.site.register(Book, BookAdmin)
|
||||
|
|
|
@ -28,15 +28,15 @@ CATEGORY_CHOICES = (
|
|||
)
|
||||
|
||||
TAGS_CHOICES = (
|
||||
('sex', _('Sex')),
|
||||
('work', _('Work')),
|
||||
('happy', _('Happy')),
|
||||
('food', _('Food')),
|
||||
('field', _('Field')),
|
||||
('boring', _('Boring')),
|
||||
('interesting', _('Interesting')),
|
||||
('huge', _('Huge')),
|
||||
('nice', _('Nice')),
|
||||
('sex', _('Sex')), # noqa: E241
|
||||
('work', _('Work')), # noqa: E241
|
||||
('happy', _('Happy')), # noqa: E241
|
||||
('food', _('Food')), # noqa: E241
|
||||
('field', _('Field')), # noqa: E241
|
||||
('boring', _('Boring')), # noqa: E241
|
||||
('interesting', _('Interesting')), # noqa: E241
|
||||
('huge', _('Huge')), # noqa: E241
|
||||
('nice', _('Nice')), # noqa: E241
|
||||
)
|
||||
|
||||
PROVINCES = (
|
||||
|
@ -52,7 +52,7 @@ STATES = (
|
|||
|
||||
PROVINCES_AND_STATES = (
|
||||
(_("Canada - Provinces"), PROVINCES),
|
||||
(_("USA - States"), STATES),
|
||||
(_("USA - States"), STATES), # noqa: E241
|
||||
)
|
||||
|
||||
|
||||
|
@ -60,7 +60,7 @@ class Book(models.Model):
|
|||
title = models.CharField(max_length=200)
|
||||
categories = MultiSelectField(choices=CATEGORY_CHOICES,
|
||||
max_choices=3,
|
||||
#default='1,5')
|
||||
# default='1,5')
|
||||
default=1)
|
||||
tags = MultiSelectField(choices=TAGS_CHOICES,
|
||||
null=True, blank=True)
|
||||
|
|
|
@ -27,7 +27,7 @@ from .models import Book, PROVINCES, STATES, PROVINCES_AND_STATES
|
|||
|
||||
|
||||
if sys.version_info < (3,):
|
||||
u = unicode
|
||||
u = unicode # noqa: F821
|
||||
else:
|
||||
u = str
|
||||
|
||||
|
@ -129,7 +129,7 @@ class MultiSelectTestCase(TestCase):
|
|||
self.assertEqual(get_field(Book, 'categories').value_to_string(book), '1,3,5')
|
||||
|
||||
def test_flatchoices(self):
|
||||
self.assertEqual(get_field(Book, 'published_in').flatchoices, list(PROVINCES+STATES))
|
||||
self.assertEqual(get_field(Book, 'published_in').flatchoices, list(PROVINCES + STATES))
|
||||
|
||||
def test_named_groups(self):
|
||||
self.assertEqual(get_field(Book, 'published_in').choices, PROVINCES_AND_STATES)
|
||||
|
|
|
@ -35,6 +35,7 @@ except ImportError: # Django < 1.4
|
|||
from .views import app_index
|
||||
|
||||
|
||||
urlpatterns = patterns('',
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
url(r'^$', app_index, name='app_index'),
|
||||
)
|
||||
|
|
|
@ -32,7 +32,7 @@ MANAGERS = ADMINS
|
|||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
|
||||
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
|
||||
'NAME': 'example.db', # Or path to database file if using sqlite3.
|
||||
# The following settings are not used with sqlite3:
|
||||
'USER': '',
|
||||
|
@ -100,7 +100,7 @@ STATICFILES_DIRS = (
|
|||
STATICFILES_FINDERS = (
|
||||
'django.contrib.staticfiles.finders.FileSystemFinder',
|
||||
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
||||
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
|
||||
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
|
||||
)
|
||||
|
||||
# Make this unique, and don't share it with anybody.
|
||||
|
@ -128,7 +128,7 @@ if VERSION < (1, 8):
|
|||
TEMPLATE_LOADERS = (
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
# 'django.template.loaders.eggs.Loader',
|
||||
# 'django.template.loaders.eggs.Loader',
|
||||
)
|
||||
|
||||
TEMPLATE_DIRS = (
|
||||
|
@ -191,13 +191,13 @@ INSTALLED_APPS = (
|
|||
|
||||
|
||||
# If formadmin is installed
|
||||
from django.conf import ENVIRONMENT_VARIABLE
|
||||
from django.conf import ENVIRONMENT_VARIABLE # noqa: E402
|
||||
# I check it if formadmin is installed of this way because if I execute
|
||||
# python manage.py runserver --settings=settings_no_debug
|
||||
# I get an error
|
||||
if os.environ[ENVIRONMENT_VARIABLE] == 'example.settings':
|
||||
try:
|
||||
import formadmin
|
||||
import formadmin # noqa: F401
|
||||
INSTALLED_APPS += ('formadmin',)
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from example.settings import *
|
||||
from example.settings import * # noqa: F401,F403
|
||||
|
||||
DEBUG = False
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
|
|
@ -42,12 +42,14 @@ js_info_dict = {
|
|||
'packages': ('django.conf',),
|
||||
}
|
||||
|
||||
urlpatterns = patterns('',
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
url(r'^', include('app.urls')),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
)
|
||||
|
||||
urlpatterns += patterns('',
|
||||
urlpatterns += patterns(
|
||||
'',
|
||||
url(r'^%s(?P<path>.*)$' % settings.MEDIA_URL[1:],
|
||||
serve,
|
||||
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
|
||||
|
|
|
@ -15,16 +15,17 @@ framework.
|
|||
"""
|
||||
import os
|
||||
|
||||
# This application object is used by any WSGI server configured to use this
|
||||
# file. This includes Django's development server, if the WSGI_APPLICATION
|
||||
# setting points here.
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
|
||||
# if running multiple sites in the same mod_wsgi process. To fix this, use
|
||||
# mod_wsgi daemon mode with each site in its own daemon process, or use
|
||||
# os.environ["DJANGO_SETTINGS_MODULE"] = "test_project.settings"
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
|
||||
|
||||
# This application object is used by any WSGI server configured to use this
|
||||
# file. This includes Django's development server, if the WSGI_APPLICATION
|
||||
# setting points here.
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
application = get_wsgi_application()
|
||||
|
||||
# Apply WSGI middleware here.
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
from multiselectfield.db.fields import MultiSelectField
|
||||
from multiselectfield.forms.fields import MultiSelectFormField
|
||||
from multiselectfield.db.fields import MultiSelectField # noqa: F401
|
||||
from multiselectfield.forms.fields import MultiSelectFormField # noqa: F401
|
||||
|
|
|
@ -27,7 +27,7 @@ from ..utils import get_max_length
|
|||
from ..validators import MaxValueMultiFieldValidator
|
||||
|
||||
if sys.version_info < (3,):
|
||||
string_type = unicode
|
||||
string_type = unicode # noqa: F821
|
||||
else:
|
||||
string_type = str
|
||||
|
||||
|
@ -148,6 +148,7 @@ class MultiSelectField(models.CharField):
|
|||
setattr(cls, 'get_%s_list' % self.name, get_list)
|
||||
setattr(cls, 'get_%s_display' % self.name, get_display)
|
||||
|
||||
|
||||
if VERSION < (1, 8):
|
||||
MultiSelectField = add_metaclass(models.SubfieldBase)(MultiSelectField)
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ import sys
|
|||
|
||||
|
||||
if sys.version_info[0] == 2:
|
||||
string = basestring
|
||||
string_type = unicode
|
||||
string = basestring # noqa: F821
|
||||
string_type = unicode # noqa: F821
|
||||
else:
|
||||
string = str
|
||||
string_type = string
|
||||
|
|
|
@ -20,14 +20,17 @@ from django.utils.translation import ugettext_lazy as _
|
|||
|
||||
|
||||
class MaxValueMultiFieldValidator(validators.MaxLengthValidator):
|
||||
clean = lambda self, x: len(','.join(x))
|
||||
code = 'max_multifield_value'
|
||||
|
||||
def clean(self, x):
|
||||
return len(','.join(x))
|
||||
|
||||
|
||||
class MinChoicesValidator(validators.MinLengthValidator):
|
||||
message = _(u'You must select a minimum of %(limit_value)d choices.')
|
||||
code = 'min_choices'
|
||||
|
||||
|
||||
class MaxChoicesValidator(validators.MaxLengthValidator):
|
||||
message = _(u'You must select a maximum of %(limit_value)d choices.')
|
||||
code = 'max_choices'
|
||||
|
|
2
setup.py
2
setup.py
|
@ -23,6 +23,7 @@ from setuptools import setup, find_packages
|
|||
def read(*rnames):
|
||||
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
|
||||
|
||||
|
||||
setup(
|
||||
name="django-multiselectfield",
|
||||
version="0.1.4",
|
||||
|
@ -51,6 +52,7 @@ setup(
|
|||
'django>=1.4',
|
||||
'tox',
|
||||
'coverage',
|
||||
'flake8',
|
||||
],
|
||||
install_requires=[
|
||||
'django>=1.4',
|
||||
|
|
21
tox.ini
21
tox.ini
|
@ -6,6 +6,7 @@ usedevelop = True
|
|||
setenv =
|
||||
PYTHONPATH=.
|
||||
commands =
|
||||
python {envbindir}/flake8 --ignore=E501
|
||||
python {envbindir}/coverage run -p example/run_tests.py
|
||||
python {envbindir}/coverage run -p example/run_tests.py example.settings_no_debug
|
||||
install_command =
|
||||
|
@ -18,6 +19,7 @@ deps =
|
|||
pillow==1.7.8
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
[testenv:py26-dj15]
|
||||
basepython = python2.6
|
||||
|
@ -26,6 +28,7 @@ deps =
|
|||
pillow==1.7.8
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
[testenv:py26-dj16]
|
||||
basepython = python2.6
|
||||
|
@ -34,6 +37,7 @@ deps =
|
|||
pillow==1.7.8
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
|
||||
[testenv:py27-dj14]
|
||||
|
@ -43,6 +47,7 @@ deps =
|
|||
pillow==1.7.8
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
[testenv:py27-dj15]
|
||||
basepython = python2.7
|
||||
|
@ -51,6 +56,7 @@ deps =
|
|||
pillow==1.7.8
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
[testenv:py27-dj16]
|
||||
basepython = python2.7
|
||||
|
@ -59,6 +65,7 @@ deps =
|
|||
pillow==1.7.8
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
[testenv:py27-dj17]
|
||||
basepython = python2.7
|
||||
|
@ -67,6 +74,7 @@ deps =
|
|||
pillow==1.7.8
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
[testenv:py27-dj18]
|
||||
basepython = python2.7
|
||||
|
@ -75,6 +83,7 @@ deps =
|
|||
pillow==1.7.8
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
[testenv:py27-dj19]
|
||||
basepython = python2.7
|
||||
|
@ -83,6 +92,7 @@ deps =
|
|||
pillow==1.7.8
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
[testenv:py27-dj110]
|
||||
basepython = python2.7
|
||||
|
@ -91,6 +101,7 @@ deps =
|
|||
pillow==1.7.8
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
|
||||
[testenv:py33-dj16]
|
||||
|
@ -100,6 +111,7 @@ deps =
|
|||
pillow==2.1.0
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
[testenv:py33-dj17]
|
||||
basepython = python3.3
|
||||
|
@ -108,6 +120,7 @@ deps =
|
|||
pillow==2.1.0
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
[testenv:py33-dj18]
|
||||
basepython = python3.3
|
||||
|
@ -116,6 +129,7 @@ deps =
|
|||
pillow==2.1.0
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
|
||||
[testenv:py34-dj17]
|
||||
|
@ -125,6 +139,7 @@ deps =
|
|||
pillow==2.1.0
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
[testenv:py34-dj18]
|
||||
basepython = python3.4
|
||||
|
@ -133,6 +148,7 @@ deps =
|
|||
pillow==2.1.0
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
[testenv:py34-dj19]
|
||||
basepython = python3.4
|
||||
|
@ -141,6 +157,7 @@ deps =
|
|||
pillow==2.1.0
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
[testenv:py34-dj110]
|
||||
basepython = python3.4
|
||||
|
@ -149,6 +166,7 @@ deps =
|
|||
pillow==2.1.0
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
|
||||
[testenv:py35-dj18]
|
||||
|
@ -158,6 +176,7 @@ deps =
|
|||
pillow==2.1.0
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
[testenv:py35-dj19]
|
||||
basepython = python3.5
|
||||
|
@ -166,6 +185,7 @@ deps =
|
|||
pillow==2.1.0
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
||||
[testenv:py35-dj110]
|
||||
basepython = python3.5
|
||||
|
@ -174,3 +194,4 @@ deps =
|
|||
pillow==2.1.0
|
||||
PyYAML==3.10
|
||||
coveralls==0.3
|
||||
flake8
|
||||
|
|
Loading…
Reference in a new issue