Package GChartWrapper :: Module tests
[hide private]
[frames] | no frames]

Source Code for Module GChartWrapper.tests

  1  #!/usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3  from GChartWrapper import * 
  4  from GChartWrapper.encoding import Encoder 
  5  from GChartWrapper.constants import PY_VER,_print 
  6  import unittest 
  7   
8 -class TestChartTypes(unittest.TestCase):
9 """ 10 Extensive unit tests, more are welcome 11 12 All methods should be commented and must return a GChart instance as the last line. 13 """ 14 # All is dict of (name : checksum) pairs 15 all = { 16 'currency_bar':'8ec06bda7223eb500e7f0357efd6e717543d9abb', 17 'financial':'0c3dee619eb6c43d8b5405f537438467a7d736e5', 18 'text_pin':'42558403a2a9d66e9b54deea094114029c86d529', 19 'simple':'1fb72aac2758d164bca43a40472ae185091291b1', 20 'text':'4e1f2755c9f6160d959ed91829543e0687b55a0e', 21 'guide_granularity_20':'1dfcb2ba4444e3c09be3b55221cc04e5a5c0bf32', 22 'pie':'3fe7636938cda678be044848799a2c87ecad6099', 23 'small_bubble_icon':'65d1df5f7bda98cfaea2a96dfe8dcca1058c444c', 24 'guide_granularity_40':'dc7d8714f28d7a59d2b768ecba7f685814a73bd4', 25 'guide_radar':'9703b8ca52e8c38c37353c6935d5053f8120c37a', 26 'icon_pin':'01110b589dbe1ed9aed7a3eb057bd9020b6d21a2', 27 'guide_sparkline':'767bab6609f60b6c7185b0ed0a1434ad9d73f4c7', 28 'guide_bhg':'b051f7ab51afd534f89095fab7db3c161fcb3bc3', 29 'margins':'4f995e40b16a49d0c407c0bf1b536f7642f6253d', 30 'venn':'cf327d123a3a2fdf04620a966903fc20f096f82c', 31 'fill':'1766f4b8b774d41985a4a3b2ab3f9791dedab2a3', 32 'guide_line_lc':'11ec3b84d8de22e8bf6a32cbca3b62374aa68a46', 33 'large_bubble_icon_texts':'20c705a0e3038594749b8b9cdf8f09e470e76b17', 34 'large_bubble_texts':'ff1474c87defa687727a4ee42dca9c641a46668c', 35 'guide_granularity_300':'0d5a40563ad832312bd357564a9da9787e38d6ef', 36 'large_bubble_icon':'f09ebedf3cc5c461604539afdcff9dac09817d71', 37 'adv_icon_pin':'b8a2ec08aeb3fb0a839598a82dfba02c7cdc8638', 38 'axes':'6040f894d8e71160b9e87541f7ef9db224efae9c', 39 'qr_code':'bdcea2f3b1dbb331de2ed8a730736c99f2d81c90', 40 'markers':'fc7ab02d17a07a611a02b0a4dda7763c4bfec712', 41 'guide_granularity_80':'014f1a251dab5fa14fdadf7868b64a210bb1cf5e', 42 'axes_position':'7d6d5d0fa5565ef3e1069ba91db472484a339696', 43 'jacobian':'6d0d251ac640c0d5185124cb5ea9ccc636268f14', 44 'multiline':'5f27957e39363ca470c0e97d1fcffdc19fa00afb', 45 'numpy':'9b0fb89df43d69b64755153b919e598180fc1a9d', 46 'guide_meter':'cdad708a80c49b705212d098bf83f9ccb30610aa', 47 'letter_pin':'430c921aa8d73e80feae07b2ba04909c6a6b1ab3', 48 'guide_granularity_150':'35281ef165d532021290c003e2068527d40003b0', 49 'guide_intro':'0b3b189c0675fd51bda46714706e3f7dfb4164dc', 50 'thought_note':'9375cabf12b442764db34862c68ae74f85c42ca9', 51 'czech_and_unicode':'ead386ad75dabb21e13fd4b3a357d6025bdd4506', 52 'guide_bvg':'36ce2efaf74fad1912b8351147b821d0253f9c56', 53 'min_max':'5aae24644331ca33c0cb83dc01a34d389edd6adf', 54 'guide_bhs':'a1d1801762105d58f67c544be36e2af7bf69a2a8', 55 'guide_map':'2391235ee09f58cc194eaf16b3c87f839613ebc5', 56 'guide_bvs':'e65f1bea45ae7197943366d8de1268aad6e5b66d', 57 'grid':'90953636424f46e568bf8a316efbba4df0461eef', 58 'legend2':'acc8c1a1199e2363fee076486365b6f8a29e72a0', 59 'line':'9b6f9a566b49fa23c91a6f992e4a4737caac4ae5', 60 'guide_chbh_size':'a6b043ed705fe90afef78c393403fc813ca7aa1e', 61 'legend':'33cd2c7acdc4aa9745ed95a0aa1ff641525adf5c', 62 'adv_letter_pin':'97cd7dac85adad57e2cf8209d0795a4f5216cb6a', 63 'sticky_note':'a3a55893fc130abd814c80c9841e3547e2c2877a', 64 'bar':'d3251fb77a28a5918955020c745fa435b0f4a314', 65 'bar_text':'c01b4efa34a4850f6888ebcde3d9ee28ba621f85', 66 'title':'40d64c1c3aeb9c3836e501033c4bf65da2ff2f83', 67 'tick_marks':'9cab6532523a353cd87d3edec45d9222de9dde5d', 68 'concentric_pie':'cb6325bb97779fabdc77c8ab76e6bf4ed1d5447b', 69 'hvz':'7a890b9c2c6016faff3cb6789d9732a5caf8fa9d', 70 'guide_chbh_clipped':'83ff879fc173bbcf80350d62d7d880b619424d10', 71 'guide_bvs_scale':'a327b4be8fa55deccba5b4baab7680c75f621064', 72 'weather_note':'9a7988231bc235bda5ab21e19288fba5b554adf7', 73 'markerfill':'95664c2d4aeae5bcb94b1b003b361e2035d44e64', 74 'packman':'2cd25d4a258abb9d62d144668e3cb54f71b01af1', 75 'interval':'5e60f45fb27f32aefe048d9eb22f17a7d117c162', 76 'bar_zero':'94219f27b54883078db0ef744292a40e46de2da7', 77 'omitted_colors':'bc72f51d748767fc1692b6a227d5184415e9e2f5', 78 'scatter':'36f99c6a7e93af8d164af220ae626c10002f808e', 79 'fancy_radar':'049d0fe4a213204e8e31f07658c7a665ea866698', 80 'legend_position':'5f2d550e98ae1a85312b4d7e33761d30ca89acfd', 81 'circle_diamonds':'0e02091bfe03d6cf31704c87de01dea6c47e3717', 82 } 83
84 - def __init__(self, *a, **kw):
85 super(TestChartTypes, self).__init__(*a, **kw)
86
87 - def _test_a_chart(self, rep, chart):
88 chart_name = rep.split('test_')[1][:-1] 89 self.assertEqual(self.all[chart_name], chart.checksum(), 90 '%s: %s != %s'%(chart_name,self.all[chart_name],chart.checksum()))
91
92 - def test_scatter(self):
93 G = Scatter([[12,87,75,41,23,96,68,71,34,9],[98,60,27,34,56,79,58,74,18,76],[84,23,69,81,47,94,60,93,64,54]]) 94 G.axes('xy') 95 G.axes.label(0, 0,20,30,40,50,60,70,80,90,10) 96 G.axes.label(1, 0,25,50,75,100) 97 G.size(300,200) 98 self._test_a_chart(repr(self), G) 99 return G
100
101 - def test_fancy_radar(self):
102 G = RadarSpline(['voJATd9v','MW9BA9'],encoding='simple') 103 G.color('red','orange') 104 G.size(400,400) 105 G.line(2,4,0) 106 G.line(2,4,0) 107 G.axes('x') 108 G.axes.label(0, 0,45,90,135,180,225,270,315) 109 G.axes.range(0, 0.0,360.0) 110 G.grid(25.0,25.0,4.0,4.0) 111 G.marker('B','FF000080',0,1.0,5.0) 112 G.marker('B','FF990080',1,1.0,5.0) 113 G.marker('h','blue',0,1.0,4.0) 114 G.marker('h','3366CC80',0,0.5,5.0) 115 G.marker('V','00FF0080',0,1.0,5.0) 116 G.marker('V','008000',0,5.5,5.0) 117 G.marker('v','00A000',0,6.5,4) 118 self._test_a_chart(repr(self), G) 119 return G
120
121 - def test_omitted_colors(self):
122 G = Line([[20,10,15,25,17,30],[0,5,10,7,12,6],[35,25,45,47,24,46],[15,40,30,27,39,54],[70,55,63,59,80,60]],encoding='text',series=1) 123 G.scale(0,100,-50,100) 124 G.marker('F','',1,'1:4',20) 125 self._test_a_chart(repr(self), G) 126 return G
127
128 - def test_bar_zero(self):
129 G = VerticalBarGroup([20,35,50,10,95],encoding='text') 130 G.color('cc0000') 131 G.position(.5) 132 self._test_a_chart(repr(self), G) 133 return G
134
135 - def test_interval(self):
136 G = Line('cEAELFJHUc',encoding='simple') 137 G.color('76A4FB') 138 G.line(2) 139 G.axes('x') 140 G.axes.range(0,10,50,5) 141 self._test_a_chart(repr(self), G) 142 return G
143
144 - def test_packman(self):
145 G = Pie([80,20]) 146 G.orientation(0.628) 147 G.color('yellow','white') 148 self._test_a_chart(repr(self), G) 149 return G
150
151 - def test_simple(self):
152 # Instantiate the GChart instance, this is all you will need for making charts 153 # GChart(type=None, dataset=None), see the doc for more 154 G = GChart() 155 # Set the chart type, either Google API type or regular name 156 G.type('pie') 157 # Update the chart's dataset, can be two dimensional or contain string data 158 G.dataset( 'helloworld' ) 159 # Set the size of the chart, default is 300x150 160 G.size(250,100) 161 self._test_a_chart(repr(self), G) 162 return G
163
164 - def test_hvz(self):
165 # Make a vertical bar group and scale it to the max 166 G = VerticalBarGroup( [[31],[59],[4]], encoding='text' ) 167 G.scale(0,59) 168 G.color('lime','red','blue') 169 G.legend('Goucher(31)','Truman(59)','Kansas(4)') 170 G.fill('c','lg',45,'cccccc',0,'black',1) 171 G.fill('bg','s','cccccc') 172 G.size(200,100) 173 self._test_a_chart(repr(self), G) 174 return G
175
176 - def test_qr_code(self):
177 # Output a QR code graph that allows 15% restore with 0 margin 178 # *Defaults to UTF-8 encoding 179 G = QRCode('''To the human eye QR Codes look like hieroglyphics, 180 but they can be read by any device that has 181 the appropriate software installed.''') 182 # or use output_encoding method 183 G.output_encoding('UTF-8') 184 # level_data(error_correction,margin_size) 185 G.level_data('M',0) 186 self._test_a_chart(repr(self), G) 187 return G
188
189 - def test_title(self):
190 # Title using name with optional color and size 191 G = Line( ['GurMrabsClgubaolGvzCrgrefOrnhgvshyvforggregunahtyl'] ) 192 G.title('The Zen of Python','00cc00',36) 193 G.color('00cc00') 194 self._test_a_chart(repr(self), G) 195 return G
196
197 - def test_line(self):
198 # Add red line 6 thick 199 # with 5 line segments with 2 blank segments 200 G = Line( ['hX1xPj'] ) 201 G.axes('xy') 202 G.axes.label(0, 'Mar', 'Apr', 'May', 'June', 'July') 203 G.axes.label(1, None, '50+Kb') 204 G.color('red') 205 G.line(6,5,2) 206 self._test_a_chart(repr(self), G) 207 return G
208
209 - def test_bar(self):
210 # 2 color horizontal bars 10 wide 211 # with 5 spacing between bars in group and 10 between groups 212 G = HorizontalBarGroup( ['hell','orld'] ) 213 G.color('cc0000', '00aa00') 214 G.bar(10,5,10) 215 self._test_a_chart(repr(self), G) 216 return G
217
218 - def test_pie(self):
219 # Simple pie chart based on list 220 G = Pie3D( [1,2,3,4] ) 221 G.label('A','B','C','D') 222 G.color('00dd00') 223 self._test_a_chart(repr(self), G) 224 return G
225
226 - def test_venn(self):
227 # Extended venn diagram based on int list, scale the data to the max value 228 G = Venn( [100,80,60,30,30,30,10], encoding='text') 229 G.scale(0,100) 230 self._test_a_chart(repr(self), G) 231 return G
232
233 - def test_axes(self):
234 # Call type first with the chxt 235 # then call label and style in order, 236 # label can contain None(s) 237 G = Line( ['foobarbaz'] ) 238 G.color('76A4FB') 239 G.axes('xyrx') 240 G.axes.label(0,'Foo', 'Bar', 'Baz') 241 G.axes.style(0, '0000dd', 14) 242 G.axes.label(1, None, '20K', '60K', '100K') 243 G.axes.label(2, 'A', 'B', 'C') 244 G.axes.label(3, None,'20','40','60','80') 245 self._test_a_chart(repr(self), G) 246 return G
247
248 - def test_grid(self):
249 # Create dashed line with grid x,y as floats 250 # then, just like line, the line and blank segments 251 G = Line( ['foobarbaz'] ) 252 G.color('76A4FB') 253 G.line(3,6,3) 254 G.grid(20.0,25.0,1,0) 255 self._test_a_chart(repr(self), G) 256 return G
257
258 - def test_markers(self):
259 # Mark up some of the data randomly 260 G = Line( ['helloWorldZZZZ098236561'] ) 261 G.marker('c','red',0,1,20) 262 G.marker('d','80C65A',0,6,15) 263 G.marker('o','FF9900',0,4.0,20.0) 264 G.marker('s','3399CC',0,5.0,10.0) 265 G.marker('v','BBCCED',0,6.0,1.0) 266 G.marker('V','3399CC',0,7.0,1.0) 267 G.marker('x','FFCC33',0,8.0,20.0) 268 G.marker('h','black',0,0.30,0.5 ) 269 G.marker('a','000099',0,4,10) 270 G.marker('R','A0BAE9',0,8,0.6) 271 G.marker('r','E5ECF9',0,1,0.25) 272 self._test_a_chart(repr(self), G) 273 return G
274
275 - def test_jacobian(self):
276 # from http://toys.jacobian.org/hg/googlecharts/raw-file/tip/docs/examples.html 277 G = Line(['ALAtBmC1EcGYIsLWOXRuVdZhd9ivn4tYzO5b..'],encoding='extended') 278 G.size(300,200) 279 G.color('cc0000') 280 G.fill('c','s','eeeeee') 281 G.legend('Sweet') 282 self._test_a_chart(repr(self), G) 283 return G
284
285 - def test_markerfill(self):
286 # Fill the chart areas with markers 287 G = Line( ['99','cefhjkqwrlgYcfgc', 288 'QSSVXXdkfZUMRTUQ','HJJMOOUbVPKDHKLH','AA'] ) 289 G.marker('b','76A4FB',0,1,0) 290 G.marker('b','224499',1,2,0) 291 G.marker('b','red',2,3,0) 292 G.marker('B','80C65A',3,4,0) 293 self._test_a_chart(repr(self), G) 294 return G
295
296 - def test_fill(self):
297 # Fill the chart/background using chf, add axes to show bg 298 G = Line( ['pqokeYONOMEBAKPOQVTXZdecaZcglprqxuux393ztpoonkeggjp'] ) 299 G.color('red') 300 G.line(4,3,0) 301 G.axes('xy') 302 G.axes.label(0, 1,2,3,4,5) 303 G.axes.label(1, None,50,100) 304 G.fill('c','lg',45,'white',0,'76A4FB',0.75) 305 G.fill('bg','s','EFEFEF') 306 self._test_a_chart(repr(self), G) 307 return G
308 309
310 - def test_legend(self):
311 # Add legend to the data set which follows collors 312 G = Line( ['FOETHECat','leafgreen','IRON4YOUs'] ) 313 G.color('red','lime','blue') 314 G.legend('Animals','Vegetables','Minerals') 315 G.axes('y') 316 self._test_a_chart(repr(self), G) 317 return G
318
319 - def test_legend2(self):
320 # Add a left aligned legend to the chart 321 G = Line( ['abcde','FGHIJ','09876'] ) 322 G.color('red','lime','blue') 323 G.legend('Animals','Vegetables','Minerals') 324 G.legend_pos('l') 325 G.axes('y') 326 self._test_a_chart(repr(self), G) 327 return G
328
329 - def test_legend_position(self):
330 # Place the legend in the top position 331 G = Venn([100,20,20,20,20,0,0]) 332 G.legend('First','Second','Third') 333 G.legend_pos('t') 334 G.color('red','lime','blue') 335 self._test_a_chart(repr(self), G) 336 return G
337
338 - def test_multiline(self):
339 # Draw multiple lines with markers on an lxy chart 340 G = LineXY( [ 341 [0,30,60,70,90,95,100], # x values 342 [20,30,40,50,60,70,80], # y values, etc. 343 [10,30,40,45,52], 344 [100,90,40,20,10], 345 ['-1'], # domain not found, interpolated 346 [5,33,50,55,7], 347 ]) 348 G.scale(0,100) 349 G.color('3072F3','red','00aaaa') 350 G.marker('s','red',0,-1,5) 351 G.marker('s','blue',1,-1,5) 352 G.marker('s','00aa00',2,-1,5) 353 G.line(2,4,1) 354 self._test_a_chart(repr(self), G) 355 return G
356
357 - def test_axes_position(self):
358 # multiple axis with label positions specified 359 # values between 0 and 100 - use text encoding 360 data = [[4.6, 6.0, 7.4, 11.6, 12.0, 14.8, 18.1, 25.1, 361 27.9, 28.3, 30.6, 34.4, 43.7, 48.3, 57.6, 64.6, 362 72.5, 74.4, 76.2, 77.2, 86.0, 86.9, 93.9, 96.7, 99.0], 363 [80.5, 100.0, 95.4, 93.7, 96.3, 91.7, 71.5, 63.0, 364 65.2, 65.5, 66.0, 75.9, 65.8, 64.4, 64.2, 62.5, 37.2, 365 35.3, 32.4, 35.2, 38.4, 37.9, 69.8, 38.0, 64.5]] 366 367 # positions between 0 and 100 368 axis = [ [0, 13, 28, 42, 56, 71, 84, 100], 369 ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] ] 370 371 # don't do integer arithmetic 372 min_value = float(min(data[1])) 373 max_value = float(max(data[1])) 374 last_value = float(data[1][-1]) 375 376 G = LineXY(data, encoding='text') 377 G.color('76A4FB') 378 G.marker('o', '0077CC',0,-1,5) 379 G.marker('r', 'E6F2FA',0,(min_value/max_value),1.0) # 0 to 1.0 380 G.axes("xyr") 381 G.axes.label(0, *axis[1]) 382 G.axes.position(0, *axis[0]) 383 G.axes.label(1, '%d'%min_value, '%d'%max_value) 384 G.axes.position(1, int(100*min_value/max_value),100) # 0 to 100 385 G.axes.label(2, '%d'%last_value) 386 G.axes.position(2, int(100*last_value/max_value)) # 0 to 100 387 self._test_a_chart(repr(self), G) 388 return G
389 390 # Examples from the Google Chart API Developer's Guide 391 # http://code.google.com/apis/chart/ 392
393 - def test_guide_intro(self):
394 G = Pie3D([60,40], encoding='text') 395 G.size(250,100) 396 G.label('Hello', 'World') 397 self._test_a_chart(repr(self), G) 398 return G
399
400 - def test_guide_granularity_20(self):
401 G = Line('fohmnytenefohmnytene', encoding='simple') 402 G.size(200,100) 403 G.axes('xy') 404 G.axes.label(0, 'April','May','June') 405 G.axes.label(1, None, '50+Kb') 406 self._test_a_chart(repr(self), G) 407 return G
408
409 - def test_guide_granularity_40(self):
410 G = Line('frothsmzndyoteepngenfrothsmzndyoteepngen', encoding='simple') 411 G.size(200,100) 412 G.axes('xy') 413 G.axes.label(0, 'April','May','June') 414 G.axes.label(1, None, '50+Kb') 415 self._test_a_chart(repr(self), G) 416 return G
417
418 - def test_guide_granularity_80(self):
419 G = Line('formostthisamazingdayfortheleapinggreenlformostthisamazingdayfortheleapinggreenl', 420 encoding='simple') 421 G.size(200,100) 422 G.axes('xy') 423 G.axes.label(0, 'April','May','June') 424 G.axes.label(1, None, '50+Kb') 425 self._test_a_chart(repr(self), G) 426 return G
427
428 - def test_guide_granularity_150(self):
429 G = Line('ithankYouGodformostthisamazingdayfortheleapinggreenlyspiritsoftreesandabluetruedreamofskyandforeverythingwhichisnaturalwhichisinfinitewhichisyeseecumm', 430 encoding='simple') 431 G.size(200,100) 432 G.axes('xy') 433 G.axes.label(0, 'April','May','June') 434 G.axes.label(1, None, '50+Kb') 435 self._test_a_chart(repr(self), G) 436 return G
437
438 - def test_guide_granularity_300(self):
439 G = Line('ithankYouGodformostthisamazingdayfortheleapinggreenlyspiritsoftreesandabluetruedreamofskyandforeverythingwhichisnaturalwhichisinfinitewhichisyesithankYouGodformostthisamazingdayfortheleapinggreenlyspiritsoftreesandabluetruedreamofskyandforeverythingwhichisnaturalwhichisinfinitewhichisyeseecummings', 440 encoding='simple') 441 G.size(200,100) 442 G.axes('xy') 443 G.axes.label(0, 'April','May','June') 444 G.axes.label(1, None, '50+Kb') 445 self._test_a_chart(repr(self), G) 446 return G
447
448 - def test_guide_line_lc(self):
449 # http://code.google.com/apis/chart/#line_charts 450 G = Line('fooZaroo', encoding='simple') 451 G.size(200,100) 452 self._test_a_chart(repr(self), G) 453 return G
454 455 456
457 - def test_guide_sparkline(self):
458 # http://code.google.com/apis/chart/#sparkline 459 G = Sparkline([27,25,25,25,25,27,100,31,25,36,25,25,39, 460 25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25, 461 27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25, 462 26,37,33,33,37,37,39,25,25,25,25], encoding='text') 463 G.color('0077CC') 464 G.size(200,40) 465 G.marker('B', 'E6F2FA',0,0,0) 466 G.line(1,0,0) 467 self._test_a_chart(repr(self), G) 468 return G
469 470
471 - def test_guide_bhs(self):
472 # http://code.google.com/apis/chart/#bar_charts 473 G = HorizontalBarStack('ello', encoding='simple') 474 G.color('4d89f9') 475 G.size(200,125) 476 self._test_a_chart(repr(self), G) 477 return G
478
479 - def test_guide_bvs(self):
480 G = VerticalBarStack([ [10,50,60,80,40],[50,60,100,40,20] ], encoding='text') 481 G.color('4d89f9', 'c6d9fd') 482 G.size(200,125) 483 self._test_a_chart(repr(self), G) 484 return G
485
486 - def test_guide_bvs_scale(self):
487 G = VerticalBarStack([ [10,50,60,80,40],[50,60,100,40,20] ], encoding='text') 488 G.color('4d89f9', 'c6d9fd') 489 G.size(200,125) 490 G.scale(0,160) 491 self._test_a_chart(repr(self), G) 492 return G
493
494 - def test_guide_bhg(self):
495 G = HorizontalBarGroup(['el','or'], encoding='simple') 496 G.color('4d89f9','c6d9fd') 497 G.size(200,125) 498 self._test_a_chart(repr(self), G) 499 return G
500
501 - def test_guide_bvg(self):
502 G = VerticalBarGroup(['hello','world'], encoding='simple') 503 G.color('4d89f9','c6d9fd') 504 G.size(200,125) 505 self._test_a_chart(repr(self), G) 506 return G
507
508 - def test_guide_chbh_clipped(self):
509 G = HorizontalBarStack('hello', encoding='simple') 510 G.color('4d89f9') 511 G.size(200,125) 512 self._test_a_chart(repr(self), G) 513 return G
514
515 - def test_guide_chbh_size(self):
516 G = HorizontalBarStack('hello', encoding='simple') 517 G.color('4d89f9') 518 G.size(200,125) 519 G.bar(10) 520 self._test_a_chart(repr(self), G) 521 return G
522
523 - def test_guide_radar(self):
524 # Create a radar chart w/ multiple lines 525 G = Radar([ [77,66,15,0,31,48,100,77],[20,36,100,2,0,100] ], encoding='text') 526 G.size(200,200) 527 G.color('red','FF9900') 528 G.line(2,4,0) 529 G.line(2,4,0) 530 G.axes('x') 531 G.axes.label(0, 0,45,90,135,180,225,270,315) 532 G.axes.range(0, 0,360) 533 self._test_a_chart(repr(self), G) 534 return G
535
536 - def test_guide_map(self):
537 # Make a map of the US as in the API guide 538 G = Map('fSGBDQBQBBAGABCBDAKLCDGFCLBBEBBEPASDKJBDD9BHHEAACAC', encoding='simple') 539 G.color('f5f5f5','edf0d4','6c9642','365e24','13390a') 540 G.fill('bg','s','eaf7fe') 541 G.size(440,220) 542 G.map('usa', 'NYPATNWVNVNJNHVAHIVTNMNCNDNELASDDCDEFLWAKSWIORKYMEOHIAIDCTWYUTINILAKTXCOMDMAALMOMNCAOKMIGAAZMTMSSCRIAR') 543 self._test_a_chart(repr(self), G) 544 return G
545
546 - def test_guide_meter(self):
547 # Create a simple Google-O-Meter with a label 548 G = Meter(70) 549 G.label('Hello') 550 G.size(225,125) 551 self._test_a_chart(repr(self), G) 552 return G
553
554 - def test_numpy(self):
555 # Test to see whether numpy arrays work correctly 556 # Must have numpy installed to do this test correctly 557 data = [10,20,30,40,50,60,70,80,90] 558 try: 559 from numpy import array 560 data = array(data) 561 except ImportError: 562 _print('Warning: numpy must be installed to do this test correctly') 563 G = Radar(data, encoding='text') 564 G.size(200,200) 565 self._test_a_chart(repr(self), G) 566 return G
567
568 - def test_concentric_pie(self):
569 # Using concentric pie charts 570 G = PieC(['Helo','Wrld'], encoding='simple') 571 G.size(200,100) 572 self._test_a_chart(repr(self), G) 573 return G
574
575 - def test_financial(self):
576 # Fancy markers for financial data 577 G = Line([[0,5,10,7,12,6],[35,25,45,47,24,46],[15,40,30,27,39,54],[70,55,63,59,80,60]], encoding='text') 578 G.marker('F','blue',0,'1:4',20) 579 G.size(200,125) 580 self._test_a_chart(repr(self), G) 581 return G
582
583 - def test_bar_text(self):
584 # Using text markers in a bar chart 585 G = HorizontalBarGroup([[40,60],[50,30]], encoding='text') 586 G.size(200,125) 587 G.marker('tApril mobile hits','black',0,0,13) 588 G.marker('tMay mobile hits','black',0,1,13,-1) 589 G.marker('tApril desktop hits','black',1,0,13) 590 G.marker('tMay desktop hits', 'black',1,1,13) 591 G.color('FF9900','FFCC33') 592 self._test_a_chart(repr(self), G) 593 return G
594
595 - def test_margins(self):
596 G = Line(['Uf9a','a3fG'], encoding='simple') 597 G.size(250,100) 598 G.label(1,2,3,4) 599 G.fill('bg','s','e0e0e0') 600 G.color('black','blue') 601 G.margin(20,20,20,30,80,20) 602 G.legend('Temp','Sales') 603 self._test_a_chart(repr(self), G) 604 return G
605
606 - def test_min_max(self):
607 G = Line('mHMza', encoding='simple') 608 G.color('008000') 609 G.line(2.0,4.0,1.0) 610 G.size(200,140) 611 G.axes('x') 612 G.axes.label(0, None,'t',None,'F',None) 613 G.marker('tMin','blue',0,1,10) 614 G.marker('fMax','red',0,3,15) 615 G.margin(0,0,30,0) 616 self._test_a_chart(repr(self), G) 617 return G
618
619 - def test_text(self):
620 # Make a text chart label w/ any text you like 621 # Google automagically ignores white space and spaces text correctly 622 text = ''' 623 1600 Ampitheatre Parkway 624 Mountain View, CA 625 (650)+253-0000 626 ''' 627 G = Text('darkred',16,'h','red','b',text) 628 self._test_a_chart(repr(self), G) 629 return G
630
631 - def test_letter_pin(self):
632 # Simple map pin w/ a letter/number 633 G = Pin('pin_letter','A','red','black') 634 self._test_a_chart(repr(self), G) 635 return G
636
637 - def test_icon_pin(self):
638 # Map pin w/ a certain icon 639 G = Pin('pin_icon','home','yellow') 640 self._test_a_chart(repr(self), G) 641 return G
642
643 - def test_adv_letter_pin(self):
644 G = Pin('xpin_letter','star','A','aqua','black','red') 645 self._test_a_chart(repr(self), G) 646 return G
647
648 - def test_adv_icon_pin(self):
649 # Map pin w/ cool icon 650 G = Pin('xpin_icon','star','home','aqua','red') 651 self._test_a_chart(repr(self), G) 652 return G
653
654 - def test_text_pin(self):
655 # Straight up map pin w/ following text 656 G = Pin('spin',1.2,30,'FFFF88',10,'_','Foo\nBar') 657 self._test_a_chart(repr(self), G) 658 return G
659
660 - def test_sticky_note(self):
661 # Note w/ title and text 662 G = Note('note_title','pinned_c',1,'darkgreen','l',"Joe's\nToday 2-for-1 !\n555-1234") 663 self._test_a_chart(repr(self), G) 664 return G
665
666 - def test_thought_note(self):
667 # Thought bubble note 668 G = Note('note','thought',1,'navy','h',"wouldn't it be\ngreat to eat\nat Joe's?") 669 self._test_a_chart(repr(self), G) 670 return G
671
672 - def test_weather_note(self):
673 # First example w/ true utf-8 encoding 674 G = Note('weather','taped_y','sunny','Barcelona','max 25°','min 15°') 675 self._test_a_chart(repr(self), G) 676 return G
677
678 - def test_small_bubble_icon(self):
679 # Small bubble marker 680 G = Bubble('icon_text_small','petrol','bb','$3/gal','khaki','black') 681 self._test_a_chart(repr(self), G) 682 return G
683
684 - def test_large_bubble_icon(self):
685 # Larger bubble marker 686 G = Bubble('icon_text_big','snack','bb','$2.99','ffbb00','black') 687 self._test_a_chart(repr(self), G) 688 return G
689
690 - def test_large_bubble_icon_texts(self):
691 # Large bubble marker w/ icon and multiline text 692 G = Bubble('icon_texts_big','petrol','bb','khaki','black','LoCost Fuel\n$3.05/gal unleaded\n$2.10/gal diesel') 693 self._test_a_chart(repr(self), G) 694 return G
695
696 - def test_large_bubble_texts(self):
697 # Large bubble marker with just text 698 G = Bubble('texts_big','bb','teal','khaki',"Joe\'s Restaurant\n123 Long St\n92745 Mountain View") 699 self._test_a_chart(repr(self), G) 700 return G
701
702 - def test_czech_and_unicode(self):
703 # Submitted by anedvedicky 704 G = VerticalBarStack( [[10], [20], [30]], encoding = 'text') 705 G.color('green','lime','red') 706 G.label('šýŽěůčář...') 707 G.legend('šýŽěůčář...','∫µ≤','´®†¥¨ˆøπ¬˚≤µ˜') 708 self._test_a_chart(repr(self), G) 709 return G
710
711 - def test_tick_marks(self):
712 G = Line('cEAELFJHHHKUju9uuXUc', encoding="simple") 713 G.color('76A4FB') 714 G.size(220, 125) 715 G.line(2) 716 G.axes('xyrx') 717 G.axes.range(1, 0,4) 718 G.axes.label(2, 'min','avg','max') 719 G.axes.label(3, 'Jan','Feb','Mar') 720 G.axes.style(2, '0000DD',13,-1,'t','FF0000') 721 G.axes.position(2, 10,35,95) 722 G.axes.tick(1,10) 723 G.axes.tick(2,-180) 724 self._test_a_chart(repr(self), G) 725 return G
726
727 - def test_currency_bar(self):
728 G = VerticalBarStack([43.56,35.62,48.34,57.50,67.30,60.91]) 729 G.color('blue') 730 G.bar(17,15) 731 G.marker('N*cEUR1*','black',0,-1,11) 732 self._test_a_chart(repr(self), G) 733 return G
734
735 - def test_circle_diamonds(self):
736 G = Line(['Hello','world']) 737 G.marker('o','ff9900',0,-1,15.0) 738 G.marker('d','ff0000',1,-1,10.0) 739 self._test_a_chart(repr(self), G) 740 return G
741
742 - def test_fromstring(self):
743 url='http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World' 744 self.assertEqual(GChart.fromurl(url).checksum(),'4e53c7add42ce61a933ce106a9854222c54c9147')
745
746 - def _test_encoding(self, encoding, expected, data, scale):
747 codec = Encoder(encoding, scale) 748 self.assertEqual(codec.encode(data), expected) 749 self.assertEqual(codec.decode(codec.encode(data)), [data])
750
751 - def test_simple_encode(self):
752 self._test_encoding('simple', 's:Ab9', [0,27,61], 61)
753
754 - def test_text_encode(self):
755 self._test_encoding('text', 't:0.0,10.0,100.0,-1.0,-1.0', [0,10,100,-1,-1], (0,100))
756
757 - def test_extended_encode(self):
758 self._test_encoding('extended', 'e:AH-HAA..', [7,3975,0,4095], 4095)
759
760 -def get_chart(chart):
761 return getattr(TestChartTypes('test_%s'%chart), 'test_%s'%chart)()
762
763 -def saveall():
764 import os 765 if not os.path.isdir('tests'): 766 os.mkdir('tests') 767 for chart in TestChartTypes.all: 768 chartobj = get_chart(chart) 769 chartobj.save('tests/%s'%chart)
770 771 if __name__ == '__main__': 772 import sys 773 calls = { 774 'unit': lambda: unittest.main(), 775 'save': lambda: saveall(), 776 } 777 arg = sys.argv[-1] 778 sys.argv = sys.argv[:-1] 779 if arg in calls: 780 calls[arg]() 781 else: 782 for chart in TestChartTypes.all: 783 _print( chart,'\t',get_chart(chart)) 784