コード例 #1
0
def test_slot_with_default_uses_default_if_nothing_given_in_need():
    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 = init_needed(resources=[a])
    relpaths = [r.relpath for r in sort_resources(needed.resources())]
    assert relpaths == ['b.js', 'a.js']
コード例 #2
0
def test_slot_with_default_uses_default_if_nothing_given_in_need():
    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 = NeededResources(resources=[a])
    relpaths = [r.relpath for r in sort_resources(needed.resources())]
    assert relpaths == ["b.js", "a.js"]
コード例 #3
0
def test_slot_depends_subset():
    lib = Library("lib", "")

    c = Resource(lib, "c.js")
    slot = Slot(lib, ".js", depends=[c])
    a = Resource(lib, "a.js", depends=[slot])
    b = Resource(lib, "b.js", depends=[])

    needed = NeededResources()
    needed.need(a, {slot: b})
    assert [r.relpath for r in sort_resources(needed.resources())] == ["c.js", "b.js", "a.js"]
コード例 #4
0
def test_default_can_be_overridden():
    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 = init_needed()
    needed.need(a, {slot: custom_resource_for_slot})

    relpaths = [r.relpath for r in sort_resources(needed.resources())]
    assert relpaths == ['c.js', 'a.js']
コード例 #5
0
def test_slot_depends_subset():
    lib = Library('lib', '')

    c = Resource(lib, 'c.js')
    slot = Slot(lib, '.js', depends=[c])
    a = Resource(lib, 'a.js', depends=[slot])
    b = Resource(lib, 'b.js', depends=[])

    needed = init_needed()
    needed.need(a, {slot: b})
    assert [r.relpath for r in sort_resources(needed.resources())] == \
        ['c.js', 'b.js', 'a.js']
コード例 #6
0
def test_default_can_be_overridden():
    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 = NeededResources()
    needed.need(a, {slot: custom_resource_for_slot})

    relpaths = [r.relpath for r in sort_resources(needed.resources())]
    assert relpaths == ["c.js", "a.js"]
コード例 #7
0
def test_render_filled_slots():
    lib = Library('lib', '')

    slot = Slot(lib, '.js')
    a = Resource(lib, 'a.js', depends=[slot])

    b = Resource(lib, 'b.js')

    needed = init_needed()
    needed.need(a, {slot: b})

    assert [r.relpath for r in sort_resources(needed.resources())] == \
        ['b.js', 'a.js']
コード例 #8
0
def test_render_filled_slots():
    needed = NeededResources()

    lib = Library("lib", "")

    slot = Slot(lib, ".js")
    a = Resource(lib, "a.js", depends=[slot])

    b = Resource(lib, "b.js")

    needed.need(a, {slot: b})

    assert [r.relpath for r in sort_resources(needed.resources())] == ["b.js", "a.js"]
コード例 #9
0
def test_fill_slot():
    lib = Library('lib', '')

    slot = Slot(lib, '.js')
    a = Resource(lib, 'a.js', depends=[slot])

    b = Resource(lib, 'b.js')

    needed = init_needed()
    needed.need(a, {slot: b})

    resources = sort_resources(needed.resources())
    assert len(resources) == 2
    # verify filled slot is correctly
    assert resources[0].library is b.library
    assert resources[0].relpath is b.relpath
コード例 #10
0
def test_fill_slot():
    needed = NeededResources()

    lib = Library("lib", "")

    slot = Slot(lib, ".js")
    a = Resource(lib, "a.js", depends=[slot])

    b = Resource(lib, "b.js")

    needed.need(a, {slot: b})

    resources = sort_resources(needed.resources())
    assert len(resources) == 2
    # verify filled slot is correctly
    assert resources[0].library is b.library
    assert resources[0].relpath is b.relpath
コード例 #11
0
def test_bundle_resources():
    foo = Library('foo', '')
    x1 = Resource(foo, 'a.css')
    x2 = Resource(foo, 'b.css')
    x3 = Resource(foo, 'c.css', dont_bundle=True)

    bar = Library('bar', '')
    y1 = Resource(bar, 'y1.css')
    y2 = Resource(bar, 'y2.css')
    y3 = Resource(bar, 'subdir/y3.css')
    y4 = Resource(bar, 'subdir/y4.css')
    init_needed()

    bundle = bundle_resources([x1, x2])
    assert len(bundle) == 1
    assert isinstance(bundle[0], Bundle)

    # x3 is not bundle safe.
    bundle = bundle_resources([x1, x3])
    assert len(bundle) == 2
    # We don't create bundles of one element.
    assert bundle[0] == x1
    assert bundle[1] == x3

    # x2 and x1 are not bundled because x3 is in the way.
    # (sort_resources in NeededResources fixes the sorting)
    bundle = bundle_resources([x1, x3, x2])
    assert bundle == [x1, x3, x2]

    # The resources are sorted by renderer order, library dependencies
    # and resource dependencies.
    bundle = bundle_resources(sort_resources([x1, x3, x2]))
    assert len(bundle) == 2
    assert isinstance(bundle[0], Bundle)
    assert bundle[1] == x3

    bundle = bundle_resources([x1, x2, y1, y2])
    assert len(bundle) == 2

    bundle = bundle_resources([y1, y2, y3, y4])
    assert len(bundle) == 2
コード例 #12
0
ファイル: test_bundle.py プロジェクト: fsys/fanstatic
def test_bundle_resources():
    foo = Library('foo', '')
    x1 = Resource(foo, 'a.css')
    x2 = Resource(foo, 'b.css')

    bundle = bundle_resources([x1, x2])
    assert len(bundle) == 1
    assert isinstance(bundle[0], Bundle)

    x3 = Resource(foo, 'c.css', dont_bundle=True)
    # x3 is not bundle safe.
    bundle = bundle_resources([x1, x3])
    assert len(bundle) == 2
    # We don't create bundles of one element.
    assert bundle[0] == x1
    assert bundle[1] == x3

    # x2 and x1 are not bundled because x3 is in the way.
    # (sort_resources in NeededResources fixes the sorting)
    bundle = bundle_resources([x1, x3, x2])
    assert bundle == [x1, x3, x2]

    # The resources are sorted by renderer order, library dependencies
    # and resource dependencies.
    bundle = bundle_resources(sort_resources([x1, x3, x2]))
    assert len(bundle) == 2
    assert isinstance(bundle[0], Bundle)
    assert bundle[1] == x3

    bar = Library('bar', '')
    y1 = Resource(bar, 'y1.css')
    y2 = Resource(bar, 'y2.css')

    bundle = bundle_resources([x1, x2, y1, y2])
    assert len(bundle) == 2

    y3 = Resource(bar, 'subdir/y3.css')
    y4 = Resource(bar, 'subdir/y4.css')
    bundle = bundle_resources([y1, y2, y3, y4])
    assert len(bundle) == 2