本文整理汇总了Python中webassets.Environment.add方法的典型用法代码示例。如果您正苦于以下问题:Python Environment.add方法的具体用法?Python Environment.add怎么用?Python Environment.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webassets.Environment
的用法示例。
在下文中一共展示了Environment.add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCLI
# 需要导入模块: from webassets import Environment [as 别名]
# 或者: from webassets.Environment import add [as 别名]
class TestCLI(object):
def setup(self):
self.assets_env = Environment("", "")
self.cmd_env = CommandLineEnvironment(self.assets_env, logging)
def test_rebuild_container_bundles(self):
"""Test the rebuild command can deal with container bundles.
"""
a = MockBundle(output="a")
b1 = MockBundle(output="b1")
b2 = MockBundle(output="b2")
b = MockBundle(b1, b2)
self.assets_env.add(a, b)
self.cmd_env.rebuild()
assert a.build_called
assert not b.build_called
assert b1.build_called
assert b2.build_called
示例2: TestEnvApi
# 需要导入模块: from webassets import Environment [as 别名]
# 或者: from webassets.Environment import add [as 别名]
class TestEnvApi(object):
"""General Environment functionality."""
def setup(self):
self.m = Environment(None, None)
def test_register_single_bundle(self):
"""Test registering a single ``Bundle`` object.
"""
b = Bundle()
self.m.register('foo', b)
assert self.m['foo'] == b
def test_register_dict(self):
"""Register a bunch of bundles at once."""
a = Bundle()
b = Bundle()
self.m.register({'foo': a, 'bar': b})
assert self.m['foo'] == a
assert self.m['bar'] == b
def test_register_new_bundle(self):
"""Test self.m.registering a new bundle on the fly.
"""
b = Bundle()
self.m.register('foo', b, 's2', 's3')
assert b in self.m['foo'].contents
# Special case of using only a single, non-bundle source argument.
self.m.register('footon', 's1')
assert 's1' in self.m['footon'].contents
# Special case of specifying only a single bundle as a source, but
# additional options - this also creates a wrapping bundle.
self.m.register('foofighters', b, output="bar")
assert b in self.m['foofighters'].contents
def test_register_invalid_call(self):
"""Test calling self.m.register with an invalid syntax.
"""
assert_raises(TypeError, self.m.register)
assert_raises(TypeError, self.m.register, 'one-argument-only')
def test_register_duplicate(self):
"""Test name clashes.
"""
b1 = Bundle()
b2 = Bundle()
self.m.register('foo', b1)
# Multiple calls with the same name are ignored if the given bundle
# is the same as originally passed.
self.m.register('foo', b1)
assert len(self.m) == 1
# Otherwise, an error is raised.
assert_raises(RegisterError, self.m.register, 'foo', b2)
assert_raises(RegisterError, self.m.register, 'foo', 's1', 's2', 's3')
def test_register_anon_bundle(self):
"""Self registering an anonymous bundle.
"""
b = Bundle()
self.m.add(b)
assert len(self.m) == 1
assert list(self.m) == [b]
def test_contains(self):
"""Test __contains__.
"""
b = Bundle()
self.m.register('foo', b)
assert 'foo' in self.m
assert not 'bar' in self.m
def test_url_and_directory(self):
"""The url and directory options are a bit special, because they
are so essential.
"""
# An environment can be constructed without given url or directory.
env = Environment()
# But then accessing them will fail, and with it most operations.
assert_raises(EnvironmentError, getattr, env, 'url')
assert_raises(EnvironmentError, getattr, env, 'directory')
# Test constructing the environment with values for url and directory
env = Environment('foo', 'bar')
assert env.url == 'bar'
assert env.config['directory'] == 'foo'
assert env.directory == os.path.join(os.getcwd(), 'foo')
def test_append_load_path(self):
env = Environment()
assert env.load_path == []
env.append_path('foo', '/foo')
#.........这里部分代码省略.........
示例3: TestEnvApi
# 需要导入模块: from webassets import Environment [as 别名]
# 或者: from webassets.Environment import add [as 别名]
class TestEnvApi(object):
"""General Environment functionality."""
def setup(self):
self.m = Environment(None, None)
def test_single_bundle(self):
"""Test self.m.registering a single ``Bundle`` object.
"""
b = Bundle()
self.m.register('foo', b)
assert self.m['foo'] == b
def test_new_bundle(self):
"""Test self.m.registering a new bundle on the fly.
"""
b = Bundle()
self.m.register('foo', b, 's2', 's3')
assert b in self.m['foo'].contents
# Special case of using only a single, non-bundle source argument.
self.m.register('footon', 's1')
assert 's1' in self.m['footon'].contents
# Special case of specifying only a single bundle as a source, but
# additional options - this also creates a wrapping bundle.
self.m.register('foofighters', b, output="bar")
assert b in self.m['foofighters'].contents
def test_invalid_call(self):
"""Test calling self.m.register with an invalid syntax.
"""
assert_raises(TypeError, self.m.register)
assert_raises(TypeError, self.m.register, 'one-argument-only')
def test_duplicate(self):
"""Test name clashes.
"""
b1 = Bundle()
b2 = Bundle()
self.m.register('foo', b1)
# Multiple calls with the same name are ignored if the given bundle
# is the same as originally passed.
self.m.register('foo', b1)
assert len(self.m) == 1
# Otherwise, an error is raised.
assert_raises(RegisterError, self.m.register, 'foo', b2)
assert_raises(RegisterError, self.m.register, 'foo', 's1', 's2', 's3')
def test_anon_bundle(self):
"""Self registering an anonymous bundle.
"""
b = Bundle()
self.m.add(b)
assert len(self.m) == 1
assert list(self.m) == [b]
def test_contains(self):
"""Test __contains__.
"""
b = Bundle()
self.m.register('foo', b)
assert 'foo' in self.m
assert not 'bar' in self.m
示例4: Environment
# 需要导入模块: from webassets import Environment [as 别名]
# 或者: from webassets.Environment import add [as 别名]
#!/usr/bin/env python
from os import path
from webassets import Bundle, Environment
env = Environment(path.join(path.dirname(__file__), 'static'), '/stylesheets')
# App Engine doesn't support automatic rebuilding.
env.auto_build = False
# This file needs to be shipped with your code.
env.manifest = 'file'
bundle = Bundle('in.css', filters="cssmin", output="out.css")
env.add(bundle)
if __name__== "__main__":
# If this file is called directly, do a manual build.
bundle.build()
示例5: TestEnvApi
# 需要导入模块: from webassets import Environment [as 别名]
# 或者: from webassets.Environment import add [as 别名]
class TestEnvApi(object):
"""General Environment functionality."""
def setup(self):
self.m = Environment(None, None)
def test_register_single_bundle(self):
"""Test registering a single ``Bundle`` object.
"""
b = Bundle()
self.m.register("foo", b)
assert self.m["foo"] == b
def test_register_dict(self):
"""Register a bunch of bundles at once."""
a = Bundle()
b = Bundle()
self.m.register({"foo": a, "bar": b})
assert self.m["foo"] == a
assert self.m["bar"] == b
def test_register_new_bundle(self):
"""Test self.m.registering a new bundle on the fly.
"""
b = Bundle()
self.m.register("foo", b, "s2", "s3")
assert b in self.m["foo"].contents
# Special case of using only a single, non-bundle source argument.
self.m.register("footon", "s1")
assert "s1" in self.m["footon"].contents
# Special case of specifying only a single bundle as a source, but
# additional options - this also creates a wrapping bundle.
self.m.register("foofighters", b, output="bar")
assert b in self.m["foofighters"].contents
def test_register_invalid_call(self):
"""Test calling self.m.register with an invalid syntax.
"""
assert_raises(TypeError, self.m.register)
assert_raises(TypeError, self.m.register, "one-argument-only")
def test_register_duplicate(self):
"""Test name clashes.
"""
b1 = Bundle()
b2 = Bundle()
self.m.register("foo", b1)
# Multiple calls with the same name are ignored if the given bundle
# is the same as originally passed.
self.m.register("foo", b1)
assert len(self.m) == 1
# Otherwise, an error is raised.
assert_raises(RegisterError, self.m.register, "foo", b2)
assert_raises(RegisterError, self.m.register, "foo", "s1", "s2", "s3")
def test_register_anon_bundle(self):
"""Self registering an anonymous bundle.
"""
b = Bundle()
self.m.add(b)
assert len(self.m) == 1
assert list(self.m) == [b]
def test_contains(self):
"""Test __contains__.
"""
b = Bundle()
self.m.register("foo", b)
assert "foo" in self.m
assert not "bar" in self.m
def test_bool_evaluation(self):
"""Test that environment evaluates to True in a boolean context.
"""
env = Environment()
assert env
def test_url_and_directory(self):
"""The url and directory options are a bit special, because they
are so essential.
"""
# An environment can be constructed without given url or directory.
env = Environment()
# But then accessing them will fail, and with it most operations.
assert_raises(EnvironmentError, getattr, env, "url")
assert_raises(EnvironmentError, getattr, env, "directory")
# Test constructing the environment with values for url and directory
env = Environment("foo", "bar")
assert env.url == "bar"
assert env.config["directory"] == "foo"
assert env.directory == os.path.join(os.getcwd(), "foo")
#.........这里部分代码省略.........