Skip to content

Commit

Permalink
Misc small fixes
Browse files Browse the repository at this point in the history
* Run coverage across entire build matrix
* Use the root url for 'get_csv' in the demo app, because it's the only view.
* Add flake8 linting to travis jobs
* Make a few small syntax changes to make it easier to support python3
  in the future
* Fix lint
* Simplify development dependencies
  http://python-packaging-user-guide.readthedocs.org/en/latest/requirements/
  it makes sense to specify a loose requirement for django in `setup.py`
  and a duplicate it in `dev_requirements.txt`
  • Loading branch information
steve authored and Steve Lamb committed Jan 22, 2016
1 parent 4b36144 commit 9ffb68d
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 34 deletions.
17 changes: 9 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ python:
- "2.6"
- "2.7"
env:
- DJANGO=1.5 RUNNER="coverage run --source=djqscsv" SUCCESS="coveralls"
- DJANGO=1.6 RUNNER="python" SUCCESS="echo DONE"
- DJANGO=1.7 RUNNER="python" SUCCESS="echo DONE"
- DJANGO=1.8 RUNNER="python" SUCCESS="echo DONE"
- DJANGO=1.5
- DJANGO=1.6
- DJANGO=1.7
- DJANGO=1.8
matrix:
exclude:
- python: "2.6"
env: DJANGO=1.7 RUNNER="python" SUCCESS="echo DONE"
env: DJANGO=1.7
- python: "2.6"
env: DJANGO=1.8 RUNNER="python" SUCCESS="echo DONE"
env: DJANGO=1.8
install:
- pip install -q Django==$DJANGO
- pip install -r dev_requirements.txt
- python setup.py install
script:
- $RUNNER test_app/manage.py test djqscsv_tests
- coverage run --source=djqscsv test_app/manage.py test djqscsv_tests
- flake8 --exclude=migrations djqscsv/ test_app/
after_success:
- $SUCCESS
- coveralls
2 changes: 2 additions & 0 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
coveralls==0.3
coverage==3.6
flake8==2.5.1
django>=1.5
4 changes: 2 additions & 2 deletions djqscsv/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from djqscsv import (render_to_csv_response, write_csv, # NOQA
generate_filename, CSVException) # NOQA
from .djqscsv import (render_to_csv_response, write_csv, # NOQA
generate_filename, CSVException) # NOQA
5 changes: 4 additions & 1 deletion djqscsv/_csql.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
This module may later be officially supported.
"""


def _identity(x):
return x


def _transform(dataset, arg):
if isinstance(arg, str):
field = arg
Expand Down Expand Up @@ -43,6 +45,7 @@ def EXCLUDE(dataset, *args):

def CONSTANT(value, display_name):
return (None, display_name, lambda x: value)



def AS(field, display_name):
return (field, display_name, _identity)
2 changes: 1 addition & 1 deletion test_app/djqscsv_tests/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

import djqscsv.djqscsv as djqscsv # NOQA

from djqscsv._csql import SELECT, EXCLUDE, AS, CONSTANT
from djqscsv._csql import SELECT, EXCLUDE, AS, CONSTANT # NOQA
7 changes: 4 additions & 3 deletions test_app/djqscsv_tests/models.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
from django.db import models

from django.utils.translation import ugettext as _

from django.utils.encoding import python_2_unicode_compatible
from datetime import datetime

SOME_TIME = datetime(2001, 01, 01, 01, 01)
SOME_TIME = datetime(2001, 1, 1, 1, 1)


class Activity(models.Model):
name = models.CharField(max_length=50, verbose_name="Name of Activity")


@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=50, verbose_name=_("Person's name"))
address = models.CharField(max_length=255)
info = models.TextField(verbose_name="Info on Person")
hobby = models.ForeignKey(Activity)
born = models.DateTimeField(default=SOME_TIME)

def __unicode__(self):
def __str__(self):
return self.name
4 changes: 2 additions & 2 deletions test_app/djqscsv_tests/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from test_csv_creation import *
from test_utilities import *
from djqscsv_tests.tests.test_csv_creation import * # NOQA
from djqscsv_tests.tests.test_utilities import * # NOQA
3 changes: 1 addition & 2 deletions test_app/djqscsv_tests/tests/test_csv_creation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.db.models import Count
from django.test import TestCase
from django.core.exceptions import ValidationError

from django import VERSION as DJANGO_VERSION

Expand All @@ -16,7 +15,6 @@
from django.utils import six

if six.PY3:
from functools import filter
from io import StringIO
else:
from StringIO import StringIO
Expand Down Expand Up @@ -285,6 +283,7 @@ def test_extra_select_header_map(self):
self.qs, csv_with_extra,
field_header_map={'Most Powerful': 'Sturdiest'})


class RenderToCSVResponseTests(CSVTestCase):

def test_render_to_csv_response_with_filename_and_datestamp(self):
Expand Down
16 changes: 9 additions & 7 deletions test_app/djqscsv_tests/tests/test_utilities.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# -*- coding: utf-8 -*-
import datetime

from operator import attrgetter

from django.test import TestCase
from django.core.exceptions import ValidationError

from django.utils.encoding import python_2_unicode_compatible

from djqscsv_tests.context import djqscsv

from djqscsv_tests.util import create_people_and_get_queryset
Expand Down Expand Up @@ -81,9 +85,8 @@ def test_sanitize_date_with_formatter(self):
def test_sanitize_date_with_bad_formatter(self):
record = {'name': 'Tenar',
'created': datetime.datetime(1973, 5, 13)}
formatter = lambda d: d.day
with self.assertRaises(AttributeError):
djqscsv._sanitize_unicode_record(formatter, record)
djqscsv._sanitize_unicode_record(attrgetter('day'), record)


class AppendDatestampTests(TestCase):
Expand Down Expand Up @@ -120,15 +123,14 @@ def test_generate_filename(self):
class SafeUtf8EncodeTest(TestCase):
def test_safe_utf8_encode(self):

@python_2_unicode_compatible
class Foo(object):
def __unicode__(self):
def __str__(self):
return u'¯\_(ツ)_/¯'
def __str_(self):
return self.__unicode__().encode('utf-8')

for val in (u'¯\_(ツ)_/¯', 'plain', r'raw',
b'123', 11312312312313L, False,
datetime.datetime(2001, 01, 01),
b'123', 11312312312313, False,
datetime.datetime(2001, 1, 1),
4, None, [], set(), Foo):

first_pass = djqscsv._safe_utf8_stringify(val)
Expand Down
9 changes: 4 additions & 5 deletions test_app/djqscsv_tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.conf.urls import patterns, include, url
import views
from django.conf.urls import url
from djqscsv_tests import views

urlpatterns = patterns(
'',
url(r'^get_csv/', views.get_csv, name='get_csv'),
urlpatterns = (
url(r'^$', views.get_csv, name='get_csv'),
)
1 change: 1 addition & 0 deletions test_app/djqscsv_tests/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .models import Person, Activity


def create_people_and_get_queryset():
doing_magic, _ = Activity.objects.get_or_create(name="Doing Magic")
resting, _ = Activity.objects.get_or_create(name="Resting")
Expand Down
4 changes: 1 addition & 3 deletions test_app/djqscsv_tests/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

import djqscsv
from models import Person
from djqscsv_tests.context import djqscsv
from .util import create_people_and_get_queryset


Expand Down

0 comments on commit 9ffb68d

Please sign in to comment.