Skip to content

Commit 3aee4d7

Browse files
committed
Various improvements to test/lint
- Switch to pytest - Add flake8 - Enhance TravisCI configuration - Switch to container builds - Add pypy to grid - Add explicit postgres/sqlite to grid - Add development Django to grid
1 parent 24126a0 commit 3aee4d7

16 files changed

+144
-99
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
*.eggs
12
*.pyc
23
*.swp
34
*.un~

.travis.yml

+29-14
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,34 @@ python:
66
- "3.2"
77
- "3.3"
88
- "3.4"
9+
- "pypy"
10+
11+
sudo: false
12+
13+
cache:
14+
directories:
15+
- node_modules
16+
- .pip_download_cache
17+
- "$HOME/virtualenv/python2.7.9"
918

1019
env:
11-
- DJANGO=1.2.7
12-
- DJANGO=1.3.7
13-
- DJANGO=1.4.12
14-
- DJANGO=1.5.7
15-
- DJANGO=1.6.4
16-
- DJANGO=1.7.7
17-
- DJANGO=1.8
20+
matrix:
21+
- DB=postgres
22+
- DB=sqlite
23+
- DJANGO=1.2.7
24+
- DJANGO=1.3.7
25+
- DJANGO=1.4.12
26+
- DJANGO=1.5.7
27+
- DJANGO=1.6.4
28+
- DJANGO=1.7.7
29+
- DJANGO=1.8
30+
- 'DJANGO="-e git+git://github.com/django/django.git#egg=Django"'
31+
global:
32+
- PIP_DOWNLOAD_CACHE=".pip_download_cache"
1833

1934
matrix:
35+
allow_failures:
36+
- env: 'DJANGO="-e git+git://github.com/django/django.git#egg=Django"'
2037
exclude:
2138
- python: "3.2"
2239
env: DJANGO=1.2.7
@@ -50,13 +67,11 @@ matrix:
5067
env: DJANGO=1.8
5168

5269
before_script:
53-
- psql -c 'create database bitfield_test;' -U postgres
70+
- psql -c 'create database bitfield;' -U postgres
5471

5572
install:
56-
- pip install Django==$DJANGO
57-
- "if [[ $DJANGO == '1.2.7' ]]; then pip install psycopg2==2.4.1 django-nose==0.1.3; fi"
58-
- "if [[ $DJANGO == '1.3.7' ]]; then pip install psycopg2==2.4.1 django-nose==0.1.3; fi"
59-
- "if [[ $DJANGO == '1.8' ]]; then pip install https://github.com/django-nose/django-nose/archive/master.zip; fi"
60-
- pip install -e .
73+
- make
6174

62-
script: python setup.py test
75+
script:
76+
- make lint
77+
- make test

Makefile

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1+
develop:
2+
@echo "--> Installing dependencies"
3+
pip install -e .
4+
pip install "file://`pwd`#egg=django-bitfield[tests]"
5+
@echo ""
6+
17
test:
2-
python setup.py test
8+
@echo "--> Running Python tests"
9+
py.test
10+
@echo ""
11+
12+
lint:
13+
@echo "--> Linting Python files"
14+
PYFLAKES_NODOCTEST=1 flake8 bitfield
15+
@echo ""
16+
317

418
publish:
519
python setup.py sdist bdist_wheel upload

