/
util.py
89 lines (67 loc) · 2.17 KB
/
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
from packaging.version import Version
import numpy as np
import pytest
try:
import holoviews as hv
hv_version = Version(hv.__version__)
except Exception:
hv, hv_version = None, None
hv_available = pytest.mark.skipif(hv is None or hv_version < Version('1.13.0a23'),
reason="requires holoviews")
try:
import matplotlib as mpl
mpl.use('Agg')
except Exception:
mpl = None
mpl_available = pytest.mark.skipif(mpl is None, reason="requires matplotlib")
try:
import pandas as pd
except Exception:
pd = None
pd_available = pytest.mark.skipif(pd is None, reason="requires pandas")
try:
import streamz
except Exception:
streamz = None
streamz_available = pytest.mark.skipif(streamz is None, reason="requires streamz")
try:
import jupyter_bokeh
except Exception:
jupyter_bokeh = None
jb_available = pytest.mark.skipif(jupyter_bokeh is None, reason="requires jupyter_bokeh")
from panel.pane.markup import Markdown
def mpl_figure():
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(np.random.rand(10, 2))
plt.close(fig)
return fig
def check_layoutable_properties(layoutable, model):
layoutable.background = '#ffffff'
assert model.background == '#ffffff'
layoutable.css_classes = ['custom_class']
if isinstance(layoutable, Markdown):
assert model.css_classes == ['custom_class', 'markdown']
else:
assert model.css_classes == ['custom_class']
layoutable.width = 500
assert model.width == 500
layoutable.height = 450
assert model.height == 450
layoutable.min_height = 300
assert model.min_height == 300
layoutable.min_width = 250
assert model.min_width == 250
layoutable.max_height = 600
assert model.max_height == 600
layoutable.max_width = 550
assert model.max_width == 550
layoutable.margin = 10
assert model.margin == (10, 10, 10, 10)
layoutable.sizing_mode = 'stretch_width'
assert model.sizing_mode == 'stretch_width'
layoutable.width_policy = 'max'
assert model.width_policy == 'max'
layoutable.height_policy = 'min'
assert model.height_policy == 'min'