-
Notifications
You must be signed in to change notification settings - Fork 49
/
test_gggrid_theme.py
74 lines (54 loc) · 2.19 KB
/
test_gggrid_theme.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
# Copyright (c) 2023. JetBrains s.r.o.
# Use of this source code is governed by the MIT license that can be found in the LICENSE file.
#
#
import lets_plot as gg
def test_gggrid_theme():
spec = gg.gggrid([gg.ggplot()]) + gg.theme_grey()
assert 'theme' in spec.as_dict()
assert spec.as_dict()['theme'] == {'name': 'grey'}
def test_gggrid_flavor():
spec = gg.gggrid([gg.ggplot()]) + gg.flavor_darcula()
assert 'theme' in spec.as_dict()
assert spec.as_dict()['theme'] == {'flavor': 'darcula'}
def test_gggrid_theme_flavor():
spec = gg.gggrid([gg.ggplot()]) + gg.theme_grey() + gg.flavor_darcula()
assert 'theme' in spec.as_dict()
assert spec.as_dict()['theme'] == {'name': 'grey', 'flavor': 'darcula'}
def test_gggrid_theme_flavor_as_array():
spec = gg.gggrid([gg.ggplot()]) + (gg.theme_grey() + gg.flavor_darcula())
assert 'theme' in spec.as_dict()
assert spec.as_dict()['theme'] == {'name': 'grey', 'flavor': 'darcula'}
def test_gggrid_global_theme_override():
# Set global setting!
gg.LetsPlot.set_theme(
gg.theme_grey()
)
try:
spec = gg.gggrid([gg.ggplot()]) + gg.theme_light()
finally:
# Clear global setting
gg.LetsPlot.set_theme(None)
assert 'theme' in spec.as_dict()
assert spec.as_dict()['theme'] == {'name': 'light'}
# Global theme should be stripped from the figure spec in grid
fig = spec.as_dict()['figures'][0]
assert fig['kind'] == 'plot' # Make sure it's a plot
assert 'theme' not in fig
def test_gggrid_global_theme_override_cancelled():
# Set global setting!
gg.LetsPlot.set_theme(
gg.theme_grey()
)
try:
fig = gg.ggplot() + gg.theme_bw() # this should cancel global theme for this figure
spec = gg.gggrid([fig]) + gg.theme_light()
finally:
# Clear global setting
gg.LetsPlot.set_theme(None)
assert 'theme' in spec.as_dict()
assert spec.as_dict()['theme'] == {'name': 'light'}
# The figure no longer uses global theme thus it should be present in the figure spec.
fig = spec.as_dict()['figures'][0]
assert fig['kind'] == 'plot' # Make sure it's a plot
assert fig['theme'] == {'name': 'bw'}