First stab at Python 3 support.

This commit is contained in:
Jannis Leidel 2013-04-12 17:25:11 +02:00
parent 71d327426a
commit 89b423fa65
6 changed files with 45 additions and 20 deletions

View file

@ -1,12 +1,24 @@
language: python
python:
- "2.6"
- "2.7"
- 2.6
- 2.7
- 3.2
- 3.3
env:
- DJANGO_VERSION=1.3.7
- DJANGO_VERSION=1.4.5
- DJANGO_VERSION=1.5
- DJANGO_VERSION=1.5.1
install:
- pip install Django==$DJANGO_VERSION
- python setup.py install
script: python setup.py test
matrix:
exclude:
- python: 3.2
env: DJANGO=1.4.5
- python: 3.2
env: DJANGO=1.3.7
- python: 3.3
env: DJANGO=1.4.5
- python: 3.3
env: DJANGO=1.3.7

View file

@ -235,6 +235,9 @@ v0.5.1 (2013/04/12)
* Fixed a serious issue with ordering in the admin when using the database
backend. Thanks, Bouke Haarsma.
* Switch to django-discover-runner as test runner to be able to run on
Python 3.
v0.5 (2013/03/02)
~~~~~~~~~~~~~~~~~

View file

@ -1,6 +1,7 @@
from datetime import datetime, date, time
from decimal import Decimal
from operator import itemgetter
import six
from django import forms
from django.contrib import admin, messages
@ -26,16 +27,20 @@ STRING_LIKE = (fields.CharField, {'widget': forms.Textarea(attrs={'rows': 3}), '
FIELDS = {
bool: (fields.BooleanField, {'required': False}),
int: INTEGER_LIKE,
long: INTEGER_LIKE,
Decimal: (fields.DecimalField, {'widget': NUMERIC_WIDGET}),
str: STRING_LIKE,
unicode: STRING_LIKE,
datetime: (fields.DateTimeField, {'widget': widgets.AdminSplitDateTime}),
date: (fields.DateField, {'widget': widgets.AdminDateWidget}),
time: (fields.TimeField, {'widget': widgets.AdminTimeWidget}),
float: (fields.FloatField, {'widget': NUMERIC_WIDGET}),
}
if not six.PY3:
FIELDS.update({
long: INTEGER_LIKE,
unicode: STRING_LIKE,
})
class ConstanceForm(forms.Form):
def __init__(self, *args, **kwargs):
@ -56,12 +61,10 @@ class ConstanceAdmin(admin.ModelAdmin):
return patterns('',
url(r'^$',
self.admin_site.admin_view(self.changelist_view),
name='%s_%s_changelist' % info
),
name='%s_%s_changelist' % info),
url(r'^$',
self.admin_site.admin_view(self.changelist_view),
name='%s_%s_add' % info
),
name='%s_%s_add' % info),
)
@csrf_protect_m
@ -70,7 +73,7 @@ class ConstanceAdmin(admin.ModelAdmin):
if not self.has_change_permission(request, None):
raise PermissionDenied
default_initial = ((name, default)
for name, (default, help_text) in settings.CONFIG.iteritems())
for name, (default, help_text) in settings.CONFIG.items())
# Then update the mapping with actually values from the backend
initial = dict(default_initial,
**dict(config._backend.mget(settings.CONFIG.keys())))
@ -94,7 +97,7 @@ class ConstanceAdmin(admin.ModelAdmin):
'form': form,
'media': self.media + form.media,
}
for name, (default, help_text) in settings.CONFIG.iteritems():
for name, (default, help_text) in settings.CONFIG.items():
# First try to load the value from the actual backend
value = initial.get(name)
# Then if the returned value is None, get the default

View file

@ -38,13 +38,16 @@ setup(
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Topic :: Utilities',
],
packages=find_packages(exclude=['tests']),
include_package_data=True,
test_suite='tests.runtests.main',
test_requires=['django-nose'],
extras_require = {
test_requires=['django-discover-runner'],
install_requires=['six'],
extras_require={
'database': ['django-picklefield'],
'redis': ['redis'],
}

View file

@ -1,9 +1,10 @@
# -*- encoding: utf-8 -*-
import os
import six
from datetime import datetime, date, time
from decimal import Decimal
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
TEST_RUNNER = 'discover_runner.DiscoverRunner'
SECRET_KEY = 'cheese'
@ -25,20 +26,23 @@ INSTALLED_APPS = (
'constance',
'constance.backends.database',
'south',
'django_nose',
)
ROOT_URLCONF = 'tests.urls'
CONSTANCE_CONNECTION_CLASS = 'tests.redis_mockup.Connection'
long_value = 123456
if not six.PY3:
long_value = long(long_value)
CONSTANCE_CONFIG = {
'INT_VALUE': (1, 'some int'),
'LONG_VALUE': (123456L, 'some looong int'),
'LONG_VALUE': (long_value, 'some looong int'),
'BOOL_VALUE': (True, 'true or false'),
'STRING_VALUE': ('Hello world', 'greetings'),
'UNICODE_VALUE': ('Rivière-Bonjour'.decode('utf-8'), 'greetings'),
'UNICODE_VALUE': (six.u('Rivière-Bonjour'), 'greetings'),
'DECIMAL_VALUE': (Decimal('0.1'), 'the first release version'),
'DATETIME_VALUE': (datetime(2010, 8, 23, 11, 29, 24), 'time of the first commit'),
'FLOAT_VALUE': (3.1415926536, 'PI'),

View file

@ -49,13 +49,13 @@ class StorageTestsMixin(object):
from constance import config
try:
config.NON_EXISTENT
except Exception, e:
except Exception as e:
pass
self.assertEquals(type(e), AttributeError)
try:
config.NON_EXISTENT = 1
except Exception, e:
except Exception as e:
pass
self.assertEquals(type(e), AttributeError)