Esempio n. 1
0
def test_bundle():
    foo = Library('foo', '')
    a = Resource(foo, 'a.css')
    b = Resource(foo, 'b.css')

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

    resources = bundle_resources(needed.resources())
    assert len(resources) == 1
    bundle = resources[0]
    assert bundle.resources() == [a, b]
Esempio n. 2
0
def test_bundle():
    foo = Library('foo', '')
    a = Resource(foo, 'a.css')
    b = Resource(foo, 'b.css')

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

    resources = bundle_resources(needed.resources())
    assert len(resources) == 1
    bundle = resources[0]
    assert bundle.resources() == [a, b]
Esempio n. 3
0
def test_bundle_dont_bundle_at_the_start():
    foo = Library('foo', '')
    a = Resource(foo, 'a.css', dont_bundle=True)
    b = Resource(foo, 'b.css')
    c = Resource(foo, 'c.css')

    needed = NeededResources(bundle=True)
    needed.need(a)
    needed.need(b)
    needed.need(c)

    resources = bundle_resources(needed.resources())
    assert len(resources) == 2
    assert resources[0] is a
    assert resources[1].resources() == [b, c]
Esempio n. 4
0
def test_bundle_dont_bundle_at_the_start():
    foo = Library('foo', '')
    a = Resource(foo, 'a.css', dont_bundle=True)
    b = Resource(foo, 'b.css')
    c = Resource(foo, 'c.css')

    needed = NeededResources(bundle=True)
    needed.need(a)
    needed.need(b)
    needed.need(c)

    resources = bundle_resources(needed.resources())
    assert len(resources) == 2
    assert resources[0] is a
    assert resources[1].resources() == [b, c]
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
Esempio n. 6
0
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