当前位置: 首页>>代码示例>>Python>>正文


Python NeededResources.need方法代码示例

本文整理汇总了Python中resourceful.NeededResources.need方法的典型用法代码示例。如果您正苦于以下问题:Python NeededResources.need方法的具体用法?Python NeededResources.need怎么用?Python NeededResources.need使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在resourceful.NeededResources的用法示例。


在下文中一共展示了NeededResources.need方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_rendering_base_url

# 需要导入模块: from resourceful import NeededResources [as 别名]
# 或者: from resourceful.NeededResources import need [as 别名]
def test_rendering_base_url():
    foo = Library('foo', '')
    x1 = Resource(foo, 'a.js')
    x2 = Resource(foo, 'b.css')
    y1 = Resource(foo, 'c.js', depends=[x1, x2])

    needed = NeededResources()
    needed.need(y1)
    assert needed.render() == '''\
<link rel="stylesheet" type="text/css" href="/resourceful/foo/b.css" />
<script type="text/javascript" src="/resourceful/foo/a.js"></script>
<script type="text/javascript" src="/resourceful/foo/c.js"></script>'''

    needed = NeededResources(base_url='http://localhost/static')
    needed.need(y1)
    assert needed.render() == '''\
<link rel="stylesheet" type="text/css" href="http://localhost/static/resourceful/foo/b.css" />
<script type="text/javascript" src="http://localhost/static/resourceful/foo/a.js"></script>
<script type="text/javascript" src="http://localhost/static/resourceful/foo/c.js"></script>'''
    # The base_url has been set.
    assert needed.has_base_url()

    needed.set_base_url('foo')
    # The base_url can only be set once.
    assert needed._base_url == 'http://localhost/static'
开发者ID:aisleplanner,项目名称:resourceful,代码行数:27,代码来源:test_core.py

示例2: test_resource_url_version_hashing_bymd5

# 需要导入模块: from resourceful import NeededResources [as 别名]
# 或者: from resourceful.NeededResources import need [as 别名]
def test_resource_url_version_hashing_bymd5(tmpdir):
    foo = Library('foo', tmpdir.strpath)
    x1 = Resource(foo, 'a.js', version=True)
    x2 = Resource(foo, 'b.css', version=True)

    x1_file = tmpdir.join('a.js')
    x1_file.write('/* test1 */')
    x2_file = tmpdir.join('b.css')
    x2_file.write('/* test2 */')

    needed = NeededResources(versioning=True, versioning_use_md5=True)
    needed.need(x1)
    needed.need(x2)
    matcher = re.compile('''
<link rel="stylesheet" type="text/css" href="/resourceful/([^"]+)" />
<script type="text/javascript" src="/resourceful/([^"]+)"></script>'''[1:])
    match = matcher.match(needed.render())
    assert match is not None
    groups = match.groups()
    css_path = groups[0]
    assert css_path[0:4] == 'foo/'
    assert css_path[-5:] == 'b.css'
    css_version = css_path[4:-6]
    assert css_version == ':version:b73f1f3e3d512e180603faf9a1218803'

    js_path = groups[1]
    assert js_path[0:4] == 'foo/'
    assert js_path[-4:] == 'a.js'
    js_version = js_path[4:-5]
    assert js_version == ':version:8a58cfef526fbdf6d2b1e737bf515124'
开发者ID:aisleplanner,项目名称:resourceful,代码行数:32,代码来源:test_core.py

示例3: test_library_ordering_bug

# 需要导入模块: from resourceful import NeededResources [as 别名]
# 或者: from resourceful.NeededResources import need [as 别名]
def test_library_ordering_bug():
    jquery_lib = Library('jquery', '')
    jqueryui_lib = Library('jqueryui', '')
    obviel_lib = Library('obviel', '')
    bread_lib = Library('bread', '')
    app_lib = Library('app', '')

    jquery = Resource(jquery_lib, 'jquery.js')
    jqueryui = Resource(jqueryui_lib, 'jqueryui.js', depends=[jquery])

    obviel = Resource(obviel_lib, 'obviel.js', depends=[jquery])
    obviel_forms = Resource(obviel_lib, 'obviel_forms.js',
                            depends=[obviel])
    obviel_datepicker = Resource(obviel_lib, 'obviel_datepicker.js',
                                 depends=[obviel_forms, jqueryui])

    vtab = Resource(bread_lib, 'vtab.js', depends=[jqueryui])

    tabview = Resource(bread_lib, 'tabview.js', depends=[obviel, vtab])

    bread = Resource(bread_lib, 'bread.js', depends=[tabview, obviel_forms])

    app = Resource(app_lib, 'app.js', depends=[bread, obviel_datepicker])

    needed = NeededResources()

    needed.need(app)
    resources = needed.resources()
    for resource in resources:
        print((resource, resource.library.library_nr))
    assert resources == [jquery, jqueryui, obviel, obviel_forms,
                         obviel_datepicker, vtab, tabview, bread, app]
