-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtest_baseplot.py
152 lines (125 loc) · 4.39 KB
/
test_baseplot.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import pytest
from pynimate.baseplot import Baseplot
def test_baseplot_generate_column_colors(sample_data1_basedfr):
base_plot = Baseplot(sample_data1_basedfr)
column_colors = {
"Afghanistan": (0.267968, 0.223549, 0.512008),
"Angola": (0.190631, 0.407061, 0.556089),
"Albania": (0.127568, 0.566949, 0.550556),
"USA": (0.20803, 0.718701, 0.472873),
"Argentina": (0.565498, 0.84243, 0.262877),
}
assert base_plot.generate_column_colors() == column_colors
def test_baseplot_set_column_colors_str(sample_data1_basedfr):
base_plot = Baseplot(sample_data1_basedfr)
base_plot.set_column_colors("#FF2C55")
column_colors = {
"Afghanistan": "#FF2C55",
"Angola": "#FF2C55",
"Albania": "#FF2C55",
"USA": "#FF2C55",
"Argentina": "#FF2C55",
}
assert base_plot.column_colors == column_colors
def test_baseplot_set_column_colors_list(sample_data1_basedfr):
base_plot = Baseplot(sample_data1_basedfr)
base_plot.set_column_colors(
[
"#C41E3D",
"#7D1128",
"#FF2C55",
"#3C0919",
"#E2294F",
]
)
column_colors = {
"Afghanistan": "#C41E3D",
"Angola": "#7D1128",
"Albania": "#FF2C55",
"USA": "#3C0919",
"Argentina": "#E2294F",
}
assert base_plot.column_colors == column_colors
def test_baseplot_set_column_colors_dict(sample_data1_basedfr):
base_plot = Baseplot(sample_data1_basedfr)
base_plot.set_column_colors(
{
"Afghanistan": "#C41E3D",
"Angola": "#7D1128",
"Albania": "#FF2C55",
"USA": "#3C0919",
"Argentina": "#E2294F",
}
)
column_colors = {
"Afghanistan": "#C41E3D",
"Angola": "#7D1128",
"Albania": "#FF2C55",
"USA": "#3C0919",
"Argentina": "#E2294F",
}
assert base_plot.column_colors == column_colors
def test_baseplot_set_column_color_err_length(sample_data1_basedfr):
with pytest.raises(AssertionError):
base_plot = Baseplot(sample_data1_basedfr)
column_colors = [
"#2a9d8f",
"#e9c46a",
"#e76f51",
"#a7c957",
]
base_plot.set_column_colors(column_colors)
def test_baseplot_set_column_color_err_col_mismatch(sample_data1_basedfr):
with pytest.raises(ValueError):
bar = Baseplot(sample_data1_basedfr)
bar_colors = {
"India": "#2a9d8f",
"Angola": "#e9c46a",
"Albania": "#e76f51",
"USA": "#a7c957",
"Argentina": "#e5989b",
}
bar.set_column_colors(bar_colors)
def test_baseplot_set_column_color_err_type(sample_data1_basedfr):
with pytest.raises(TypeError):
bar = Baseplot(sample_data1_basedfr)
bar_colors = set(
[
"#2a9d8f",
"#e9c46a",
"#e76f51",
"#a7c957",
"#e5989b",
]
)
bar.set_column_colors(bar_colors)
def test_baseplot_xylim(sample_data1_basedfr):
base_plot = Baseplot(sample_data1_basedfr)
xmin, xmax = base_plot.xlim
ymin, ymax = base_plot.ylim
assert xmin is None and ymin is None
assert xmax.strftime("%Y-%m-%d") == "1962-01-01" and ymax == 5
def test_baseplot_text_structure(sample_data1_basedfr):
base_plot = Baseplot(sample_data1_basedfr)
base_plot.set_title("Title")
base_plot.set_xlabel("Xlabel")
base_plot.set_time()
for text in base_plot.text_collection.values():
assert isinstance(text, tuple)
assert text[0] is None or callable(text[0])
assert isinstance(text[1], dict)
def test_baseplot_set_text_error_empty_text(sample_data1_basedfr):
with pytest.raises(AssertionError):
bar = Baseplot(sample_data1_basedfr)
bar.set_text("text1")
def test_baseplot_set_text_priority(sample_data1_basedfr):
bar = Baseplot(sample_data1_basedfr)
bar.set_text("text1", text="Test", callback=lambda *args: "Test")
assert "s" not in bar.text_collection["text1"][1]
def test_baseplot_remove_text(sample_data1_basedfr):
bar = Baseplot(sample_data1_basedfr)
bar.set_text("text1", text="Test1")
bar.set_text("text2", text="Test2")
bar.set_text("text3", text="Test3")
bar.remove_text(["text1", "text2"])
assert list(bar.text_collection.keys()) == ["text3"]