summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2010-08-13 03:03:03 +0000
committerChris McDonough <chrism@agendaless.com>2010-08-13 03:03:03 +0000
commit39480c04dedfcac3b0255f2030a3e58daae7dd0e (patch)
tree7adb9fc0c6bc1dcbe548183a8518c2f91df15d5a /repoze/bfg/tests
parent4576408321cbe3510d8cf594f694b20707fbb17f (diff)
downloadpyramid-39480c04dedfcac3b0255f2030a3e58daae7dd0e.tar.gz
pyramid-39480c04dedfcac3b0255f2030a3e58daae7dd0e.tar.bz2
pyramid-39480c04dedfcac3b0255f2030a3e58daae7dd0e.zip
- The Configurator now accepts a dotted name *string* to a package as
a ``package`` constructor argument. The ``package`` argument was previously required to be a package *object* (not a dotted name string). - The ``repoze.bfg.configuration.Configurator.with_package`` method was added. This method returns a new Configurator using the same application registry as the configurator object it is called upon. The new configurator is created afresh with its ``package`` constructor argument set to the value passed to ``with_package``. This feature will make it easier for future BFG versions to allow dotted names as arguments in places where currently only object references are allowed (the work to allow dotted names isntead of object references everywhere has not yet been done, however). - The ``repoze.bfg.configuration.Configurator.maybe_dotted`` method resolves a Python dotted name string supplied as its ``dotted`` argument to a global Python object. If the value cannot be resolved, a ``repoze.bfg.configuration.ConfigurationError`` is raised. If the value supplied as ``dotted`` is not a string, the value is returned unconditionally without any resolution attempted.
Diffstat (limited to 'repoze/bfg/tests')
-rw-r--r--repoze/bfg/tests/test_configuration.py93
-rw-r--r--repoze/bfg/tests/test_path.py18
2 files changed, 94 insertions, 17 deletions
diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py
index 88c797c0f..f11aee2c1 100644
--- a/repoze/bfg/tests/test_configuration.py
+++ b/repoze/bfg/tests/test_configuration.py
@@ -179,6 +179,37 @@ class ConfiguratorTests(unittest.TestCase):
self.assertEqual(config.registry.getUtility(IRendererFactory, 'yeah'),
renderer)
+ def test_with_package_module(self):
+ from repoze.bfg.tests import test_configuration
+ import repoze.bfg.tests
+ config = self._makeOne()
+ newconfig = config.with_package(test_configuration)
+ self.assertEqual(newconfig.package, repoze.bfg.tests)
+
+ def test_with_package_package(self):
+ import repoze.bfg.tests
+ config = self._makeOne()
+ newconfig = config.with_package(repoze.bfg.tests)
+ self.assertEqual(newconfig.package, repoze.bfg.tests)
+
+ def test_maybe_dotted_string_success(self):
+ import repoze.bfg.tests
+ config = self._makeOne()
+ result = config.maybe_dotted('repoze.bfg.tests')
+ self.assertEqual(result, repoze.bfg.tests)
+
+ def test_maybe_dotted_string_fail(self):
+ from repoze.bfg.configuration import ConfigurationError
+ config = self._makeOne()
+ self.assertRaises(ConfigurationError,
+ config.maybe_dotted, 'cant.be.found')
+
+ def test_maybe_dotted_notstring_success(self):
+ import repoze.bfg.tests
+ config = self._makeOne()
+ result = config.maybe_dotted(repoze.bfg.tests)
+ self.assertEqual(result, repoze.bfg.tests)
+
def test_setup_registry_fixed(self):
class DummyRegistry(object):
def subscribers(self, events, name):
@@ -3604,9 +3635,9 @@ class TestDottedNameResolver(unittest.TestCase):
def test__zope_dottedname_style_resolve_relative_leading_dots(self):
import repoze.bfg.tests.test_configuration
- typ = self._makeOne(package=repoze.bfg.tests.test_configuration)
+ typ = self._makeOne(package=repoze.bfg.tests)
result = typ._zope_dottedname_style(
- '..test_configuration.TestDottedNameResolver')
+ '..tests.test_configuration.TestDottedNameResolver')
self.assertEqual(result, self.__class__)
def test__zope_dottedname_style_resolve_relative_is_dot(self):
@@ -3665,13 +3696,7 @@ class TestDottedNameResolver(unittest.TestCase):
self.assertRaises(ImportError, typ._pkg_resources_style,
'repoze.bfg.tests:nonexisting')
- def test__pkg_resources_style_resolve_relative_startswith_colon(self):
- import repoze.bfg.tests.test_configuration
- typ = self._makeOne(package=repoze.bfg.tests.test_configuration)
- result = typ._pkg_resources_style(':TestDottedNameResolver')
- self.assertEqual(result, self.__class__)
-
- def test__pkg_resources_style_resolve_relative_startswith_dot(self):
+ def test__pkg_resources_style_resolve_relative(self):
import repoze.bfg.tests
typ = self._makeOne(package=repoze.bfg.tests)
result = typ._pkg_resources_style(
@@ -3696,29 +3721,63 @@ class TestDottedNameResolver(unittest.TestCase):
self.assertRaises(ImportError, typ._pkg_resources_style,
':notexisting')
- def test_deserialize_not_a_string(self):
+ def test_resolve_not_a_string(self):
typ = self._makeOne()
- e = self.config_exc(typ, None)
+ e = self.config_exc(typ.resolve, None)
self.assertEqual(e.args[0], 'None is not a string')
- def test_deserialize_using_pkgresources_style(self):
+ def test_resolve_using_pkgresources_style(self):
typ = self._makeOne()
- result = typ(
+ result = typ.resolve(
'repoze.bfg.tests.test_configuration:TestDottedNameResolver')
self.assertEqual(result, self.__class__)
- def test_deserialize_using_zope_dottedname_style(self):
+ def test_resolve_using_zope_dottedname_style(self):
typ = self._makeOne()
- result = typ(
+ result = typ.resolve(
'repoze.bfg.tests.test_configuration:TestDottedNameResolver')
self.assertEqual(result, self.__class__)
- def test_deserialize_style_raises(self):
+ def test_resolve_missing_raises(self):
typ = self._makeOne()
- e = self.config_exc(typ, 'cant.be.found')
+ e = self.config_exc(typ.resolve, 'cant.be.found')
self.assertEqual(e.args[0],
"The dotted name 'cant.be.found' cannot be imported")
+ def test_ctor_string_module_resolveable(self):
+ import repoze.bfg.tests
+ typ = self._makeOne('repoze.bfg.tests.test_configuration')
+ self.assertEqual(typ.package, repoze.bfg.tests)
+ self.assertEqual(typ.package_name, 'repoze.bfg.tests')
+
+ def test_ctor_string_package_resolveable(self):
+ import repoze.bfg.tests
+ typ = self._makeOne('repoze.bfg.tests')
+ self.assertEqual(typ.package, repoze.bfg.tests)
+ self.assertEqual(typ.package_name, 'repoze.bfg.tests')
+
+ def test_ctor_string_irresolveable(self):
+ from repoze.bfg.configuration import ConfigurationError
+ self.assertRaises(ConfigurationError, self._makeOne, 'cant.be.found')
+
+ def test_ctor_module(self):
+ import repoze.bfg.tests
+ import repoze.bfg.tests.test_configuration
+ typ = self._makeOne(repoze.bfg.tests.test_configuration)
+ self.assertEqual(typ.package, repoze.bfg.tests)
+ self.assertEqual(typ.package_name, 'repoze.bfg.tests')
+
+ def test_ctor_package(self):
+ import repoze.bfg.tests
+ typ = self._makeOne(repoze.bfg.tests)
+ self.assertEqual(typ.package, repoze.bfg.tests)
+ self.assertEqual(typ.package_name, 'repoze.bfg.tests')
+
+ def test_ctor_None(self):
+ typ = self._makeOne(None)
+ self.assertEqual(typ.package, None)
+ self.assertEqual(typ.package_name, None)
+
class Test_isexception(unittest.TestCase):
def _callFUT(self, ob):
from repoze.bfg.configuration import isexception
diff --git a/repoze/bfg/tests/test_path.py b/repoze/bfg/tests/test_path.py
index dac32b244..8ee0474f9 100644
--- a/repoze/bfg/tests/test_path.py
+++ b/repoze/bfg/tests/test_path.py
@@ -112,6 +112,24 @@ class TestPackagePath(unittest.TestCase):
self.failIf(hasattr(module, '__bfg_abspath__'))
self.assertEqual(result, module.package_path)
+class TestPackageOf(unittest.TestCase):
+ def _callFUT(self, package):
+ from repoze.bfg.path import package_of
+ return package_of(package)
+
+ def test_it_package(self):
+ from repoze.bfg import tests
+ package = DummyPackageOrModule(tests)
+ result = self._callFUT(package)
+ self.assertEqual(result, tests)
+
+ def test_it_module(self):
+ import repoze.bfg.tests.test_configuration
+ from repoze.bfg import tests
+ package = DummyPackageOrModule(repoze.bfg.tests.test_configuration)
+ result = self._callFUT(package)
+ self.assertEqual(result, tests)
+
class TestPackageName(unittest.TestCase):
def _callFUT(self, package):
from repoze.bfg.path import package_name