Skip to content

Commit

Permalink
python3 support (fixes #3)
Browse files Browse the repository at this point in the history
 - simplify test structure
 - update travis test matrix
  • Loading branch information
sheppard committed Aug 8, 2014
1 parent e5d6f15 commit 16c66d6
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: python
python:
- "2.7"
- "3.4"
env:
- DJANGO="django==1.6" REST="djangorestframework==2.3.12" PANDAS="pandas==0.13.0"
- DJANGO="django==1.6" REST="djangorestframework==2.3.14" PANDAS="pandas==0.14.1"
install:
- pip install $DJANGO
- pip install $REST
Expand Down
9 changes: 8 additions & 1 deletion rest_pandas/renderers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from rest_framework.renderers import BaseRenderer
from rest_framework import status
from tempfile import mkstemp
from StringIO import StringIO

try:
# Python 2 (uses str)
from StringIO import StringIO
except ImportError:
# Python 3 (Python 2 equivalent uses unicode)
from io import StringIO

import os


Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ def parse_markdown_readme():
'Environment :: Web Environment',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Topic :: Scientific/Engineering :: Information Analysis',
'Topic :: Scientific/Engineering :: Visualization',
],
test_suite='tests.runtests.main',
tests_require=['wq.io'],
test_suite='tests',
tests_require=['wq.io>=0.6.0'],
)
8 changes: 8 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os
os.environ['DJANGO_SETTINGS_MODULE'] = "tests.settings"

from django.test.utils import setup_test_environment
setup_test_environment()

from django.core.management import call_command
call_command('syncdb')
28 changes: 0 additions & 28 deletions tests/runtests.py

This file was deleted.

11 changes: 11 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SECRET_KEY = '1234'
INSTALLED_APPS = (
'tests.testapp',
)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
ROOT_URLCONF = "tests.urls"
14 changes: 8 additions & 6 deletions tests/testapp/tests.py → tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework.test import APITestCase
from .models import TimeSeries
from tests.testapp.models import TimeSeries
from wq.io import load_string
import json

Expand All @@ -18,26 +18,28 @@ def setUp(self):

def test_view(self):
response = self.client.get("/timeseries.csv")
data = load_string(unicode(response.content))
data = self.load_string(response)
self.assertEqual(len(data), 5)
self.assertEqual(data[0].value, '0.5')

def test_view_json(self):
response = self.client.get("/timeseries.json")
self.assertEqual(response.accepted_media_type, "application/json")
data = load_string(unicode(response.content))
data = json.loads(response.content)
data = json.loads(response.content.decode('utf-8'))
self.assertEqual(len(data.keys()), 5)
self.assertEqual(data["1"]["value"], 0.5)

def test_viewset(self):
response = self.client.get("/router/timeseries/.csv")
data = load_string(unicode(response.content))
data = self.load_string(response)
self.assertEqual(len(data), 5)
self.assertEqual(data[0].value, '0.5')

def test_no_model(self):
response = self.client.get("/nomodel.csv")
data = load_string(unicode(response.content))
data = self.load_string(response)
self.assertEqual(len(data), 4)
self.assertEqual(data[0].x, '5')

def load_string(self, response):
return load_string(response.content.decode('utf-8'))

0 comments on commit 16c66d6

Please sign in to comment.