-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtest_bar.py
86 lines (70 loc) · 2.46 KB
/
test_bar.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
# Legacy tests for barplot, will be removed in 2.0.0
import pytest
from pynimate.bar import Barplot
def test_barplot_set_bar_color_list(sample_data1):
bar = Barplot(sample_data1, "%Y-%m-%d", "3MS")
bar_colors_list = [
"#2a9d8f",
"#e9c46a",
"#e76f51",
"#a7c957",
"#e5989b",
]
bar_colors = {
"Afghanistan": "#2a9d8f",
"Angola": "#e9c46a",
"Albania": "#e76f51",
"USA": "#a7c957",
"Argentina": "#e5989b",
}
bar.set_bar_color(bar_colors_list)
assert bar.datafier.bar_colors == bar_colors
def test_barplot_set_bar_color_dict(sample_data1):
bar = Barplot(sample_data1, "%Y-%m-%d", "3MS")
bar_colors = {
"Afghanistan": "#2a9d8f",
"Angola": "#e9c46a",
"Albania": "#e76f51",
"USA": "#a7c957",
"Argentina": "#e5989b",
}
bar.set_bar_color(bar_colors)
assert bar.datafier.bar_colors == bar_colors
def test_barplot_set_bar_color_error_length(sample_data1):
with pytest.raises(AssertionError):
bar = Barplot(sample_data1, "%Y-%m-%d", "3MS")
bar_colors = [
"#2a9d8f",
"#e9c46a",
"#e76f51",
"#a7c957",
]
bar.set_bar_color(bar_colors)
assert bar.datafier.bar_colors == bar_colors
def test_barplot_set_bar_color_error_col_mismatch(sample_data1):
with pytest.raises(AssertionError):
bar = Barplot(sample_data1, "%Y-%m-%d", "3MS")
bar_colors = {
"India": "#2a9d8f",
"Angola": "#e9c46a",
"Albania": "#e76f51",
"USA": "#a7c957",
"Argentina": "#e5989b",
}
bar.set_bar_color(bar_colors)
assert bar.datafier.bar_colors == bar_colors
def test_barplot_set_text_error_empty_text(sample_data1):
with pytest.raises(AssertionError):
bar = Barplot(sample_data1, "%Y-%m-%d", "3MS")
bar.set_text("text1")
def test_barplot_set_text_priority(sample_data1):
bar = Barplot(sample_data1, "%Y-%m-%d", "3MS")
bar.set_text("text1", text="Test", callback=lambda *args: "Test")
assert "s" not in bar.text_collection["text1"][1]
def test_barplot_remove_text(sample_data1):
bar = Barplot(sample_data1, "%Y-%m-%d", "3MS")
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()) == ["time", "text3"]