/
test_util.py
110 lines (73 loc) · 2.79 KB
/
test_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from collections import OrderedDict
import param
from bokeh.models import Div
from panel.depends import bind
from panel.io.notebook import render_mimebundle
from panel.pane import PaneBase
from panel.util import (
abbreviated_repr, extract_dependencies, get_method_owner, parse_query,
)
def test_get_method_owner_class():
assert get_method_owner(PaneBase.get_pane_type) is PaneBase
def test_get_method_owner_instance():
div = Div()
assert get_method_owner(div.update) is div
def test_get_function_dependencies():
class Test(param.Parameterized):
a = param.Parameter()
assert extract_dependencies(bind(lambda a: a, Test.param.a)) == [Test.param.a]
def test_get_parameterized_dependencies():
class Test(param.Parameterized):
a = param.Parameter()
b = param.Parameter()
@param.depends('a')
def dep_a(self):
return
@param.depends('dep_a', 'b')
def dep_ab(self):
return
test = Test()
assert extract_dependencies(test.dep_a) == [test.param.a]
assert extract_dependencies(test.dep_ab) == [test.param.a, test.param.b]
def test_get_parameterized_subobject_dependencies():
class A(param.Parameterized):
value = param.Parameter()
class B(param.Parameterized):
a = param.ClassSelector(default=A(), class_=A)
@param.depends('a.value')
def dep_a_value(self):
return
test = B()
assert extract_dependencies(test.dep_a_value) == [test.a.param.value]
def test_render_mimebundle(document, comm):
div = Div()
data, metadata = render_mimebundle(div, document, comm)
assert metadata == {'application/vnd.holoviews_exec.v0+json': {'id': div.ref['id']}}
assert 'application/vnd.holoviews_exec.v0+json' in data
assert 'text/html' in data
assert data['application/vnd.holoviews_exec.v0+json'] == ''
def test_abbreviated_repr_dict():
assert abbreviated_repr({'key': 'some really, really long string'}) == "{'key': 'some really, ...}"
def test_abbreviated_repr_list():
assert abbreviated_repr(['some really, really long string']) == "['some really, ...]"
def test_abbreviated_repr_ordereddict():
assert (abbreviated_repr(OrderedDict([('key', 'some really, really long string')]))
== "OrderedDict([('key', ...])")
def test_parse_query():
query = '?bool=true&int=2&float=3.0&json=["a"%2C+"b"]'
expected_results = {
"bool": True,
"int": 2,
"float": 3.0,
"json": ["a", "b"],
}
results = parse_query(query)
assert expected_results == results
def test_parse_query_singe_quoted():
query = "?str=abc&json=%5B%27def%27%5D"
expected_results = {
"str": 'abc',
"json": ['def'],
}
results = parse_query(query)
assert expected_results == results