Browse Source

Coverage again

pull/130/head
Florian Mounier 11 years ago
parent
commit
f7ed668a13
  1. 3
      pygal/graph/pie.py
  2. 17
      pygal/interpolate.py
  3. 7
      pygal/serie.py
  4. 19
      pygal/test/test_config.py
  5. 100
      pygal/test/test_interpolate.py
  6. 87
      pygal/test/test_map.py
  7. 1
      pygal/test/test_view.py

3
pygal/graph/pie.py

@ -77,9 +77,6 @@ class Pie(Graph):
def _plot(self):
total = sum(map(sum, map(lambda x: x.values, self.series)))
if total == 0:
return
current_angle = 0
for index, serie in enumerate(self.series):
angle = self.slice(

17
pygal/interpolate.py

@ -38,7 +38,7 @@ def quadratic_interpolate(x, y, precision=250, **kwargs):
for i in range(1, n):
b[i] = 2 * slope[i - 1] - b[i - 1]
c = [(slope[i] - b[i]) / delta_x[i] for i in range(n)]
c = [(slope[i] - b[i]) / delta_x[i] if delta_x[i] else 0 for i in range(n)]
for i in range(n + 1):
yield x[i], a[i]
@ -67,7 +67,7 @@ def cubic_interpolate(x, y, precision=250, **kwargs):
for i in range(1, n):
j = i - 1
l = 1 / (2 * (x[i + 1] - x[j]) - h[j] * m[j])
l = 1 / (2 * (x[i + 1] - x[j]) - h[j] * m[j]) if x[i + 1] - x[j] else 0
m[i] = h[i] * l
z[i] = (3 * (g[i] - g[j]) - h[j] * z[j]) * l
@ -102,7 +102,9 @@ def hermite_interpolate(x, y, precision=250,
for i in range(1, n):
m[i] = w[i] = .5 * (
(y[i + 1] - y[i]) / (x[i + 1] - x[i]) +
(y[i] - y[i - 1]) / (x[i] - x[i - 1]))
(y[i] - y[i - 1]) / (
x[i] - x[i - 1])
) if x[i + 1] - x[i] and x[i] - x[i - 1] else 0
elif type == 'kochanek_bartels':
c = c or 0
@ -118,7 +120,8 @@ def hermite_interpolate(x, y, precision=250,
c = c or 0
for i in range(1, n):
m[i] = w[i] = (1 - c) * (
y[i + 1] - y[i - 1]) / (x[i + 1] - x[i - 1])
y[i + 1] - y[i - 1]) / (
x[i + 1] - x[i - 1]) if x[i + 1] - x[i - 1] else 0
def p(i, x_):
t = (x_ - x[i]) / delta_x[i]
@ -160,7 +163,8 @@ def lagrange_interpolate(x, y, precision=250, **kwargs):
for m in range(n + 1):
if m == k:
continue
p *= (X - x[m]) / (x[k] - x[m])
if x[k] - x[m]:
p *= (X - x[m]) / (x[k] - x[m])
s += y[k] * p
yield X, s
@ -182,7 +186,8 @@ def trigonometric_interpolate(x, y, precision=250, **kwargs):
for m in range(n + 1):
if m == k:
continue
p *= sin(0.5 * (X - x[m])) / sin(0.5 * (x[k] - x[m]))
if sin(0.5 * (x[k] - x[m])):
p *= sin(0.5 * (X - x[m])) / sin(0.5 * (x[k] - x[m]))
s += y[k] * p
yield X, s

7
pygal/serie.py

@ -35,10 +35,3 @@ class Serie(object):
@cached_property
def safe_values(self):
return list(filter(lambda x: x is not None, self.values))
class Label(object):
"""A label with his position"""
def __init__(self, label, pos):
self.label = label
self.pos = pos

19
pygal/test/test_config.py

@ -360,7 +360,7 @@ def test_x_y_title(Chart):
def test_x_label_major(Chart):
if Chart in (
Pie, Radar, Funnel, Dot, Gauge, Worldmap,
Pie, Funnel, Dot, Gauge, Worldmap,
SupranationalWorldmap, Histogram, Box,
FrenchMap_Regions, FrenchMap_Departments,
Pyramid, DateY):
@ -404,7 +404,7 @@ def test_x_label_major(Chart):
def test_y_label_major(Chart):
if Chart in (
Pie, Radar, Funnel, Dot, Gauge, Worldmap,
Pie, Funnel, Dot, Gauge, Worldmap,
SupranationalWorldmap, Histogram, Box,
FrenchMap_Regions, FrenchMap_Departments,
HorizontalBar, HorizontalStackedBar,
@ -448,3 +448,18 @@ def test_y_label_major(Chart):
q = chart.render_pyquery()
assert len(q(".axis.y text.major")) == 12
assert len(q(".axis.y text")) == 12
def test_no_y_labels(Chart):
chart = Chart()
chart.y_labels = []
chart.add('_', [1, 2, 3])
chart.add('?', [10, 21, 5])
assert chart.render_pyquery()
def test_fill(Chart):
chart = Chart(fill=True)
chart.add('_', [1, 2, 3])
chart.add('?', [10, 21, 5])
assert chart.render_pyquery()

100
pygal/test/test_interpolate.py

@ -0,0 +1,100 @@
# -*- coding: utf-8 -*-
# This file is part of pygal
#
# A python svg graph plotting library
# Copyright © 2012-2014 Kozea
#
# This library is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# 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 pygal.test import pytest_generate_tests, make_data
def test_cubic(Chart, datas):
chart = Chart(interpolate='cubic')
chart = make_data(chart, datas)
assert chart.render()
def test_cubic_prec(Chart, datas):
chart = Chart(interpolate='cubic', interpolation_precision=200)
chart = make_data(chart, datas)
chart_low = Chart(interpolate='cubic', interpolation_precision=5)
chart_low = make_data(chart, datas)
assert len(chart.render()) >= len(chart_low.render())
def test_quadratic(Chart, datas):
chart = Chart(interpolate='quadratic')
chart = make_data(chart, datas)
assert chart.render()
def test_lagrange(Chart, datas):
chart = Chart(interpolate='lagrange')
chart = make_data(chart, datas)
assert chart.render()
def test_trigonometric(Chart, datas):
chart = Chart(interpolate='trigonometric')
chart = make_data(chart, datas)
assert chart.render()
def test_hermite(Chart, datas):
chart = Chart(interpolate='hermite')
chart = make_data(chart, datas)
assert chart.render()
def test_hermite_finite(Chart, datas):
chart = Chart(interpolate='hermite',
interpolation_parameters={'type': 'finite_difference'})
chart = make_data(chart, datas)
assert chart.render()
def test_hermite_cardinal(Chart, datas):
chart = Chart(interpolate='hermite',
interpolation_parameters={'type': 'cardinal', 'c': .75})
chart = make_data(chart, datas)
assert chart.render()
def test_hermite_catmull_rom(Chart, datas):
chart = Chart(interpolate='hermite',
interpolation_parameters={'type': 'catmull_rom'})
chart = make_data(chart, datas)
assert chart.render()
def test_hermite_kochanek_bartels(Chart, datas):
chart = Chart(interpolate='hermite',
interpolation_parameters={
'type': 'kochanek_bartels', 'b': -1, 'c': 1, 't': 1})
chart = make_data(chart, datas)
assert chart.render()
chart = Chart(interpolate='hermite',
interpolation_parameters={
'type': 'kochanek_bartels', 'b': -1, 'c': -8, 't': 0})
chart = make_data(chart, datas)
assert chart.render()
chart = Chart(interpolate='hermite',
interpolation_parameters={
'type': 'kochanek_bartels', 'b': 0, 'c': 10, 't': -1})
chart = make_data(chart, datas)
assert chart.render()

87
pygal/test/test_map.py

@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-
# This file is part of pygal
#
# A python svg graph plotting library
# Copyright © 2012-2014 Kozea
#
# This library is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# 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 pygal import (
Worldmap, SupranationalWorldmap)
from pygal.i18n import COUNTRIES, SUPRANATIONAL, set_countries
import operator
try:
from functools import reduce
except ImportError:
pass
_COUNTRIES = dict(COUNTRIES)
def test_worldmap():
set_countries(_COUNTRIES, True)
datas = {}
for i, ctry in enumerate(COUNTRIES):
datas[ctry] = i
wmap = Worldmap()
wmap.add('countries', datas)
q = wmap.render_pyquery()
assert len(
q('.country.color-0')
) == len(COUNTRIES)
assert 'France' in q('#fr').text()
def test_worldmap_i18n():
set_countries(_COUNTRIES, True)
datas = {}
for i, ctry in enumerate(COUNTRIES):
datas[ctry] = i
set_countries({'fr': 'Francia'})
wmap = Worldmap()
wmap.add('countries', datas)
q = wmap.render_pyquery()
assert len(
q('.country.color-0')
) == len(COUNTRIES)
assert 'Francia' in q('#fr').text()
def test_worldmap_i18n_clear():
set_countries(_COUNTRIES, True)
wmap = Worldmap()
wmap.add('countries', dict(fr=12))
set_countries({'fr': 'Frankreich'}, clear=True)
q = wmap.render_pyquery()
assert len(
q('.country.color-0')
) == 1
assert 'Frankreich' in q('#fr').text()
def test_supranationalworldmap():
set_countries(_COUNTRIES, True)
datas = {}
for i, supra in enumerate(SUPRANATIONAL):
datas[supra] = i + 1
wmap = SupranationalWorldmap()
wmap.add('supra', datas)
q = wmap.render_pyquery()
assert len(
q('.country.color-0')
) == len(
reduce(operator.or_, map(set, SUPRANATIONAL.values())))

1
pygal/test/test_view.py

@ -21,7 +21,6 @@ from pygal.test import pytest_generate_tests, make_data
def test_all_logarithmic(Chart):
print(repr(Chart))
chart = Chart(logarithmic=True)
chart.add('1', [1, 30, 8, 199, -23])
chart.add('2', [87, 42, .9, 189, 81])

Loading…
Cancel
Save