本文整理汇总了Python中pyramid.configuration.Configurator.add_settings方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_settings方法的具体用法?Python Configurator.add_settings怎么用?Python Configurator.add_settings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.configuration.Configurator
的用法示例。
在下文中一共展示了Configurator.add_settings方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: registerSettings
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_settings [as 别名]
def registerSettings(dictarg=None, **kw):
"""Register one or more 'setting' key/value pairs. A setting is
a single key/value pair in the dictionary-ish object returned from
the API :attr:`pyramid.registry.Registry.settings`.
You may pass a dictionary::
registerSettings({'external_uri':'http://example.com'})
Or a set of key/value pairs::
registerSettings(external_uri='http://example.com')
Use of this function is required when you need to test code that calls
the :attr:`pyramid.registry.Registry.settings` API and which uses return
values from that API.
.. warning:: This API is deprecated as of :app:`Pyramid` 1.0.
Instead use the
:meth:`pyramid.configuration.Configurator.add_settings`
method in your unit and integration tests.
"""
registry = get_current_registry()
config = Configurator(registry=registry)
config.add_settings(dictarg, **kw)
示例2: TestIntegration
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_settings [as 别名]
class TestIntegration(unittest.TestCase):
def setUp(self):
import pyramid.mako_templating
from pyramid.configuration import Configurator
self.config = Configurator()
self.config.begin()
self.config.add_settings({'mako.directories':
'pyramid.tests:fixtures'})
self.config.add_renderer('.mak',
pyramid.mako_templating.renderer_factory)
def tearDown(self):
self.config.end()
def test_render(self):
from pyramid.renderers import render
result = render('helloworld.mak', {'a':1})
self.assertEqual(result, u'\nHello föö\n')
def test_render_to_response(self):
from pyramid.renderers import render_to_response
result = render_to_response('helloworld.mak', {'a':1})
self.assertEqual(result.ubody, u'\nHello föö\n')
def test_get_renderer(self):
from pyramid.renderers import get_renderer
result = get_renderer('helloworld.mak')
self.assertEqual(result.implementation().render_unicode(),
u'\nHello föö\n')
示例3: TextTemplateRendererTests
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_settings [as 别名]
class TextTemplateRendererTests(Base, unittest.TestCase):
def setUp(self):
from pyramid.configuration import Configurator
from pyramid.registry import Registry
registry = Registry()
self.config = Configurator(registry=registry)
self.config.begin()
def tearDown(self):
self.config.end()
def _getTargetClass(self):
from pyramid.chameleon_text import TextTemplateRenderer
return TextTemplateRenderer
def _makeOne(self, *arg, **kw):
klass = self._getTargetClass()
return klass(*arg, **kw)
def test_instance_implements_ITemplate(self):
from zope.interface.verify import verifyObject
from pyramid.interfaces import ITemplateRenderer
path = self._getTemplatePath('minimal.txt')
verifyObject(ITemplateRenderer, self._makeOne(path))
def test_class_implements_ITemplate(self):
from zope.interface.verify import verifyClass
from pyramid.interfaces import ITemplateRenderer
verifyClass(ITemplateRenderer, self._getTargetClass())
def test_template_reified(self):
minimal = self._getTemplatePath('minimal.txt')
instance = self._makeOne(minimal)
self.failIf('template' in instance.__dict__)
template = instance.template
self.assertEqual(template, instance.__dict__['template'])
def test_template_with_ichameleon_translate(self):
from pyramid.interfaces import IChameleonTranslate
def ct(): pass
self.config.registry.registerUtility(ct, IChameleonTranslate)
minimal = self._getTemplatePath('minimal.txt')
instance = self._makeOne(minimal)
self.failIf('template' in instance.__dict__)
template = instance.template
self.assertEqual(template.translate, ct)
def test_template_with_debug_templates(self):
self.config.add_settings({'debug_templates':True})
minimal = self._getTemplatePath('minimal.txt')
instance = self._makeOne(minimal)
self.failIf('template' in instance.__dict__)
template = instance.template
self.assertEqual(template.debug, True)
def test_template_with_reload_templates(self):
self.config.add_settings({'reload_templates':True})
minimal = self._getTemplatePath('minimal.txt')
instance = self._makeOne(minimal)
self.failIf('template' in instance.__dict__)
template = instance.template
self.assertEqual(template.auto_reload, True)
def test_template_with_emptydict(self):
from pyramid.interfaces import ISettings
self.config.registry.registerUtility({}, ISettings)
minimal = self._getTemplatePath('minimal.txt')
instance = self._makeOne(minimal)
self.failIf('template' in instance.__dict__)
template = instance.template
self.assertEqual(template.auto_reload, False)
self.assertEqual(template.debug, False)
def test_call(self):
minimal = self._getTemplatePath('minimal.txt')
instance = self._makeOne(minimal)
result = instance({}, {})
self.failUnless(isinstance(result, str))
self.assertEqual(result, 'Hello.\n')
def test_call_with_nondict_value(self):
minimal = self._getTemplatePath('minimal.txt')
instance = self._makeOne(minimal)
self.assertRaises(ValueError, instance, None, {})
def test_call_nonminimal(self):
nonminimal = self._getTemplatePath('nonminimal.txt')
instance = self._makeOne(nonminimal)
result = instance({'name':'Chris'}, {})
self.failUnless(isinstance(result, str))
self.assertEqual(result, 'Hello, Chris!\n')
def test_implementation(self):
minimal = self._getTemplatePath('minimal.txt')
instance = self._makeOne(minimal)
result = instance.implementation()()
self.failUnless(isinstance(result, str))
self.assertEqual(result, 'Hello.\n')
示例4: TestIntegration
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_settings [as 别名]
class TestIntegration(unittest.TestCase):
def setUp(self):
import pyramid.mako_templating
from pyramid.configuration import Configurator
self.config = Configurator()
self.config.begin()
self.config.add_settings({'mako.directories':
'pyramid.tests:fixtures'})
self.config.add_renderer('.mak',
pyramid.mako_templating.renderer_factory)
def tearDown(self):
self.config.end()
def test_render(self):
from pyramid.renderers import render
result = render('helloworld.mak', {'a':1})
self.assertEqual(result, u'\nHello föö\n')
def test_render_from_fs(self):
from pyramid.renderers import render
self.config.add_settings({'reload_templates': True})
result = render('helloworld.mak', {'a':1})
self.assertEqual(result, u'\nHello föö\n')
def test_render_inheritance(self):
from pyramid.renderers import render
result = render('helloinherit.mak', {})
self.assertEqual(result, u'Layout\nHello World!\n')
def test_render_inheritance_pkg_spec(self):
from pyramid.renderers import render
result = render('hello_inherit_pkg.mak', {})
self.assertEqual(result, u'Layout\nHello World!\n')
def test_render_to_response(self):
from pyramid.renderers import render_to_response
result = render_to_response('helloworld.mak', {'a':1})
self.assertEqual(result.ubody, u'\nHello föö\n')
def test_render_to_response_pkg_spec(self):
from pyramid.renderers import render_to_response
result = render_to_response('pyramid.tests:fixtures/helloworld.mak', {'a':1})
self.assertEqual(result.ubody, u'\nHello föö\n')
def test_render_with_abs_path(self):
from pyramid.renderers import render
result = render('/helloworld.mak', {'a':1})
self.assertEqual(result, u'\nHello föö\n')
def test_get_renderer(self):
from pyramid.renderers import get_renderer
result = get_renderer('helloworld.mak')
self.assertEqual(result.implementation().render_unicode(),
u'\nHello föö\n')
def test_template_not_found(self):
from pyramid.renderers import render
from mako.exceptions import TemplateLookupException
self.assertRaises(TemplateLookupException, render,
'helloworld_not_here.mak', {})