From 7f1e1e9918d77958ab7fa5e142883869dbf8dd79 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Thu, 18 Jun 2009 22:17:41 +0000 Subject: Add path module tests. --- repoze/bfg/tests/test_path.py | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 repoze/bfg/tests/test_path.py (limited to 'repoze/bfg/tests/test_path.py') diff --git a/repoze/bfg/tests/test_path.py b/repoze/bfg/tests/test_path.py new file mode 100644 index 000000000..42ab1f8fe --- /dev/null +++ b/repoze/bfg/tests/test_path.py @@ -0,0 +1,51 @@ +import unittest + +class TestCallerPath(unittest.TestCase): + def _callFUT(self, path, level=2, package_globals=None): + from repoze.bfg.path import caller_path + return caller_path(path, level, package_globals) + + def test_isabs(self): + self.assertEqual(self._callFUT('/a/b/c'), '/a/b/c') + + def test_pkgrelative(self): + import os + here = os.path.abspath(os.path.dirname(__file__)) + self.assertEqual(self._callFUT('a/b/c'), os.path.join(here, 'a/b/c')) + + def test_memoization_has_bfg_abspath(self): + import os + here = os.path.abspath(os.path.dirname(__file__)) + package_globals = {'__bfg_abspath__':'/foo/bar'} + self.assertEqual( + self._callFUT('a/b/c', + package_globals=package_globals), + os.path.join('/foo/bar', 'a/b/c')) + + def test_memoization_success(self): + import os + here = os.path.abspath(os.path.dirname(__file__)) + package_globals = {'__name__':'repoze.bfg.tests.test_path'} + self.assertEqual( + self._callFUT('a/b/c', + package_globals=package_globals), + os.path.join(here, 'a/b/c')) + self.assertEqual(package_globals['__bfg_abspath__'], here) + + def test_memoization_fail(self): + import os + here = os.path.abspath(os.path.dirname(__file__)) + class faildict(dict): + def __setitem__(self, *arg): + raise KeyError('name') + package_globals = faildict({'__name__':'repoze.bfg.tests.test_path'}) + self.assertEqual( + self._callFUT('a/b/c', + package_globals=package_globals), + os.path.join(here, 'a/b/c')) + self.failIf('__bfg_abspath__' in package_globals) + + + + + -- cgit v1.2.3