-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_data_visualization.py
More file actions
98 lines (91 loc) · 3.26 KB
/
Copy pathtest_data_visualization.py
File metadata and controls
98 lines (91 loc) · 3.26 KB
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
import json
from src.blocks import data_visualization
def test_example01():
block = data_visualization.example01()
actual = block.to_dict()
expected = {
"type": "data_visualization",
"title": "My Favorite Candy Bars",
"chart": {
"type": "pie",
"segments": [
{"label": "Kit Kat", "value": 45},
{"label": "Twix", "value": 28},
{"label": "Crunch", "value": 18},
{"label": "Milky Way", "value": 9},
],
},
}
assert json.dumps(actual, sort_keys=True) == json.dumps(expected, sort_keys=True)
def test_example02():
block = data_visualization.example02()
actual = block.to_dict()
expected = {
"type": "data_visualization",
"title": "My Favorite Pies by Percentage of Tastiness",
"chart": {
"type": "bar",
"series": [
{
"name": "Pies",
"data": [
{"label": "Strawberry Rhubarb", "value": 85},
{"label": "Pumpkin", "value": 70},
{"label": "Lemon Meringue", "value": 72},
{"label": "Blueberry", "value": 90},
{"label": "Key Lime", "value": 56},
],
}
],
"axis_config": {
"categories": [
"Strawberry Rhubarb",
"Pumpkin",
"Lemon Meringue",
"Blueberry",
"Key Lime",
],
"x_label": "Pies",
"y_label": "Percentage of Tastiness",
},
},
}
assert json.dumps(actual, sort_keys=True) == json.dumps(expected, sort_keys=True)
def test_example03():
block = data_visualization.example03()
actual = block.to_dict()
expected = {
"type": "data_visualization",
"title": "Weekly Paper Sales",
"chart": {
"type": "line",
"series": [
{
"name": "Dunder Mifflin Infinity Website",
"data": [
{"label": "Week 1", "value": 32000},
{"label": "Week 2", "value": 35000},
{"label": "Week 3", "value": 29000},
{"label": "Week 4", "value": 41000},
{"label": "Week 5", "value": 45000},
],
},
{
"name": "Dunder Mifflin In-store",
"data": [
{"label": "Week 1", "value": 18000},
{"label": "Week 2", "value": 21000},
{"label": "Week 3", "value": 24000},
{"label": "Week 4", "value": 22000},
{"label": "Week 5", "value": 26000},
],
},
],
"axis_config": {
"categories": ["Week 1", "Week 2", "Week 3", "Week 4", "Week 5"],
"x_label": "Week",
"y_label": "Paper Sales (USD)",
},
},
}
assert json.dumps(actual, sort_keys=True) == json.dumps(expected, sort_keys=True)