1 2
from bokeh.models import Div
2

3 2
from panel.layout import Card
4 2
from panel.models import Card as CardModel
5 2
from panel.pane import HTML
6

7

8 2
def test_card_model_cache_cleanup(document, comm):
9 2
    html = HTML()
10 2
    l = Card(header=html)
11

12 2
    model = l.get_root(document, comm)
13 2
    ref = model.ref['id']
14
    
15 2
    assert ref in l._models
16 2
    assert l._models[ref] == (model, None)
17 2
    assert ref in html._models
18

19 2
    l._cleanup(model)
20 2
    assert l._models == {}
21 2
    assert html._models == {}
22

23

24 2
def test_card_get_root(document, comm):
25 2
    div1 = Div()
26 2
    div2 = Div()
27 2
    layout = Card(div1, div2)
28

29 2
    model = layout.get_root(document, comm=comm)
30 2
    ref = model.ref['id']
31 2
    header = layout._header_layout._models[ref][0]
32

33 2
    assert isinstance(model, CardModel)
34 2
    assert model.children == [header, div1, div2]
35 2
    assert header.children[0].text == "​"
36

37

38 2
def test_card_get_root_title(document, comm):
39 2
    div1 = Div()
40 2
    div2 = Div()
41 2
    layout = Card(div1, div2, title='Test')
42

43 2
    model = layout.get_root(document, comm=comm)
44 2
    ref = model.ref['id']
45 2
    header = layout._header_layout._models[ref][0]
46

47 2
    assert isinstance(model, CardModel)
48 2
    assert model.children == [header, div1, div2]
49 2
    assert header.children[0].text == "Test"
50

51 2
    div3 = Div()
52 2
    layout.header = div3
53 2
    assert header.children[0] is div3
54

55 2
    layout.header = None
56 2
    assert header.children[0].text == "Test"
57

58

59 2
def test_card_get_root_header(document, comm):
60 2
    div1 = Div()
61 2
    div2 = Div()
62 2
    div3 = Div()
63 2
    layout = Card(div1, div2, header=div3)
64

65 2
    model = layout.get_root(document, comm=comm)
66 2
    ref = model.ref['id']
67 2
    header = layout._header_layout._models[ref][0]
68

69 2
    assert isinstance(model, CardModel)
70 2
    assert model.children == [header, div1, div2]
71 2
    assert header.children[0] is div3

Read our documentation on viewing source code .

Loading