开发者ID:aisleplanner,项目名称:resourceful,代码行数:34,代码来源:test_core.py

示例4: test_slot_with_default_uses_default_if_nothing_given_in_need

# 需要导入模块: from resourceful import NeededResources [as 别名]
# 或者: from resourceful.NeededResources import need [as 别名]
def test_slot_with_default_uses_default_if_nothing_given_in_need():
    needed = NeededResources()
    lib = Library('lib', '')
    default_resource_for_slot = Resource(lib, 'b.js')
    slot = Slot(lib, '.js', default=default_resource_for_slot)
    a = Resource(lib, 'a.js', depends=[slot])
    needed.need(a)
    relpaths = [r.relpath for r in needed.resources()]
    assert relpaths == ['b.js', 'a.js']
开发者ID:aisleplanner,项目名称:resourceful,代码行数:11,代码来源:test_slot.py

示例5: test_empty_base_url_and_publisher_signature

# 需要导入模块: from resourceful import NeededResources [as 别名]
# 或者: from resourceful.NeededResources import need [as 别名]
def test_empty_base_url_and_publisher_signature():
    ''' When the base_url is not set and the publisher_signature is an empty string,
    render a URL without them. '''
    foo = Library('foo', '')
    x1 = Resource(foo, 'a.js')
    needed = NeededResources(publisher_signature='')
    needed.need(x1)

    assert needed.render() == '''\
开发者ID:aisleplanner,项目名称:resourceful,代码行数:11,代码来源:test_core.py

示例6: test_bundle_single_dont_bundle_entry

# 需要导入模块: from resourceful import NeededResources [as 别名]
# 或者: from resourceful.NeededResources import need [as 别名]
def test_bundle_single_dont_bundle_entry():
    foo = Library('foo', '')
    a = Resource(foo, 'a.js', dont_bundle=True)

    needed = NeededResources(bundle=True)
    needed.need(a)
    resources = needed.resources()

    assert resources == [a]
开发者ID:aisleplanner,项目名称:resourceful,代码行数:11,代码来源:test_core.py

示例7: test_rendering

# 需要导入模块: from resourceful import NeededResources [as 别名]
# 或者: from resourceful.NeededResources import need [as 别名]
def test_rendering():
    foo = Library('foo', '')
    x1 = Resource(foo, 'a.js')
    x2 = Resource(foo, 'b.css')
    y1 = Resource(foo, 'c.js', depends=[x1, x2])

    needed = NeededResources()
    needed.need(y1)

    assert needed.render() == '''\
开发者ID:aisleplanner,项目名称:resourceful,代码行数:12,代码来源:test_core.py

示例8: test_bundle_single_entry

# 需要导入模块: from resourceful import NeededResources [as 别名]
# 或者: from resourceful.NeededResources import need [as 别名]
def test_bundle_single_entry():
    # we can successfully bundle a single resource (it's not bundled though)
    foo = Library('foo', '')
    a = Resource(foo, 'a.js')

    needed = NeededResources(bundle=True)
    needed.need(a)
    resources = needed.resources()

    assert resources == [a]
开发者ID:aisleplanner,项目名称:resourceful,代码行数:12,代码来源:test_core.py

示例9: test_default_can_be_overridden

# 需要导入模块: from resourceful import NeededResources [as 别名]
# 或者: from resourceful.NeededResources import need [as 别名]
def test_default_can_be_overridden():
    needed = NeededResources()
    lib = Library('lib', '')
    default_resource_for_slot = Resource(lib, 'b.js')
    slot = Slot(lib, '.js', default=default_resource_for_slot)
    a = Resource(lib, 'a.js', depends=[slot])
    custom_resource_for_slot = Resource(lib, 'c.js')
    needed.need(a, {slot: custom_resource_for_slot})
    relpaths = [r.relpath for r in needed.resources()]
    assert relpaths == ['c.js', 'a.js']
