From 89b423fa6584e73cf90a2042c999702e6de0d2fd Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Fri, 12 Apr 2013 17:25:11 +0200 Subject: [PATCH] First stab at Python 3 support. --- .travis.yml | 18 +++++++++++++++--- README.rst | 3 +++ constance/admin.py | 19 +++++++++++-------- setup.py | 7 +++++-- tests/settings.py | 14 +++++++++----- tests/storage.py | 4 ++-- 6 files changed, 45 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6e0da0a..0c4379f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.rst b/README.rst index d468da0..1177f50 100644 --- a/README.rst +++ b/README.rst @@ -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) ~~~~~~~~~~~~~~~~~ diff --git a/constance/admin.py b/constance/admin.py index c7af7e5..78a6af6 100644 --- a/constance/admin.py +++ b/constance/admin.py @@ -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 diff --git a/setup.py b/setup.py index 4b78875..6c71b4c 100644 --- a/setup.py +++ b/setup.py @@ -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'], } diff --git a/tests/settings.py b/tests/settings.py index e1a4401..af27c2f 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -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'), diff --git a/tests/storage.py b/tests/storage.py index d5eb916..0a9e710 100644 --- a/tests/storage.py +++ b/tests/storage.py @@ -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)