本文整理汇总了Python中webassets.Environment.config[NAME]方法的典型用法代码示例。如果您正苦于以下问题:Python Environment.config[NAME]方法的具体用法?Python Environment.config[NAME]怎么用?Python Environment.config[NAME]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webassets.Environment
的用法示例。
在下文中一共展示了Environment.config[NAME]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_config
# 需要导入模块: from webassets import Environment [as 别名]
# 或者: from webassets.Environment import config[NAME] [as 别名]
def test_get_config(self):
"""Test the ``get_config`` helper.
"""
m = Environment(None, None)
f = Filter()
f.set_environment(m)
get_config = f.get_config
# For the purposes of the following tests, we use two test
# names which we expect to be undefined in os.env.
NAME = "FOO%s" % id(object())
NAME2 = "FOO%s" % id(NAME)
assert NAME != NAME2
assert not NAME in os.environ and not NAME2 in os.environ
try:
# Test raising of error, and test not raising it.
assert_raises(EnvironmentError, get_config, NAME)
assert get_config(NAME, require=False) == None
# Start with only the environment variable set.
os.environ[NAME] = "bar"
assert get_config(NAME) == "bar"
assert get_config(env=NAME, setting=False) == "bar"
assert_raises(EnvironmentError, get_config, setting=NAME, env=False)
# Set the value in the environment as well.
m.config[NAME] = "foo"
# Ensure that settings take precedence.
assert_equals(get_config(NAME), "foo")
# Two different names can be supplied.
assert get_config(setting=NAME2, env=NAME) == "bar"
# Unset the env variable, now with only the setting.
del os.environ[NAME]
assert get_config(NAME) == "foo"
assert get_config(setting=NAME, env=False) == "foo"
assert_raises(EnvironmentError, get_config, env=NAME)
finally:
if NAME in os.environ:
del os.environ[NAME]
示例2: test_get_config
# 需要导入模块: from webassets import Environment [as 别名]
# 或者: from webassets.Environment import config[NAME] [as 别名]
def test_get_config(self):
"""Test the ``get_config`` helper.
"""
m = Environment(None, None)
f = Filter()
f.set_context(ContextWrapper(m))
get_config = f.get_config
# For the purposes of the following tests, we use two test
# names which we expect to be undefined in os.env.
NAME = 'FOO%s' % id(object())
NAME2 = 'FOO%s' % id(NAME)
assert NAME != NAME2
assert not NAME in os.environ and not NAME2 in os.environ
with os_environ_sandbox():
# Test raising of error, and test not raising it.
assert_raises(EnvironmentError, get_config, NAME)
assert get_config(NAME, require=False) is None
# Start with only the environment variable set.
os.environ[NAME] = 'bar'
assert get_config(NAME) == 'bar'
assert get_config(env=NAME, setting=False) == 'bar'
assert_raises(EnvironmentError, get_config, setting=NAME, env=False)
# Set the value in the environment as well.
m.config[NAME] = 'foo'
# Ensure that settings take precedence.
assert_equal(get_config(NAME), 'foo')
# Two different names can be supplied.
assert get_config(setting=NAME2, env=NAME) == 'bar'
# Unset the env variable, now with only the setting.
del os.environ[NAME]
assert get_config(NAME) == 'foo'
assert get_config(setting=NAME, env=False) == 'foo'
assert_raises(EnvironmentError, get_config, env=NAME)