Browse Source

Add some simple tests in moulin rouge

pull/8/head
Florian Mounier 12 years ago
parent
commit
05b4974219
  1. 35
      demo/moulinrouge.py
  2. 18
      demo/moulinrouge/__init__.py
  3. 7
      demo/moulinrouge/templates/index.jinja2
  4. 92
      demo/moulinrouge/tests.py

35
demo/moulinrouge.py

@ -18,8 +18,37 @@
# You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>.
from moulinrouge import create_app
import logging
app = create_app()
if __name__ == "__main__":
app.run(debug=True, threaded=True, host='0.0.0.0', port=21112)
try:
from log_colorizer import make_colored_stream_handler
handler = make_colored_stream_handler()
app.logger.handlers = []
app.logger.addHandler(handler)
import werkzeug
werkzeug._internal._log('debug', '<-- I am with stupid')
logging.getLogger('werkzeug').handlers = []
logging.getLogger('werkzeug').addHandler(handler)
handler.setLevel(logging.DEBUG)
app.logger.setLevel(logging.DEBUG)
logging.getLogger('werkzeug').setLevel(logging.DEBUG)
except:
pass
try:
import wsreload
except ImportError:
app.logger.debug('wsreload not found')
else:
url = "http://moulinrouge.l:21112/*"
def log(httpserver):
app.logger.debug('WSReloaded after server restart')
wsreload.monkey_patch_http_server({'url': url}, callback=log)
app.logger.debug('HTTPServer monkey patched for url %s' % url)
app.run(debug=True, threaded=True, host='0.0.0.0', port=21112)

18
demo/moulinrouge/__init__.py

@ -46,17 +46,6 @@ def create_app():
"""Creates the pygal test web app"""
app = Flask(__name__)
try:
from log_colorizer import make_colored_stream_handler
handler = make_colored_stream_handler()
except ImportError:
from logging import StreamHandler
handler = StreamHandler()
getLogger('werkzeug').addHandler(handler)
getLogger('werkzeug').setLevel(INFO)
getLogger('pygal').addHandler(handler)
getLogger('pygal').setLevel(DEBUG)
def _random(data, order):
max = 10 ** order
@ -90,9 +79,12 @@ def create_app():
series.append((random_label(), values))
return series
from .tests import get_test_routes
links = get_test_routes(app)
@app.route("/")
def index():
return render_template('index.jinja2', styles=styles)
return render_template('index.jinja2', styles=styles, links=links)
@app.route("/svg/<type>/<series>/<config>")
def svg(type, series, config):
@ -187,5 +179,5 @@ def create_app():
svgs=svgs,
width=width,
height=height)
return app

7
demo/moulinrouge/templates/index.jinja2

@ -9,4 +9,11 @@
</dl>
<a href="{{ url_for('interpolation') }}">Interpolation</a>
<a href="{{ url_for('rotation') }}">Rotations test</a>
<hr />
<h3>Quick tests</h3>
<dl>
{% for link in links %}
<dd><a href="{{ url_for(link) }}">{{ link.replace('test_', '').replace('_', ' ') | title }}</a></dd>
{% endfor %}
</dl>
{% endblock section %}

92
demo/moulinrouge/tests.py

@ -0,0 +1,92 @@
# -*- coding: utf-8 -*-
# This file is part of pygal
import pygal
from pygal import Bar, Gauge, Pyramid, Funnel, Dot
from pygal.style import styles
def get_test_routes(app):
lnk = lambda v, l=None: {'value': v, 'xlink': 'javascript:alert("Test %s")' % v, 'label': l}
@app.route('/test/unsorted')
def test_unsorted():
bar = Bar(style=styles['neon'])
bar.add('A', {'red': 10, 'green': 12, 'blue': 14})
bar.add('B', {'green': 11, 'blue': 7})
bar.add('C', {'blue': 7})
bar.add('D', {})
bar.add('E', {'blue': 2, 'red': 13})
bar.x_labels = ('red', 'green', 'blue')
return bar.render_response()
@app.route('/test/bar_links')
def test_bar_links():
bar = Bar(style=styles['neon'])
bar.add('1234', [
{'value': 10,
'label': 'Ten',
'xlink': 'http://google.com?q=10'},
{'value': 20,
'label': 'Twenty',
'xlink': 'http://google.com?q=20'},
30,
{'value': 40,
'label': 'Forty',
'xlink': 'http://google.com?q=40'}
])
bar.add('4321', [40, {
'value': 30,
'label': 'Thirty',
'xlink': 'http://google.com?q=30'
}, 20, 10])
bar.x_labels = map(str, range(1, 5))
bar.logarithmic = True
bar.zero = 1
return bar.render_response()
@app.route('/test/gauge')
def test_gauge():
gauge = Gauge()
gauge.range = [-10, 10]
gauge.add('Need l', [2.3, 5.12])
gauge.add('No', [99, -99])
return gauge.render_response()
@app.route('/test/gauge')
def test_pyramid():
pyramid = Pyramid()
pyramid.x_labels = ['0-25', '25-45', '45-65', '65+']
pyramid.add('Man single', [2, 4, 2, 1])
pyramid.add('Woman single', [10, 6, 1, 1])
pyramid.add('Man maried', [10, 3, 4, 2])
pyramid.add('Woman maried', [3, 3, 5, 3])
return pyramid.render_response()
@app.route('/test/funnel')
def test_funnel():
funnel = Funnel()
funnel.add('1', [1, 2, 3])
funnel.add('3', [3, 4, 5])
funnel.add('6', [6, 5, 4])
funnel.add('12', [12, 2, 9])
return funnel.render_response()
@app.route('/test/dot')
def test_dot():
dot = Dot()
dot.x_labels = map(str, range(4))
dot.add('a', [1, lnk(3, 'Foo'), 5, 3])
dot.add('b', [2, 2, 0, 2])
dot.add('c', [5, 1, 5, lnk(3, 'Bar')])
dot.add('d', [5, 5, lnk(0, 'Babar'), 3])
return dot.render_response()
return filter(lambda x: x.startswith('test'), locals())
Loading…
Cancel
Save