Beispiel #1
0
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(resources=[app])
    resources = sort_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]
Beispiel #2
0
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 = init_needed(resources=[app])
    resources = sort_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
    ]
Beispiel #3
0
def test_convenience_clear():
    foo = Library('foo', '')
    x1 = Resource(foo, 'a.js')
    x2 = Resource(foo, 'b.css')
    y1 = Resource(foo, 'c.js', depends=[x1, x2])

    z1 = Resource(foo, 'd.js')
    z2 = Resource(foo, 'e.js', depends=[z1, x1])

    needed = init_needed(resources=[y1])

    assert sort_resources(needed.resources()) == [x2, x1, y1]
    # For some reason,for example an error page needs to be rendered,
    # the currently needed resources need to be cleared.
    clear_needed()
    assert len(needed.resources()) == 0
    z2.need()
    assert sort_resources(needed.resources()) == [x1, z1, z2]
Beispiel #4
0
def test_convenience_clear():
    foo = Library('foo', '')
    x1 = Resource(foo, 'a.js')
    x2 = Resource(foo, 'b.css')
    y1 = Resource(foo, 'c.js', depends=[x1, x2])

    z1 = Resource(foo, 'd.js')
    z2 = Resource(foo, 'e.js', depends=[z1, x1])

    needed = init_needed(resources=[y1])

    assert sort_resources(needed.resources()) == [x2, x1, y1]
    # For some reason,for example an error page needs to be rendered,
    # the currently needed resources need to be cleared.
    clear_needed()
    assert len(needed.resources()) == 0
    z2.need()
    assert sort_resources(needed.resources()) == [x1, z1, z2]
Beispiel #5
0
def test_sort_registered_inclusion_renderers_in_order():
    foo = Library('foo', '')

    def render_unknown(url):
        return '<unknown href="%s"/>' % url

    register_inclusion_renderer('.later', render_unknown, 50)
    a = Resource(foo, 'nothing.later')
    b = Resource(foo, 'something.js')
    c = Resource(foo, 'something.css')
    d = Resource(foo, 'something.ico')

    assert sort_resources([a, b, c, d]) == [c, b, d, a]

    register_inclusion_renderer('.sooner', render_unknown, 5)
    e = Resource(foo, 'nothing.sooner')
    assert sort_resources([a, b, c, d, e]) == [e, c, b, d, a]

    register_inclusion_renderer('.between', render_unknown, 25)
    f = Resource(foo, 'nothing.between')
    assert sort_resources([a, b, c, d, e, f]) == [e, c, b, f, d, a]
Beispiel #6
0
def test_sort_library_by_name():
    b_lib = Library('b_lib', '')
    a_lib = Library('a_lib', '')

    a_a = Resource(a_lib, 'a.js')
    a_b = Resource(b_lib, 'a.js')

    needed = NeededResources()
    needed.need(a_b)
    needed.need(a_a)

    assert sort_resources(needed.resources()) == [a_a, a_b]
Beispiel #7
0
def test_sort_library_by_name():
    b_lib = Library('b_lib', '')
    a_lib = Library('a_lib', '')

    a_a = Resource(a_lib, 'a.js')
    a_b = Resource(b_lib, 'a.js')

    needed = init_needed()
    needed.need(a_b)
    needed.need(a_a)

    assert sort_resources(needed.resources()) == [a_a, a_b]
Beispiel #8
0
def test_sort_registered_inclusion_renderers_in_order():
    from fanstatic import get_library_registry
    foo = Library('foo', '')

    def render_unknown(url):
        return '<unknown href="%s"/>' % url

    register_inclusion_renderer('.later', render_unknown, 50)
    register_inclusion_renderer('.sooner', render_unknown, 5)
    register_inclusion_renderer('.between', render_unknown, 25)
    a = Resource(foo, 'nothing.later')
    b = Resource(foo, 'something.js')
    c = Resource(foo, 'something.css')
    d = Resource(foo, 'something.ico')
    e = Resource(foo, 'nothing.sooner')
    f = Resource(foo, 'nothing.between')

    get_library_registry().prepare()
    assert sort_resources([a, b, c, d]) == [c, b, d, a]
    assert sort_resources([a, b, c, d, e]) == [e, c, b, d, a]
    assert sort_resources([a, b, c, d, e, f]) == [e, c, b, f, d, a]
