summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-11-20 05:38:38 +0000
committerChris McDonough <chrism@agendaless.com>2009-11-20 05:38:38 +0000
commit15a3c6f561563eb53ff1cc3637fc6afa75da9e89 (patch)
tree94134ee3c1099c30cae283d4cb7e1a8d68db45bf /repoze/bfg/tests
parent601e038028655549d23f8eda1c21cb0034724771 (diff)
downloadpyramid-15a3c6f561563eb53ff1cc3637fc6afa75da9e89.tar.gz
pyramid-15a3c6f561563eb53ff1cc3637fc6afa75da9e89.tar.bz2
pyramid-15a3c6f561563eb53ff1cc3637fc6afa75da9e89.zip
Passable stab at supporting an imperative mode.
ZCML directives which accept paths now register absolute paths, while imperative registrations now register resource specifications.
Diffstat (limited to 'repoze/bfg/tests')
-rw-r--r--repoze/bfg/tests/test_configuration.py59
-rw-r--r--repoze/bfg/tests/test_renderers.py47
-rw-r--r--repoze/bfg/tests/test_resource.py31
-rw-r--r--repoze/bfg/tests/test_router.py18
-rw-r--r--repoze/bfg/tests/test_zcml.py5
5 files changed, 47 insertions, 113 deletions
diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py
index 379609cdc..e427823fa 100644
--- a/repoze/bfg/tests/test_configuration.py
+++ b/repoze/bfg/tests/test_configuration.py
@@ -127,64 +127,28 @@ class ConfiguratorTests(unittest.TestCase):
self.assertEqual(len(subscriber), 1)
def test_declarative_fixtureapp_default_filename_withpackage(self):
- from repoze.bfg.tests import fixtureapp
- rootfactory = DummyRootFactory(None)
- registry = self._callDeclarative(rootfactory, fixtureapp)
- from repoze.bfg.tests.fixtureapp.models import IFixture
- self.failUnless(registry.queryUtility(IFixture)) # only in c.zcml
-
- def test_declarative_fixtureapp_explicit_filename(self):
- from repoze.bfg.tests import fixtureapp
- rootfactory = DummyRootFactory(None)
- registry = self._callDeclarative(
- rootfactory, fixtureapp, filename='another.zcml')
- from repoze.bfg.tests.fixtureapp.models import IFixture
- self.failIf(registry.queryUtility(IFixture)) # only in c.zcml
-
- def test_declarative_fixtureapp_explicit_filename_in_settings(self):
- import os
rootfactory = DummyRootFactory(None)
- from repoze.bfg.tests import fixtureapp
- zcmlfile = os.path.join(os.path.dirname(fixtureapp.__file__),
- 'another.zcml')
registry = self._callDeclarative(
- rootfactory, fixtureapp, filename='configure.zcml',
- settings={'configure_zcml':zcmlfile})
+ rootfactory,
+ 'repoze.bfg.tests.fixtureapp:configure.zcml')
from repoze.bfg.tests.fixtureapp.models import IFixture
- self.failIf(registry.queryUtility(IFixture)) # only in c.zcml
+ self.failUnless(registry.queryUtility(IFixture)) # only in c.zcml
def test_declarative_fixtureapp_explicit_specification_in_settings(self):
rootfactory = DummyRootFactory(None)
- from repoze.bfg.tests import fixtureapp
zcmlfile = 'repoze.bfg.tests.fixtureapp.subpackage:yetanother.zcml'
registry = self._callDeclarative(
- rootfactory, fixtureapp, filename='configure.zcml',
+ rootfactory, 'repoze.bfg.tests.fixtureapp:configure.zcml',
settings={'configure_zcml':zcmlfile})
from repoze.bfg.tests.fixtureapp.models import IFixture
self.failIf(registry.queryUtility(IFixture)) # only in c.zcml
- def test_declarative_fixtureapp_filename_hascolon_isabs(self):
- rootfactory = DummyRootFactory(None)
- from repoze.bfg.tests import fixtureapp
- zcmlfile = 'repoze.bfg.tests.fixtureapp.subpackage:yetanother.zcml'
- class Dummy:
- def isabs(self, name):
- return True
- os = Dummy()
- os.path = Dummy()
- self.assertRaises(IOError, self._callDeclarative,
- rootfactory,
- fixtureapp,
- filename='configure.zcml',
- settings={'configure_zcml':zcmlfile},
- os=os)
-
def test_declarative_custom_settings(self):
settings = {'mysetting':True}
- from repoze.bfg.tests import fixtureapp
rootfactory = DummyRootFactory(None)
registry = self._callDeclarative(
- rootfactory, fixtureapp, settings=settings)
+ rootfactory, 'repoze.bfg.tests.fixtureapp:configure.zcml',
+ settings=settings)
from repoze.bfg.interfaces import ISettings
settings = registry.getUtility(ISettings)
self.assertEqual(settings.reload_templates, False)
@@ -194,10 +158,10 @@ class ConfiguratorTests(unittest.TestCase):
def test_declarative_registrations(self):
settings = {'reload_templates':True,
'debug_authorization':True}
- from repoze.bfg.tests import fixtureapp
rootfactory = DummyRootFactory(None)
registry = self._callDeclarative(
- rootfactory, fixtureapp, settings=settings)
+ rootfactory, 'repoze.bfg.tests.fixtureapp:configure.zcml',
+ settings=settings)
from repoze.bfg.interfaces import ISettings
from repoze.bfg.interfaces import ILogger
from repoze.bfg.interfaces import IRootFactory
@@ -216,21 +180,20 @@ class ConfiguratorTests(unittest.TestCase):
from repoze.bfg.interfaces import IRoutesMapper
settings = {'reload_templates':True,
'debug_authorization':True}
- from repoze.bfg.tests import routesapp
rootfactory = DummyRootFactory(None)
registry = self._callDeclarative(
- rootfactory, routesapp, settings=settings)
+ rootfactory, 'repoze.bfg.tests.routesapp:configure.zcml',
+ settings=settings)
settings = registry.getUtility(ISettings)
logger = registry.getUtility(ILogger, name='repoze.bfg.debug')
self.assertEqual(registry.getUtility(IRootFactory), rootfactory)
self.failUnless(registry.getUtility(IRoutesMapper))
def test_declarative_lock_and_unlock(self):
- from repoze.bfg.tests import fixtureapp
rootfactory = DummyRootFactory(None)
dummylock = DummyLock()
registry = self._callDeclarative(
- rootfactory, fixtureapp, filename='configure.zcml',
+ rootfactory, 'repoze.bfg.tests.fixtureapp:configure.zcml',
lock=dummylock)
self.assertEqual(dummylock.acquired, True)
self.assertEqual(dummylock.released, True)
diff --git a/repoze/bfg/tests/test_renderers.py b/repoze/bfg/tests/test_renderers.py
index a330d19da..d94ffbc1e 100644
--- a/repoze/bfg/tests/test_renderers.py
+++ b/repoze/bfg/tests/test_renderers.py
@@ -10,9 +10,9 @@ class TestTemplateRendererFactory(unittest.TestCase):
def tearDown(self):
cleanUp()
- def _callFUT(self, path, factory, level=3):
+ def _callFUT(self, path, factory):
from repoze.bfg.renderers import template_renderer_factory
- return template_renderer_factory(path, factory, level)
+ return template_renderer_factory(path, factory)
def test_abspath_notfound(self):
from repoze.bfg.interfaces import ITemplateRenderer
@@ -52,27 +52,11 @@ class TestTemplateRendererFactory(unittest.TestCase):
result = self._callFUT('foo:bar/baz', None)
self.failUnless(renderer is result)
- def test_relpath_notfound(self):
- self.assertRaises(ValueError, self._callFUT, 'wont/exist', None)
-
- def test_relpath_is_package_notfound(self):
- from repoze.bfg import tests
- module_name = tests.__name__
+ def test_spec_notfound(self):
self.assertRaises(ValueError, self._callFUT,
- '%s:wont/exist' % module_name, None)
-
- def test_relpath_alreadyregistered(self):
- from repoze.bfg.interfaces import ITemplateRenderer
- from repoze.bfg import tests
- module_name = tests.__name__
- relpath = 'test_renderers.py'
- spec = '%s:%s' % (module_name, relpath)
- renderer = {}
- testing.registerUtility(renderer, ITemplateRenderer, name=spec)
- result = self._callFUT('test_renderers.py', None)
- self.failUnless(result is renderer)
+ 'repoze.bfg.tests:wont/exist', None)
- def test_relpath_is_package_alreadyregistered(self):
+ def test_spec_alreadyregistered(self):
from repoze.bfg.interfaces import ITemplateRenderer
from repoze.bfg import tests
module_name = tests.__name__
@@ -83,22 +67,7 @@ class TestTemplateRendererFactory(unittest.TestCase):
result = self._callFUT(spec, None)
self.failUnless(result is renderer)
- def test_relpath_notyetregistered(self):
- import os
- from repoze.bfg.tests import test_renderers
- module_name = test_renderers.__name__
- relpath = 'test_renderers.py'
- renderer = {}
- factory = DummyFactory(renderer)
- result = self._callFUT('test_renderers.py', factory)
- self.failUnless(result is renderer)
- path = os.path.abspath(__file__)
- if path.endswith('pyc'): # pragma: no cover
- path = path[:-1]
- self.assertEqual(factory.path, path)
- self.assertEqual(factory.kw, {})
-
- def test_relpath_is_package_notyetregistered(self):
+ def test_spec_notyetregistered(self):
import os
from repoze.bfg import tests
module_name = tests.__name__
@@ -122,7 +91,7 @@ class TestTemplateRendererFactory(unittest.TestCase):
testing.registerUtility(settings, ISettings)
renderer = {}
factory = DummyFactory(renderer)
- result = self._callFUT('test_renderers.py', factory)
+ result = self._callFUT('repoze.bfg.tests:test_renderers.py', factory)
self.failUnless(result is renderer)
spec = '%s:%s' % ('repoze.bfg.tests', 'test_renderers.py')
self.assertEqual(queryUtility(ITemplateRenderer, name=spec),
@@ -136,7 +105,7 @@ class TestTemplateRendererFactory(unittest.TestCase):
testing.registerUtility(settings, ISettings)
renderer = {}
factory = DummyFactory(renderer)
- result = self._callFUT('test_renderers.py', factory)
+ result = self._callFUT('repoze.bfg.tests:test_renderers.py', factory)
self.failUnless(result is renderer)
spec = '%s:%s' % ('repoze.bfg.tests', 'test_renderers.py')
self.assertNotEqual(queryUtility(ITemplateRenderer, name=spec),
diff --git a/repoze/bfg/tests/test_resource.py b/repoze/bfg/tests/test_resource.py
index efdc15c63..f14d9860d 100644
--- a/repoze/bfg/tests/test_resource.py
+++ b/repoze/bfg/tests/test_resource.py
@@ -341,27 +341,32 @@ class TestDirectoryOverride(unittest.TestCase):
result = o('baz/notfound.pt')
self.assertEqual(result, None)
-class Test_resource_spec(unittest.TestCase):
- def _callFUT(self, path, package):
- from repoze.bfg.resource import resource_spec
- return resource_spec(path, package)
+class Test_resolve_resource_spec(unittest.TestCase):
+ def _callFUT(self, spec, package_name='__main__'):
+ from repoze.bfg.resource import resolve_resource_spec
+ return resolve_resource_spec(spec, package_name)
def test_abspath(self):
import os
here = os.path.dirname(__file__)
- path= os.path.abspath(here)
- self.assertEqual(self._callFUT(path, 'apackage'), path)
+ path = os.path.abspath(here)
+ package_name, filename = self._callFUT(path, 'apackage')
+ self.assertEqual(filename, path)
+ self.assertEqual(package_name, None)
def test_rel_spec(self):
- pkg, path = 'repoze.bfg.tests', 'test_resource.py'
- self.assertEqual(self._callFUT(path, pkg),
- 'repoze.bfg.tests:test_resource.py')
+ pkg = 'repoze.bfg.tests'
+ path = 'test_resource.py'
+ package_name, filename = self._callFUT(path, pkg)
+ self.assertEqual(package_name, 'repoze.bfg.tests')
+ self.assertEqual(filename, 'test_resource.py')
def test_abs_spec(self):
- pkg, path = 'repoze.bfg.tests', 'repoze.bfg.nottests:test_resource.py'
- self.assertEqual(self._callFUT(path, pkg),
- 'repoze.bfg.nottests:test_resource.py')
-
+ pkg = 'repoze.bfg.tests'
+ path = 'repoze.bfg.nottests:test_resource.py'
+ package_name, filename = self._callFUT(path, pkg)
+ self.assertEqual(package_name, 'repoze.bfg.nottests')
+ self.assertEqual(filename, 'test_resource.py')
class TestFileOverride(unittest.TestCase):
def _getTargetClass(self):
diff --git a/repoze/bfg/tests/test_router.py b/repoze/bfg/tests/test_router.py
index e747a26e6..2fc31419a 100644
--- a/repoze/bfg/tests/test_router.py
+++ b/repoze/bfg/tests/test_router.py
@@ -529,25 +529,21 @@ class TestMakeApp(unittest.TestCase):
def test_it(self):
settings = {'a':1}
- package = object()
rootfactory = object()
- app = self._callFUT(rootfactory, package, settings=settings,
+ app = self._callFUT(rootfactory, settings=settings,
Configurator=DummyConfigurator)
self.assertEqual(app.root_factory, rootfactory)
self.assertEqual(app.settings, settings)
- self.assertEqual(app.package, package)
- self.assertEqual(app.filename, 'configure.zcml')
+ self.assertEqual(app.spec, 'configure.zcml')
def test_it_options_means_settings(self):
settings = {'a':1}
- package = object()
rootfactory = object()
- app = self._callFUT(rootfactory, package, options=settings,
+ app = self._callFUT(rootfactory, options=settings,
Configurator=DummyConfigurator)
self.assertEqual(app.root_factory, rootfactory)
self.assertEqual(app.settings, settings)
- self.assertEqual(app.package, package)
- self.assertEqual(app.filename, 'configure.zcml')
+ self.assertEqual(app.spec, 'configure.zcml')
class DummyContext:
pass
@@ -616,10 +612,8 @@ class DummyConfigurator(object):
def make_wsgi_app(self):
return self
- def declarative(self, root_factory=None, package=None,
- filename=None, settings=None):
+ def declarative(self, root_factory=None, spec=None, settings=None):
self.root_factory = root_factory
- self.package = package
- self.filename = filename
+ self.spec = spec
self.settings = settings
diff --git a/repoze/bfg/tests/test_zcml.py b/repoze/bfg/tests/test_zcml.py
index 608c69f51..4623ea3b1 100644
--- a/repoze/bfg/tests/test_zcml.py
+++ b/repoze/bfg/tests/test_zcml.py
@@ -499,7 +499,7 @@ class TestStaticDirective(unittest.TestCase):
discriminator = route_action['discriminator']
self.assertEqual(discriminator,
('route', 'name', False, None, None, None, None, None))
- route_action['callable']()
+ route_action['callable'](*route_action['args'])
mapper = sm.getUtility(IRoutesMapper)
routes = mapper.get_routes()
self.assertEqual(len(routes), 1)
@@ -649,6 +649,9 @@ class DummyContext:
'args':args}
)
+ def path(self, path):
+ return path
+
def resolve(self, dottedname):
return self.resolved