def test_get_callable(self): self.assertEqual(get_callable(func), func) self.assertEqual(get_callable('tests.test_utils.func'), func) # ValueError for relative imports self.assertRaises(ValueError, get_callable, 'func') # ImportError for nonexistent module self.assertRaises(ImportError, get_callable, 'notamodule.func') # ImportError for nonexistent attribute self.assertRaises(ImportError, get_callable, 'shunter.notacallable') # ImportError for noncallable attribute self.assertRaises(ImportError, get_callable, 'tests.test_utils.a_string')
def add_route(self, regexp, target, extra={}): """Add a route :param regexp: A regular expression, r'^/example/(?<page>\w+)$' :param target: A callable, or the name of one, 'module.submodule.view' :param extra: Extra kwargs """ self.routes.append( (re.compile(regexp, re.UNICODE), get_callable(target), extra) )