80
71
self.assertEquals(sv(2222, [0, 10000]), 22.22)
82
73
self.raise_warnings(True)
83
self.assertRaises(UserWarning, sv, -10, [0, 1])
84
self.assertRaises(UserWarning, sv, 30, [0, 1])
75
# self.assertRaises(UserWarning, sv, -10, [0, 1])
76
# self.assertEquals(UserWarning, sv, 30, [0, 1])
86
78
def test_ext_scale(self):
87
79
sv = gc.ExtendedData.scale_value
97
89
self.assertRaises(UserWarning, sv, -10, [0, 1])
98
90
self.assertRaises(UserWarning, sv, 30, [0, 1])
101
class TestLineChart(TestBase):
103
def test_none_data(self):
104
chart = gc.SimpleLineChart(300, 100)
105
chart.add_data([1, 2, 3, None, 5])
106
self.assertChartURL(chart.get_url(), \
107
'?cht=lc&chs=300x100&chd=e:AAMzZm__zM')
109
class TestQRChart(TestBase):
111
def assertQRImage(self, chart, text):
115
print 'PyQrCodec not installed. Can not test QR code image'
120
status, string = PyQrcodec.decode(fn)
121
self.assertTrue(status)
122
self.assertEquals(text, string)
124
def test_simple(self):
126
chart = gc.QRChart(100, 150)
128
self.assertChartURL(chart.get_url(), \
129
'?cht=qr&chs=100x150&chl=Hello%20World')
131
def test_encoding(self):
132
chart = gc.QRChart(100, 100)
133
chart.add_data('Hello World')
134
self.assertChartURL(chart.get_url(), \
135
'?cht=qr&chs=100x100&chl=Hello%20World')
137
def test_no_data(self):
138
chart = gc.QRChart(100, 100)
139
self.assertRaises(NoDataGivenException, chart.get_url)
141
def test_validate_image(self):
143
chart = gc.QRChart(100, 100)
145
chart.set_ec('H', 0) # PyQrcodec seems to only work on higher EC
146
self.assertQRImage(chart, text)
148
def test_validate_utf8(self):
149
text = 'こんにちは世界' # Hello world in Japanese UTF8
150
chart = gc.QRChart(100, 100)
153
self.assertQRImage(chart, text)
155
def test_validate_shift_jis(self):
156
# XXX: It looks like PyQrcodec doesn't do shift_jis?
157
text = unicode('こんにちは世界', 'utf-8').encode('shift_jis')
158
chart = gc.QRChart(100, 100)
161
chart.set_encoding('Shift_JIS')
162
self.assertChartURL(chart.get_url(), \
163
'?cht=qr&chs=100x100&chl=%82%B1%82%F1%82%C9' \
164
'%82%BF%82%CD%90%A2%8AE&choe=Shift_JIS&chld=H|0')
165
chart.download('temp.png')
168
92
class TestGrammar(TestBase):
170
94
types = ('Venn', 'GroupedHorizontalBar', 'GoogleOMeter', 'Scatter',
171
95
'StackedVerticalBar', 'Map', 'StackedHorizontalBar', 'SimpleLine',
172
'SparkLine', 'GroupedVerticalBar', 'SplineRadar', 'XYLine', 'Radar',
96
'SparkLine', 'GroupedVerticalBar', 'SplineRadar', 'XYLine', 'Radar')
175
98
def test_chart_types(self):
176
99
ret = gc.ChartGrammar.get_possible_chart_types()