Beispiel #9
0
def test_sort_resources_library_sorting_by_name_deeper():
    X = Library('X', '')
    Y = Library('Y', '')
    Z = Library('Z', '')

    # only X and Z will be at the same level now
    a = Resource(X, 'a.js')
    c = Resource(Z, 'c.js')
    b = Resource(Y, 'b.js', depends=[a, c])

    needed = init_needed()
    needed.need(b)
    assert sort_resources(needed.resources()) == [a, c, b]
Beispiel #10
0
def test_sort_resources_library_sorting_by_name_deeper():
    X = Library('X', '')
    Y = Library('Y', '')
    Z = Library('Z', '')

    # only X and Z will be at the same level now
    a = Resource(X, 'a.js')
    c = Resource(Z, 'c.js')
    b = Resource(Y, 'b.js', depends=[a, c])

    needed = NeededResources()
    needed.need(b)
    assert sort_resources(needed.resources()) == [a, c, b]
Beispiel #11
0
def test_sort_group_per_renderer():
    foo = Library('foo', '')
    a_js = Resource(foo, 'a.js')
    b_css = Resource(foo, 'b.css')
    c_js = Resource(foo, 'c.js')
    a1_js = Resource(foo, 'a1.js', depends=[b_css])

    needed = NeededResources()
    needed.need(a_js)
    needed.need(b_css)
    needed.need(c_js)
    needed.need(a1_js)

    assert sort_resources(needed.resources()) == [b_css, a_js, c_js, a1_js]
Beispiel #12
0
def test_sort_group_per_renderer():
    foo = Library('foo', '')
    a_js = Resource(foo, 'a.js')
    b_css = Resource(foo, 'b.css')
    c_js = Resource(foo, 'c.js')
    a1_js = Resource(foo, 'a1.js', depends=[b_css])

    needed = init_needed()
    needed.need(a_js)
    needed.need(b_css)
    needed.need(c_js)
    needed.need(a1_js)

    assert sort_resources(needed.resources()) == [b_css, a_js, c_js, a1_js]
Beispiel #13
0
def test_sort_resources_libraries_together():
    K = Library('K', '')
    L = Library('L', '')
    M = Library('M', '')
    N = Library('N', '')

    k1 = Resource(K, 'k1.js')
    l1 = Resource(L, 'l1.js')
    m1 = Resource(M, 'm1.js', depends=[k1])
    m2 = Resource(M, 'm2.js', depends=[l1])
    n1 = Resource(N, 'n1.js', depends=[m1])

    needed = init_needed()
    needed.need(m1)
    needed.need(m2)
    # sort_resources makes an efficient ordering, grouping m1 and m2 together
    # after their dependencies (they are in the same library)
    assert sort_resources(needed.resources()) == [k1, l1, m1, m2]

    needed = init_needed()
    needed.need(n1)
    needed.need(m2)
    # the order is unaffected by the ordering of inclusions
    assert sort_resources(needed.resources()) == [k1, l1, m1, m2, n1]
Beispiel #14
0
def test_sort_resources_libraries_together():
    K = Library('K', '')
    L = Library('L', '')
    M = Library('M', '')
    N = Library('N', '')

    k1 = Resource(K, 'k1.js')
    l1 = Resource(L, 'l1.js')
    m1 = Resource(M, 'm1.js', depends=[k1])
    m2 = Resource(M, 'm2.js', depends=[l1])
    n1 = Resource(N, 'n1.js', depends=[m1])

    needed = NeededResources()
    needed.need(m1)
    needed.need(m2)
    # sort_resources makes an efficient ordering, grouping m1 and m2 together
    # after their dependencies (they are in the same library)
    assert sort_resources(needed.resources()) == [k1, l1, m1, m2]

    needed = NeededResources()
    needed.need(n1)
    needed.need(m2)
    # the order is unaffected by the ordering of inclusions
    assert sort_resources(needed.resources()) == [k1, l1, m1, m2, n1]
Beispiel #15
0
def test_sort_resources_library_sorting_by_name():
    # these libraries are all at the same level so should be sorted by name
    X = Library('X', '')
    Y = Library('Y', '')
    Z = Library('Z', '')

    a = Resource(X, 'a.js')
    b = Resource(Y, 'b.js')
    c = Resource(Z, 'c.js')

    needed = init_needed()
    needed.need(a)
    needed.need(b)
    needed.need(c)

    assert sort_resources(needed.resources()) == [a, b, c]
