summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-11-28 01:18:25 +0000
committerChris McDonough <chrism@agendaless.com>2009-11-28 01:18:25 +0000
commit0970432b72d8f4360b69dc58223ea0725d747d36 (patch)
tree7fe9a6a694055785d2c54ca27e3f0bd2fb01d3b6 /repoze/bfg/tests
parentc91abc312f61c2d012ff7f33b5bce07ecab3007b (diff)
downloadpyramid-0970432b72d8f4360b69dc58223ea0725d747d36.tar.gz
pyramid-0970432b72d8f4360b69dc58223ea0725d747d36.tar.bz2
pyramid-0970432b72d8f4360b69dc58223ea0725d747d36.zip
- Turn paths into resource specs in ZCML directives that use
context.path.
Diffstat (limited to 'repoze/bfg/tests')
-rw-r--r--repoze/bfg/tests/test_zcml.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/repoze/bfg/tests/test_zcml.py b/repoze/bfg/tests/test_zcml.py
index 1954adf64..1f6703d5d 100644
--- a/repoze/bfg/tests/test_zcml.py
+++ b/repoze/bfg/tests/test_zcml.py
@@ -896,6 +896,49 @@ class TestRolledUpFactory(unittest.TestCase):
result = factory(True)
self.assertEqual(result, True)
+class Test_path_spec(unittest.TestCase):
+ def _callFUT(self, context, path):
+ from repoze.bfg.zcml import path_spec
+ return path_spec(context, path)
+
+ def test_no_package_attr(self):
+ context = DummyContext()
+ path = '/thepath'
+ result = self._callFUT(context, path)
+ self.assertEqual(result, path)
+
+ def test_package_attr_None(self):
+ context = DummyContext()
+ context.package = None
+ path = '/thepath'
+ result = self._callFUT(context, path)
+ self.assertEqual(result, path)
+
+ def test_package_path_doesnt_start_with_abspath(self):
+ context = DummyContext()
+ context.package = DummyPackage('repoze.bfg.tests')
+ path = '/thepath'
+ result = self._callFUT(context, path)
+ self.assertEqual(result, path)
+
+ def test_package_path_starts_with_abspath(self):
+ import pkg_resources
+ import os
+ context = DummyContext()
+ package = DummyPackage('repoze.bfg.tests')
+ package_path = pkg_resources.resource_filename('repoze.bfg.tests', '')
+ template_path = os.path.join(package_path, 'templates/foo.pt')
+ context.package = package
+ result = self._callFUT(context, template_path)
+ self.assertEqual(result, 'repoze.bfg.tests:templates/foo.pt')
+
+ def test_package_name_is___main__(self):
+ context = DummyContext()
+ package = DummyPackage('__main__')
+ context.package = package
+ result = self._callFUT(context, '/foo.pt')
+ self.assertEqual(result, '/foo.pt')
+
class IDummy(Interface):
pass
@@ -952,3 +995,7 @@ class DummyRequest:
def copy(self):
return self
+class DummyPackage(object):
+ def __init__(self, name):
+ self.__name__ = name
+