From 1265e18a983cdb4ba2b67528f25c348a709bd78f Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Thu, 26 Jan 2012 17:50:45 +0100 Subject: [PATCH] Moved tests into a new appconf package. Shouldn't have any different behavior. --- appconf/__init__.py | 5 +++ appconf.py => appconf/base.py | 28 ++---------- tests/settings.py => appconf/test_settings.py | 2 +- {tests => appconf/tests}/__init__.py | 0 {tests/testapp => appconf/tests}/models.py | 2 +- {tests/testapp => appconf/tests}/settings.py | 0 {tests/testapp => appconf/tests}/tests.py | 44 +++++++++---------- appconf/utils.py | 22 ++++++++++ setup.py | 5 ++- tests/testapp/__init__.py | 0 tox.ini | 4 +- 11 files changed, 60 insertions(+), 52 deletions(-) create mode 100644 appconf/__init__.py rename appconf.py => appconf/base.py (83%) rename tests/settings.py => appconf/test_settings.py (95%) rename {tests => appconf/tests}/__init__.py (100%) rename {tests/testapp => appconf/tests}/models.py (94%) rename {tests/testapp => appconf/tests}/settings.py (100%) rename {tests/testapp => appconf/tests}/tests.py (69%) create mode 100644 appconf/utils.py delete mode 100644 tests/testapp/__init__.py diff --git a/appconf/__init__.py b/appconf/__init__.py new file mode 100644 index 0000000..f10c2e6 --- /dev/null +++ b/appconf/__init__.py @@ -0,0 +1,5 @@ +from __future__ import absolute_import +from .base import AppConf # noqa + +# following PEP 386, versiontools will pick it up +__version__ = (0, 4, 1, "final", 0) diff --git a/appconf.py b/appconf/base.py similarity index 83% rename from appconf.py rename to appconf/base.py index 2c2e6a6..80eb233 100644 --- a/appconf.py +++ b/appconf/base.py @@ -1,7 +1,5 @@ import sys - -# following PEP 386, versiontools will pick it up -__version__ = (0, 4, 1, "final", 0) +from .utils import import_attribute class AppConfOptions(object): @@ -56,7 +54,8 @@ class AppConfMetaClass(type): if hasattr(parent, '_meta'): new_class._meta.names.update(parent._meta.names) new_class._meta.defaults.update(parent._meta.defaults) - new_class._meta.configured_data.update(parent._meta.configured_data) + new_class._meta.configured_data.update( + parent._meta.configured_data) for name in filter(lambda name: name == name.upper(), attrs): prefixed_name = new_class._meta.prefixed_name(name) @@ -93,27 +92,6 @@ class AppConfMetaClass(type): cls._meta.configured_data = obj.configure() -def import_attribute(import_path, exception_handler=None): - from django.utils.importlib import import_module - module_name, object_name = import_path.rsplit('.', 1) - try: - module = import_module(module_name) - except: # pragma: no cover - if callable(exception_handler): - exctype, excvalue, tb = sys.exc_info() - return exception_handler(import_path, exctype, excvalue, tb) - else: - raise - try: - return getattr(module, object_name) - except: # pragma: no cover - if callable(exception_handler): - exctype, excvalue, tb = sys.exc_info() - return exception_handler(import_path, exctype, excvalue, tb) - else: - raise - - class AppConf(object): """ An app setting object to be used for handling app setting defaults diff --git a/tests/settings.py b/appconf/test_settings.py similarity index 95% rename from tests/settings.py rename to appconf/test_settings.py index 084c7fc..263a0aa 100644 --- a/tests/settings.py +++ b/appconf/test_settings.py @@ -13,7 +13,7 @@ INSTALLED_APPS = [ 'django.contrib.auth', 'django.contrib.admin', 'django_jenkins', - 'tests.testapp', + 'appconf.tests', ] JENKINS_TASKS = ( diff --git a/tests/__init__.py b/appconf/tests/__init__.py similarity index 100% rename from tests/__init__.py rename to appconf/tests/__init__.py diff --git a/tests/testapp/models.py b/appconf/tests/models.py similarity index 94% rename from tests/testapp/models.py rename to appconf/tests/models.py index 19f174f..cb96f83 100644 --- a/tests/testapp/models.py +++ b/appconf/tests/models.py @@ -61,5 +61,5 @@ class CustomHolderConf(AppConf): SIMPLE_VALUE = True class Meta: - holder = 'tests.testapp.models.custom_holder' # instead of django.conf.settings + holder = 'appconf.tests.models.custom_holder' # instead of django.conf.settings prefix = 'custom_holder' diff --git a/tests/testapp/settings.py b/appconf/tests/settings.py similarity index 100% rename from tests/testapp/settings.py rename to appconf/tests/settings.py diff --git a/tests/testapp/tests.py b/appconf/tests/tests.py similarity index 69% rename from tests/testapp/tests.py rename to appconf/tests/tests.py index f6cd40a..45738a6 100644 --- a/tests/testapp/tests.py +++ b/appconf/tests/tests.py @@ -10,50 +10,50 @@ from .models import (TestConf, PrefixConf, YetAnotherPrefixConf, class TestConfTests(TestCase): def test_basic(self): - self.assertEquals(TestConf._meta.prefix, 'testapp') + self.assertEquals(TestConf._meta.prefix, 'tests') def test_simple(self): - self.assertTrue(hasattr(settings, 'TESTAPP_SIMPLE_VALUE')) - self.assertEquals(settings.TESTAPP_SIMPLE_VALUE, True) + self.assertTrue(hasattr(settings, 'TESTS_SIMPLE_VALUE')) + self.assertEquals(settings.TESTS_SIMPLE_VALUE, True) def test_configured(self): - self.assertTrue(hasattr(settings, 'TESTAPP_CONFIGURED_VALUE')) - self.assertEquals(settings.TESTAPP_CONFIGURED_VALUE, 'correct') + self.assertTrue(hasattr(settings, 'TESTS_CONFIGURED_VALUE')) + self.assertEquals(settings.TESTS_CONFIGURED_VALUE, 'correct') def test_configure_method(self): - self.assertTrue(hasattr(settings, 'TESTAPP_CONFIGURE_METHOD_VALUE')) - self.assertEquals(settings.TESTAPP_CONFIGURE_METHOD_VALUE, True) + self.assertTrue(hasattr(settings, 'TESTS_CONFIGURE_METHOD_VALUE')) + self.assertEquals(settings.TESTS_CONFIGURE_METHOD_VALUE, True) def test_init_kwargs(self): custom_conf = TestConf(CUSTOM_VALUE='custom') self.assertEquals(custom_conf.CUSTOM_VALUE, 'custom') - self.assertEquals(settings.TESTAPP_CUSTOM_VALUE, 'custom') - self.assertRaises(AttributeError, lambda: custom_conf.TESTAPP_CUSTOM_VALUE) + self.assertEquals(settings.TESTS_CUSTOM_VALUE, 'custom') + self.assertRaises(AttributeError, lambda: custom_conf.TESTS_CUSTOM_VALUE) custom_conf.CUSTOM_VALUE_SETATTR = 'custom' - self.assertEquals(settings.TESTAPP_CUSTOM_VALUE_SETATTR, 'custom') + self.assertEquals(settings.TESTS_CUSTOM_VALUE_SETATTR, 'custom') custom_conf.custom_value_lowercase = 'custom' self.assertRaises(AttributeError, lambda: settings.custom_value_lowercase) def test_init_kwargs_with_prefix(self): - custom_conf = TestConf(TESTAPP_CUSTOM_VALUE2='custom2') - self.assertEquals(custom_conf.TESTAPP_CUSTOM_VALUE2, 'custom2') - self.assertEquals(settings.TESTAPP_CUSTOM_VALUE2, 'custom2') + custom_conf = TestConf(TESTS_CUSTOM_VALUE2='custom2') + self.assertEquals(custom_conf.TESTS_CUSTOM_VALUE2, 'custom2') + self.assertEquals(settings.TESTS_CUSTOM_VALUE2, 'custom2') def test_proxy(self): custom_conf = ProxyConf(CUSTOM_VALUE3='custom3') self.assertEquals(custom_conf.CUSTOM_VALUE3, 'custom3') - self.assertEquals(settings.TESTAPP_CUSTOM_VALUE3, 'custom3') - self.assertEquals(custom_conf.TESTAPP_CUSTOM_VALUE3, 'custom3') - self.assertTrue('tests.testapp' in custom_conf.INSTALLED_APPS) + self.assertEquals(settings.TESTS_CUSTOM_VALUE3, 'custom3') + self.assertEquals(custom_conf.TESTS_CUSTOM_VALUE3, 'custom3') + self.assertTrue('appconf.tests' in custom_conf.INSTALLED_APPS) def test_dir_members(self): custom_conf = TestConf() - self.assertTrue('TESTAPP_SIMPLE_VALUE' in dir(settings)) - self.assertTrue('TESTAPP_SIMPLE_VALUE' in settings.__members__) + self.assertTrue('TESTS_SIMPLE_VALUE' in dir(settings)) + self.assertTrue('TESTS_SIMPLE_VALUE' in settings.__members__) self.assertTrue('SIMPLE_VALUE' in dir(custom_conf)) self.assertTrue('SIMPLE_VALUE' in custom_conf.__members__) - self.assertFalse('TESTAPP_SIMPLE_VALUE' in dir(custom_conf)) - self.assertFalse('TESTAPP_SIMPLE_VALUE' in custom_conf.__members__) + self.assertFalse('TESTS_SIMPLE_VALUE' in dir(custom_conf)) + self.assertFalse('TESTS_SIMPLE_VALUE' in custom_conf.__members__) def test_custom_holder(self): custom_conf = CustomHolderConf() @@ -61,8 +61,8 @@ class TestConfTests(TestCase): self.assertEquals(custom_holder.CUSTOM_HOLDER_SIMPLE_VALUE, True) def test_subclass_configured_data(self): - self.assertTrue('TESTAPP_CONFIGURE_METHOD_VALUE2' in dir(settings)) - self.assertEquals(settings.TESTAPP_CONFIGURE_METHOD_VALUE2, False) + self.assertTrue('TESTS_CONFIGURE_METHOD_VALUE2' in dir(settings)) + self.assertEquals(settings.TESTS_CONFIGURE_METHOD_VALUE2, False) class PrefixConfTests(TestCase): diff --git a/appconf/utils.py b/appconf/utils.py new file mode 100644 index 0000000..e8f911c --- /dev/null +++ b/appconf/utils.py @@ -0,0 +1,22 @@ +import sys + + +def import_attribute(import_path, exception_handler=None): + from django.utils.importlib import import_module + module_name, object_name = import_path.rsplit('.', 1) + try: + module = import_module(module_name) + except: # pragma: no cover + if callable(exception_handler): + exctype, excvalue, tb = sys.exc_info() + return exception_handler(import_path, exctype, excvalue, tb) + else: + raise + try: + return getattr(module, object_name) + except: # pragma: no cover + if callable(exception_handler): + exctype, excvalue, tb = sys.exc_info() + return exception_handler(import_path, exctype, excvalue, tb) + else: + raise diff --git a/setup.py b/setup.py index 764cfe8..84214a6 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,10 @@ setup( author_email='jannis@leidel.info', license = 'BSD', url='http://django-appconf.readthedocs.org/', - py_modules=['appconf'], + packages=[ + 'appconf', + 'appconf.tests', + ], classifiers=[ "Development Status :: 4 - Beta", 'Environment :: Web Environment', diff --git a/tests/testapp/__init__.py b/tests/testapp/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tox.ini b/tox.ini index 7a206bb..6b5e296 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,9 @@ [testenv] downloadcache = {toxworkdir}/_download/ commands = - {envbindir}/python {envbindir}/django-admin.py jenkins {posargs:testapp} + {envbindir}/python {envbindir}/django-admin.py jenkins {posargs:tests} setenv = - DJANGO_SETTINGS_MODULE = tests.settings + DJANGO_SETTINGS_MODULE = appconf.test_settings [testenv:docs] basepython = python2.7