Beispiel #16
0
def test_inter_library_dependencies_ordering():
    lib1 = Library('lib1', '')
    lib2 = Library('lib2', '')
    lib3 = Library('lib3', '')
    lib4 = Library('lib4', '')

    js1 = Resource(lib1, 'js1.js')
    js2 = Resource(lib2, 'js2.js', depends=[js1])
    js3 = Resource(lib3, 'js3.js', depends=[js2])

    style1 = Resource(lib3, 'style1.css')
    style2 = Resource(lib4, 'style2.css', depends=[style1])

    needed = init_needed(resources=[js3, style2])
    assert sort_resources(needed.resources()) == \
        [style1, style2, js1, js2, js3]
Beispiel #17
0
def test_sort_resources_library_sorting_by_name():
    # these libraries are all at the same level so should be sorted by name
    X = Library('X', '')
    Y = Library('Y', '')
    Z = Library('Z', '')

    a = Resource(X, 'a.js')
    b = Resource(Y, 'b.js')
    c = Resource(Z, 'c.js')

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

    assert sort_resources(needed.resources()) == [a, b, c]
Beispiel #18
0
def test_inter_library_dependencies_ordering():
    lib1 = Library('lib1', '')
    lib2 = Library('lib2', '')
    lib3 = Library('lib3', '')
    lib4 = Library('lib4', '')

    js1 = Resource(lib1, 'js1.js')
    js2 = Resource(lib2, 'js2.js', depends=[js1])
    js3 = Resource(lib3, 'js3.js', depends=[js2])

    style1 = Resource(lib3, 'style1.css')
    style2 = Resource(lib4, 'style2.css', depends=[style1])

    needed = NeededResources(resources=[js3, style2])
    assert sort_resources(needed.resources()) == \
        [style1, style2, js1, js2, js3]
Beispiel #19
0
def test_sort_group_per_library():
    foo = Library('foo', '')
    bar = Library('bar', '')

    e = Resource(foo, 'e.js')
    d = Resource(foo, 'd.js', depends=[e])
    c = Resource(bar, 'c.js', depends=[e])
    b = Resource(bar, 'b.js')
    a = Resource(bar, 'a.js', depends=[c])

    needed = NeededResources()
    needed.need(a)
    needed.need(b)
    needed.need(c)
    needed.need(d)
    needed.need(e)

    assert sort_resources(needed.resources()) == [e, d, b, c, a]
Beispiel #20
0
def test_sort_group_per_library():
    foo = Library('foo', '')
    bar = Library('bar', '')

    e = Resource(foo, 'e.js')
    d = Resource(foo, 'd.js', depends=[e])
    c = Resource(bar, 'c.js', depends=[e])
    b = Resource(bar, 'b.js')
    a = Resource(bar, 'a.js', depends=[c])

    needed = init_needed()
    needed.need(a)
    needed.need(b)
    needed.need(c)
    needed.need(d)
    needed.need(e)

    assert sort_resources(needed.resources()) == [e, d, b, c, a]
Beispiel #21
0
def test_sort_resources_library_sorting():
    # a complicated example that makes sure libraries are sorted
    # correctly to obey ordering constraints but still groups them
    X = Library('X', '')
    Y = Library('Y', '')
    Z = Library('Z', '')

    a = Resource(X, 'a.js')
    b = Resource(Z, 'b.js', depends=[a])

    c = Resource(Y, 'c.js')
    c1 = Resource(Y, 'c1.js', depends=[c])
    c2 = Resource(Y, 'c2.js', depends=[c1])
    d = Resource(Z, 'd.js', depends=[c])
    e = Resource(Z, 'e.js')

    needed = init_needed()
    needed.need(b)
    needed.need(c2)
    needed.need(d)
    needed.need(e)

    assert sort_resources(needed.resources()) == [a, c, c1, c2, e, b, d]
Beispiel #22
0
def test_sort_resources_library_sorting():
    # a complicated example that makes sure libraries are sorted
    # correctly to obey ordering constraints but still groups them
    X = Library('X', '')
    Y = Library('Y', '')
    Z = Library('Z', '')

    a = Resource(X, 'a.js')
    b = Resource(Z, 'b.js', depends=[a])

    c = Resource(Y, 'c.js')
    c1 = Resource(Y, 'c1.js', depends=[c])
    c2 = Resource(Y, 'c2.js', depends=[c1])
    d = Resource(Z, 'd.js', depends=[c])
    e = Resource(Z, 'e.js')

    needed = NeededResources()
    needed.need(b)
    needed.need(c2)
    needed.need(d)
    needed.need(e)

    assert sort_resources(needed.resources()) == [a, c, c1, c2, e, b, d]