开发者ID:aisleplanner,项目名称:resourceful,代码行数:12,代码来源:test_slot.py

示例10: test_rendering_base_url_assign

# 需要导入模块: from resourceful import NeededResources [as 别名]
# 或者: from resourceful.NeededResources import need [as 别名]
def test_rendering_base_url_assign():
    foo = Library('foo', '')
    x1 = Resource(foo, 'a.js')
    x2 = Resource(foo, 'b.css')
    y1 = Resource(foo, 'c.js', depends=[x1, x2])

    needed = NeededResources()
    needed.need(y1)
    needed.set_base_url('http://localhost/static')
    assert needed.render() == '''\
开发者ID:aisleplanner,项目名称:resourceful,代码行数:12,代码来源:test_core.py

示例11: test_top_bottom_insert

# 需要导入模块: from resourceful import NeededResources [as 别名]
# 或者: from resourceful.NeededResources import need [as 别名]
def test_top_bottom_insert():
    foo = Library('foo', '')
    x1 = Resource(foo, 'a.js')
    x2 = Resource(foo, 'b.css')
    y1 = Resource(foo, 'c.js', depends=[x1, x2])

    html = b"<html><head>start of head</head><body>rest of body</body></html>"

    needed = NeededResources(bottom=True, force_bottom=True)
    needed.need(y1)
    assert needed.render_topbottom_into_html(html) == b'''\
开发者ID:aisleplanner,项目名称:resourceful,代码行数:13,代码来源:test_core.py

示例12: test_rollup_cannot

# 需要导入模块: from resourceful import NeededResources [as 别名]
# 或者: from resourceful.NeededResources import need [as 别名]
def test_rollup_cannot():
    foo = Library('foo', '')
    b1 = Resource(foo, 'b1.js')
    b2 = Resource(foo, 'b2.js')

    giant = Resource(foo, 'giant.js', supersedes=[b1, b2])

    needed = NeededResources(rollup=True)
    needed.need(b1)
    assert needed.resources() == [b1]
    assert giant not in needed.resources()
开发者ID:aisleplanner,项目名称:resourceful,代码行数:13,代码来源:test_core.py

示例13: test_redundant_more_complicated_depends_on_all

# 需要导入模块: from resourceful import NeededResources [as 别名]
# 或者: from resourceful.NeededResources import need [as 别名]
def test_redundant_more_complicated_depends_on_all():
    foo = Library('foo', '')
    a1 = Resource(foo, 'a1.js')
    a2 = Resource(foo, 'a2.js', depends=[a1])
    a3 = Resource(foo, 'a3.js', depends=[a2])
    a4 = Resource(foo, 'a4.js', depends=[a1])
    a5 = Resource(foo, 'a5.js', depends=[a4, a3])

    needed = NeededResources()
    needed.need(a5)
    assert needed.resources() == [a1, a2, a4, a3, a5]
开发者ID:aisleplanner,项目名称:resourceful,代码行数:13,代码来源:test_core.py

示例14: test_resource_subclass_render

# 需要导入模块: from resourceful import NeededResources [as 别名]
# 或者: from resourceful.NeededResources import need [as 别名]
def test_resource_subclass_render():
    foo = Library('foo', '')

    class MyResource(Resource):
        def render(self, library_url, version_method, recompute_hashes):
            return '<myresource reference="%s/%s"/>' % (library_url, self.relpath)

    a = MyResource(foo, 'printstylesheet.css')
    needed = NeededResources()
    needed.need(a)
    assert needed.render() == """\
开发者ID:aisleplanner,项目名称:resourceful,代码行数:13,代码来源:test_core.py

示例15: test_redundant_resource_reorder

# 需要导入模块: from resourceful import NeededResources [as 别名]
# 或者: from resourceful.NeededResources import need [as 别名]
def test_redundant_resource_reorder():
    foo = Library('foo', '')
    x1 = Resource(foo, 'a.js')
    x2 = Resource(foo, 'b.css')
    y1 = Resource(foo, 'c.js', depends=[x1, x2])

    needed = NeededResources()
    needed.need(x1)
    needed.need(x2)
    needed.need(y1)
    assert needed.resources() == [x2, x1, y1]
开发者ID:aisleplanner,项目名称:resourceful,代码行数:13,代码来源:test_core.py


注:本文中的resourceful.NeededResources.need方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。