Browse Source

tests/testing now is importable, but still generates the samples when run

pull/8/head
Jason R. Coombs 14 years ago
parent
commit
1851447136
  1. 71
      tests/testing.py

71
tests/testing.py

@ -1,5 +1,12 @@
import sys, os
from svg.charts.plot import Plot
from svg.charts import bar
from svg.charts import time_series
from svg.charts import pie
from svg.charts import schedule
def sample_Plot():
g = Plot({
'min_x_value': 0,
'min_y_value': 0,
@ -11,13 +18,9 @@ g = Plot({
g.add_data({'data': [1, 25, 2, 30, 3, 45], 'title': 'series 1'})
g.add_data({'data': [1,30, 2, 31, 3, 40], 'title': 'series 2'})
g.add_data({'data': [.5,35, 1, 20, 3, 10.5], 'title': 'series 3'})
res = g.burn()
f = open(r'Plot.py.svg', 'w')
f.write(res)
f.close()
from svg.charts import time_series
return g
def sample_TimeSeries():
g = time_series.Plot({})
g.timescale_divisions = '4 hours'
@ -27,17 +30,24 @@ g.x_label_format = '%d-%b %H:%M'
g.add_data({'data': ['2005-12-21T00:00:00', 20, '2005-12-22T00:00:00', 21], 'title': 'series 1'})
res = g.burn()
return g
f = open(r'TimeSeries.py.svg', 'w')
f.write(res)
f.close()
def generate_samples():
yield 'Plot', sample_Plot()
yield 'TimeSeries', sample_TimeSeries()
yield 'VerticalBar', SampleBar.vertical()
yield 'HorizontalBar', SampleBar.horizontal()
yield 'VerticalBarLarge', SampleBar.vertical_large()
yield 'Pie', sample_Pie()
from svg.charts import bar
class SampleBar:
fields = ['Internet', 'TV', 'Newspaper', 'Magazine', 'Radio']
g = bar.VerticalBar(fields)
@classmethod
def vertical(cls):
g = bar.VerticalBar(cls.fields)
g.stack = 'side'
g.scale_integers = True
@ -48,9 +58,11 @@ g.show_graph_title = True
g.add_data({'data': [-2, 3, 1, 3, 1], 'title': 'Female'})
g.add_data({'data': [0, 2, 1, 5, 4], 'title': 'Male'})
open(r'VerticalBar.py.svg', 'w').write(g.burn())
return g
g = bar.HorizontalBar(fields)
@classmethod
def horizontal(cls):
g = bar.HorizontalBar(cls.fields)
g.stack = 'side'
g.scale_integers = True
@ -61,9 +73,11 @@ g.show_graph_title = True
g.add_data({'data': [-2, 3, 1, 3, 1], 'title': 'Female'})
g.add_data({'data': [0, 2, 1, 5, 4], 'title': 'Male'})
open(r'HorizontalBar.py.svg', 'w').write(g.burn())
return g
g = bar.VerticalBar(fields)
@classmethod
def vertical_large(cls):
g = bar.VerticalBar(cls.fields)
options = dict(
scale_integers=True,
stack='side',
@ -76,14 +90,14 @@ g.__dict__.update(options)
g.add_data(dict(data=[2,22,98,143,82], title='intermediate'))
g.add_data(dict(data=[2,26,106,193,105], title='old'))
open('VerticalBarLarge.py.svg', 'w').write(g.burn())
return g
from svg.charts import pie
def sample_Pie():
g = pie.Pie({})
options = dict(
width=640,
height=480,
fields=fields,
fields=SampleBar.fields,
graph_title='Question 7',
expand_greatest = True,
show_data_labels = True,
@ -91,11 +105,9 @@ options = dict(
g.__dict__.update(options)
g.add_data({'data': [-2, 3, 1, 3, 1], 'title': 'Female'})
g.add_data({'data': [0, 2, 1, 5, 4], 'title': 'Male'})
return g
open('Pie.py.svg', 'w').write(g.burn())
from svg.charts import schedule
def sample_Schedule():
title = "Billy's Schedule"
data1 = [
"History 107", "5/19/04", "6/30/04",
@ -130,4 +142,15 @@ g = schedule.Schedule(dict(
g.add_data(dict(data=data1, title="Data"))
f = open('Schedule.py.svg', 'w').write(g.burn())
return g
def save_samples():
root = os.path.dirname(__file__)
for sample_name, sample in generate_samples():
res = sample.burn()
with open(os.path.join(root, sample_name+'.py.svg'), 'w') as f:
f.write(res)
if __name__ == '__main__':
save_samples()

Loading…
Cancel
Save