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

Source Code for Module GChartWrapper.tests

  1  #!/usr/bin/env python 
  2  from GChartWrapper.testing import TestClass 
  3  from GChartWrapper.constants import _print 
  4  import os 
  5  import sys 
  6  from inspect import getsource 
  7  import unittest 
  8   
  9  Test = TestClass() 
 10   
 11  ordering = ('simple', 'financial', 'bar_text', 'concentric_pie', 'margins',  
 12  'min_max', 'text', 'letter_pin', 'icon_pin', 'adv_icon_pin', 'adv_letter_pin', 
 13  'text_pin', 'sticky_note', 'thought_note', 'weather_note', 'small_bubble_icon', 
 14  'large_bubble_icon', 'large_bubble_icon_texts', 'large_bubble_texts','qr_code',  
 15  'legend', 'bar', 'pie', 'guide_granularity_20',   
 16  'guide_granularity_40', 'guide_granularity_80', 'guide_radar', 'hvz',  
 17  'guide_sparkline',  'venn', 'fill', 'guide_line_lc', 'title', 'axes',  
 18  'markers',  'line', 'multiline', 'axes_position', 'jacobian',  'numpy',  
 19  'guide_meter', 'guide_intro',    'guide_map',  'grid', 'legend2','guide_bhs', 
 20  'guide_bvs', 'guide_bvs_scale', 'guide_bvg', 'guide_bhg', 'guide_chbh_clipped', 
 21  'guide_chbh_size') 
 22   
 23   
24 -class ChartsTest(unittest.TestCase):
25 - def test_charts(self):
26 for test,checksum in Test.all.items(): 27 calcsum = getattr(Test,test)().checksum() 28 self.assertEqual(calcsum, checksum, 'Bad checksum for %s'%test)
29
30 -def test():
31 arg = sys.argv[-1].lower() 32 if not arg in ('save','wiki','img','url','show','tags','unit'): 33 arg = 'url' 34 35 if arg == 'save': 36 if not os.path.isdir('tests'): 37 os.mkdir('tests') 38 for test in Test.all: 39 getattr(Test,test)().save(os.path.join(os.getcwd(),'tests',test)) 40 41 elif arg == 'unit': 42 suite = unittest.TestLoader().loadTestsFromTestCase(ChartsTest) 43 unittest.TextTestRunner(verbosity=2).run(suite) 44 45 elif arg == 'wiki': 46 links = [] 47 for n,test in enumerate(ordering): 48 testobj = getattr(Test,test) 49 G = testobj() 50 title = test.title().replace('_','-') 51 _print('----') 52 links.append(title) 53 _print('=== %s ==='%title) 54 _print('{{{') #'{{{\n#!python' 55 _print( '\n'.join(map(lambda x: x[8:], getsource(testobj).splitlines()[1:-1])) ) 56 _print('}}}') 57 #print '{{{\n#!html' 58 _print('%s&.png'%G) #G.img() 59 #print '}}}' 60 _print() 61 for link in links: 62 _print(' * [http://code.google.com/p/google-chartwrapper/wiki/ChartExamples#%s %s]'%(link,link)) 63 elif arg == 'tags': 64 _print("""{% load charts %} <table><tr> 65 <th> Advanced </th><td> 66 {% chart lc 4.0 93.0 42.0 48.8 70.0 99.0 encoding=text %} 67 {% scale 4 100 %} 68 {% axes type xy %} 69 {% axes label Mar Apr May June July %} 70 {% axes label None 50+K %} 71 {% color ff0000 %} 72 {% line 6 5 2 %} 73 {% img alt=DataScaling height=400 id=img title=DataSaling %} 74 {% size 400 200 %} 75 {% endchart %} </td></tr>""") 76 for test in Test.all: 77 # if test in ('multiline','axes_position','venn','guide_meter'): continue 78 _print('<tr><th>%s</th><td>'%test.title().replace('_','-')) 79 src = [] 80 for l in map(lambda x: x.strip(), getsource(getattr(Test,test)).splitlines()[1:-1]): 81 if l.startswith('#') or not l.strip(): 82 continue 83 elif l.startswith('G ='): 84 l = 'chart '+l.split('(')[0].split('G =')[1] +' ' + '('.join(l.split('(')[1:]) 85 86 rmlst = ['G.',']','[',"'"] # __setattr__ 87 splst = ["','",'(',')',','] # __call__ 88 for s in splst: 89 l = l.replace(s,' ') 90 for r in rmlst: 91 l = l.replace(r,'') 92 l = l.replace('axes.','axes ') 93 if l.find('encoding')==0: 94 l = l.replace('=',' ') 95 src.append('{% '+l+' %}') 96 src.append('{% endchart %}') 97 src = '\n'.join(src) 98 _print(src,'</td><td><pre>',src.replace('{','&#123;').replace('}','&#125;'),'</pre></td></tr>') 99 _print('</table>') 100 elif arg == 'img': 101 for test in Test.all: 102 _print(test,'\t',getattr(Test,test)().img()) 103 _print() 104 105 elif arg == 'url': 106 for test in ordering: 107 _print(test,'\t',getattr(Test,test)()) 108 _print() 109 110 elif arg == 'show': 111 for test in Test.all: 112 getattr(Test,test)().show()
113 114 if __name__=='__main__': 115 test() 116