bitfield/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
django-bitfield
33
~~~~~~~~~~~~~~~
44
"""
5+
from __future__ import absolute_import
6+
7+
from bitfield.models import Bit, BitHandler, CompositeBitField, BitField # NOQA
8+
59

610
try:
711
VERSION = __import__('pkg_resources') \
812
.get_distribution('bitfield').version
913
except Exception:
1014
VERSION = 'unknown'
11-
12-
from bitfield.models import Bit, BitHandler, CompositeBitField, BitField # noqa

bitfield/compat.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
from __future__ import absolute_import
2+
13
__all__ = ('bitand', 'bitor')
24

5+
36
def bitand(a, b):
47
return a.bitand(b)
58

9+
610
def bitor(a, b):
711
return a.bitor(b)
812

13+
914
try:
1015
from django.db.models.expressions import ExpressionNode
1116
ExpressionNode.BITAND # noqa
@@ -15,8 +20,8 @@ def bitor(a, b):
1520
pass
1621
except AttributeError:
1722
# Django < 1.5
18-
def bitand(a, b):
23+
def bitand(a, b): # NOQA
1924
return a & b
2025

21-
def bitor(a, b):
26+
def bitor(a, b): # NOQA
2227
return a | b

bitfield/forms.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
from __future__ import absolute_import
2+
13
from django.forms import CheckboxSelectMultiple, IntegerField, ValidationError
4+
25
try:
36
from django.utils.encoding import force_text
47
except ImportError:

bitfield/models.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from __future__ import absolute_import
2+
3+
import six
4+
15
from django.db.models import signals
26
from django.db.models.fields import Field, BigIntegerField
37
from django.db.models.fields.subclassing import Creator
@@ -7,8 +11,6 @@
711
# django 1.2
812
from django.db.models.fields.subclassing import LegacyConnection as SubfieldBase # NOQA
913

10-
import six
11-
1214
from bitfield.forms import BitFormField
1315
from bitfield.query import BitQueryLookupWrapper
1416
from bitfield.types import BitHandler, Bit
@@ -244,7 +246,7 @@ class CompositeBitField(object):
244246
is_relation = False
245247
many_to_many = False
246248
concrete = False
247-
249+
248250
def __init__(self, fields):
249251
self.fields = fields
250252

bitfield/query.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import absolute_import
2+
3+
14
class BitQueryLookupWrapper(object):
25
def __init__(self, alias, column, bit):
36
self.table_alias = alias
@@ -17,12 +20,11 @@ def as_sql(self, qn, connection=None):
1720
return ("(%s.%s & %d)" % (qn(self.table_alias), qn(self.column), self.bit.mask),
1821
[])
1922

20-
2123
try:
2224
# Django 1.7+
2325
from django.db.models.lookups import Exact
24-
class BitQueryLookupWrapper(Exact):
2526

27+
class BitQueryLookupWrapper(Exact): # NOQA
2628
def process_lhs(self, qn, connection, lhs=None):
2729
lhs_sql, params = super(BitQueryLookupWrapper, self).process_lhs(
2830
qn, connection, lhs)

bitfield/tests/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
from .forms import *
2-
from .models import *
1+
from __future__ import absolute_import
2+
3+
from .forms import * # NOQA
4+
from .models import * # NOQA

bitfield/tests/forms.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
from __future__ import absolute_import
2+
13
from django import forms
2-
from bitfield.tests.models import BitFieldTestModel, CompositeBitFieldTestModel
4+
5+
from bitfield.tests.models import BitFieldTestModel
36

47

58
class BitFieldTestModelForm(forms.ModelForm):
6-
79
class Meta:
810
model = BitFieldTestModel
911
exclude = tuple()

bitfield/tests/tests.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import absolute_import
2+
13
import pickle
24

35
from django.db import connection, models

bitfield/types.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import absolute_import
2+
13
from six import string_types
24

35

@@ -127,13 +129,13 @@ def __eq__(self, other):
127129

128130
def __lt__(self, other):
129131
return int(self._value) < other
130-
132+
131133
def __le__(self, other):
132134
return int(self._value) <= other
133-
135+
134136
def __gt__(self, other):
135137
return int(self._value) > other
136-
138+
137139
def __ge__(self, other):
138140
return int(self._value) >= other
139141

@@ -243,7 +245,7 @@ def get_label(self, flag):
243245

244246
if django.VERSION[:2] >= (1, 8):
245247
from django.core.exceptions import ImproperlyConfigured
246-
248+
247249
# We need to register adapters in Django 1.8 in order to prevent
248250
# "ProgrammingError: can't adapt type"
249251
try:
@@ -252,7 +254,7 @@ def get_label(self, flag):
252254
Database.register_adapter(BitHandler, lambda x: int(x))
253255
except ImproperlyConfigured:
254256
pass
255-
257+
256258
try:
257259
from django.db.backends.postgresql_psycopg2.base import Database
258260
Database.extensions.register_adapter(Bit, lambda x: Database.extensions.AsIs(int(x)))

conftest.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from __future__ import absolute_import
2+
3+
import os.path
4+
import sys
5+
6+
from django.conf import settings
7+
8+
9+
sys.path.insert(0, os.path.dirname(__file__))
10+
11+
12+
def pytest_configure(config):
13+
if not settings.configured:
14+
test_db = os.environ.get('DB', 'postgres')
15+
16+
DATABASES = {
17+
'default': {
18+
'NAME': 'bitfield',
19+
}
20+
}
21+
22+
if test_db == 'postgres':
23+
DATABASES['default'].update({
24+
'ENGINE': 'django.db.backends.postgresql_psycopg2',
25+
'USER': 'postgres',
26+
})
27+
elif test_db == 'sqlite':
28+
DATABASES['default'].update({
29+
'ENGINE': 'django.db.backends.sqlite3',
30+
'NAME': ':memory:',
31+
})
32+
33+
settings.configure(
34+
DATABASES=DATABASES,
35+
INSTALLED_APPS=[
36+
'django.contrib.contenttypes',
37+
'bitfield',
38+
'bitfield.tests',
39+
],
40+
ROOT_URLCONF='',
41+
DEBUG=False,
42+
)

runtests.py

-58
This file was deleted.

setup.cfg

+10
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1+
[pytest]
2+
python_files=test*.py
3+
addopts=--tb=native -p no:doctest
4+
norecursedirs=bin dist docs htmlcov hooks node_modules .* {args}
5+
6+
[flake8]
7+
ignore = F999,E501,E128,E124,E402,W503,E731,F841
8+
max-line-length = 100
9+
exclude = .tox,.git,docs
10+
111
[wheel]
212
universal = 1

setup.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
'Django>=1.2',
1616
'six',
1717
],
18-
setup_requires=[
19-
'nose>=1.0',
20-
],
21-
tests_require=[
22-
'django-nose>=0.1.3',
23-
'psycopg2>=2.3',
24-
],
25-
test_suite='runtests.runtests',
18+
extras_require={
19+
'tests': [
20+
'flake8',
21+
'psycopg2>=2.3',
22+
'pytest-django',
23+
],
24+
},
2625
include_package_data=True,
2726
classifiers=[
2827
'Framework :: Django',

0 commit comments

Comments
 (0)