-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtests.py
More file actions
106 lines (92 loc) · 3.09 KB
/
Copy pathtests.py
File metadata and controls
106 lines (92 loc) · 3.09 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
99
100
101
102
103
104
105
106
import os
import unittest
from datetime import datetime
from quickchart import QuickChart, QuickChartFunction
# Network-dependent tests hit the live quickchart.io service. They are skipped
# by default so the rest of the suite stays deterministic and offline-friendly.
# Set QUICKCHART_NETWORK_TESTS=1 to opt in.
RUN_NETWORK_TESTS = os.environ.get("QUICKCHART_NETWORK_TESTS") == "1"
class TestQuickChart(unittest.TestCase):
def test_simple(self):
qc = QuickChart()
qc.width = 600
qc.height = 300
qc.device_pixel_ratio = 2.0
qc.config = {
"type": "bar",
"data": {
"labels": ["Hello world", "Test"],
"datasets": [{"label": "Foo", "data": [1, 2]}],
},
}
url = qc.get_url()
self.assertIn("w=600", url)
self.assertIn("h=300", url)
self.assertIn("devicePixelRatio=2", url)
self.assertIn("Hello+world", url)
def test_version(self):
qc = QuickChart()
qc.version = "3.4.0"
qc.config = {
"type": "bar",
"data": {
"labels": ["Hello world", "Test"],
"datasets": [{"label": "Foo", "data": [1, 2]}],
},
}
url = qc.get_url()
self.assertIn("v=3.4.0", url)
def test_no_chart(self):
qc = QuickChart()
qc.width = 600
qc.height = 300
qc.device_pixel_ratio = 2.0
self.assertRaises(RuntimeError, qc.get_url)
@unittest.skipUnless(RUN_NETWORK_TESTS, "set QUICKCHART_NETWORK_TESTS=1 to run")
def test_get_bytes(self):
qc = QuickChart()
qc.width = 600
qc.height = 300
qc.config = {
"type": "bar",
"data": {
"labels": ["Hello world", "Test"],
"datasets": [{"label": "Foo", "data": [1, 2]}],
},
}
self.assertTrue(len(qc.get_bytes()) > 8000)
def test_with_function_and_dates(self):
qc = QuickChart()
qc.config = {
"type": "bar",
"data": {
"labels": [datetime(2020, 1, 15), datetime(2021, 1, 15)],
"datasets": [{"label": "Foo", "data": [1, 2]}],
},
"options": {
"scales": {
"yAxes": [
{
"ticks": {
"callback": QuickChartFunction('(val) => val + "k"')
}
}
],
"xAxes": [
{
"ticks": {
"callback": QuickChartFunction('(val) => "$" + val')
}
}
],
}
},
}
url = qc.get_url()
self.assertIn(
"7B%22ticks%22%3A%7B%22callback%22%3A%28val%29+%3D%3E+%22%24%22+%2B+val%7D%7D%5D%7D%7D%7D",
url,
)
self.assertIn("2020-01-15T00%3A00%3A00", url)
if __name__ == "__main__":
unittest.main()