Browse Source

Add flake8 to tests. Fix style

pull/242/head
Florian Mounier 9 years ago
parent
commit
c4ee92106c
  1. 1
      .gitignore
  2. 8
      demo/moulinrouge/tests.py
  3. 1
      docs/changelog.rst
  4. 4
      docs/contributing.rst
  5. 2
      perf.py
  6. 4
      pygal/graph/base.py
  7. 2
      pygal/graph/box.py
  8. 8
      pygal/graph/graph.py
  9. 2
      pygal/graph/public.py
  10. 2
      pygal/state.py
  11. 4
      pygal/svg.py
  12. 8
      pygal/test/test_box.py
  13. 25
      pygal/test/test_date.py
  14. 1
      pygal/test/test_interpolate.py
  15. 2
      pygal/test/test_pie.py
  16. 2
      pygal/test/test_stacked.py
  17. 31
      pygal/test/test_style.py
  18. 1
      pygal/test/test_util.py
  19. 2
      pygal/test/test_view.py
  20. 5
      setup.cfg
  21. 3
      tox.ini

1
.gitignore vendored

@ -9,3 +9,4 @@ dist
coverage-py*
junit-py*
docs/_build
.cache

8
demo/moulinrouge/tests.py

@ -26,7 +26,7 @@ from pygal.style import styles, Style, RotateStyle
from pygal.colors import rotate
from pygal.graph.horizontal import HorizontalGraph
from random import randint, choice
from datetime import datetime, date, time
from datetime import datetime, date
def get_test_routes(app):
@ -369,9 +369,9 @@ def get_test_routes(app):
@app.route('/test/stacked')
def test_stacked():
stacked = StackedBar()
stacked.add('1', [1, 2, 3])
stacked.add('2', [4, 5, 6])
stacked = StackedLine(stack_from_top=True, logarithmic=True)
stacked.add('1', [1, 2])
stacked.add('2', [10, 12])
return stacked.render_response()
@app.route('/test/stacked/reverse')

1
docs/changelog.rst

@ -24,6 +24,7 @@ Changelog
* Transform min_scale and max_scale as options
* mode option has been renamed to a less generic name: box_mode
* fix stack_from_top for stacked lines
* Add flake8 test to py.test in tox
1.7.0
=====

4
docs/contributing.rst

@ -12,7 +12,7 @@ Submit your bug reports and feature requests to the `github bug tracker <http://
Code style
==========
The pygal code tries to respect the `pep8 <https://www.python.org/dev/peps/pep-0008/>`_ please keep that in mind when writing code for pygal.
The pygal code tries to respect the `pep8 <https://www.python.org/dev/peps/pep-0008/>`_ please keep that in mind when writing code for pygal. (The code style is checked along witht the unit tests, see next paragraph).
Testing
@ -25,7 +25,7 @@ To do this install ``py.test`` and them run ``py.test`` in the root of your pyga
.. code-block:: bash
[dev@dev pygal/]$ py.test
[dev@dev pygal/]$ py.test --flake8
Even better if you have several python versions installed you can run ``tox``.

2
perf.py

@ -42,6 +42,7 @@ def perf(chart_name, length, series):
if '--bench' in sys.argv:
bench = True
def prt(s):
pass
@ -49,6 +50,7 @@ if '--bench' in sys.argv:
sys.stdout.write(s)
else:
bench = False
def prt(s):
sys.stdout.write(s)
sys.stdout.flush()

4
pygal/graph/base.py

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# This file is part of pygal
#
# A python svg graph plotting library
@ -165,7 +165,7 @@ class BaseGraph(object):
values.append(value)
serie_config = SerieConfig()
serie_config(**dict((k, v) for k, v in self.state.__dict__.items()
if k in dir(serie_config)))
if k in dir(serie_config)))
serie_config(**serie_config_kwargs)
series.append(
Serie(offset + len(series),

2
pygal/graph/box.py

@ -231,7 +231,7 @@ class Box(Graph):
def pstdev(seq):
m = mean(seq)
l = len(seq)
v = sum((n - m)**2 for n in seq) / l # variance
v = sum((n - m)**2 for n in seq) / l # variance
return v**0.5 # sqrt
outliers = []

8
pygal/graph/graph.py

@ -635,8 +635,8 @@ class Graph(PublicApi):
"""Getter for the minimum series value"""
return (self.secondary_range[0] if (
self.secondary_range and self.secondary_range[0] is not None)
else (min(self._secondary_values)
if self._secondary_values else None))
else (min(self._secondary_values)
if self._secondary_values else None))
@cached_property
def _min(self):
@ -656,8 +656,8 @@ class Graph(PublicApi):
"""Getter for the maximum series value"""
return (self.secondary_range[1] if (
self.secondary_range and self.secondary_range[1] is not None)
else (max(self._secondary_values)
if self._secondary_values else None))
else (max(self._secondary_values)
if self._secondary_values else None))
@cached_property
def _order(self):

2
pygal/graph/public.py

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# This file is part of pygal
#
# A python svg graph plotting library

2
pygal/state.py

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# This file is part of pygal
#
# A python svg graph plotting library

4
pygal/svg.py

@ -228,8 +228,8 @@ class Svg(object):
line = ' '.join([coord_format(c)
for c in coords[origin_index + 1:]
if None not in c])
return self.node(node, 'path',
d=root % (origin, line), **kwargs)
return self.node(
node, 'path', d=root % (origin, line), **kwargs)
def slice(
self, serie_node, node, radius, small_radius,

8
pygal/test/test_box.py

@ -129,9 +129,10 @@ def test_quartiles_tukey():
assert 75 in outliers
assert 77 in outliers
def test_quartiles_stdev():
a = [35, 42, 35, 41, 36, 6, 12, 51, 33, 27, 46, 36, 44, 53, 75, 46, 16,\
51, 45, 29, 25, 26, 54, 61, 27, 40, 23, 34, 51, 37]
a = [35, 42, 35, 41, 36, 6, 12, 51, 33, 27, 46, 36, 44, 53, 75, 46, 16,
51, 45, 29, 25, 26, 54, 61, 27, 40, 23, 34, 51, 37]
SD = 14.67
(min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(
a, mode='stdev')
@ -142,12 +143,13 @@ def test_quartiles_stdev():
assert q0 >= q2 - SD
assert all(n in outliers for n in [6, 12, 16, 53, 54, 61, 75])
b = [5] # test for posible zero division
b = [5] # test for posible zero division
(min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(
b, mode='stdev')
assert min_s == q0 == q1 == q2 == q3 == q4 == max_s == b[0]
assert outliers == []
def test_simple_box():
box = ghostedBox()
box.add('test1', [-1, 2, 3, 3.1, 3.2, 4, 5])

25
pygal/test/test_date.py

@ -45,8 +45,7 @@ def test_date():
'2013-02-04',
'2013-02-09',
'2013-02-14',
'2013-02-18'
]
'2013-02-18']
def test_time():
@ -68,8 +67,7 @@ def test_time():
'11:06:40',
'13:53:20',
'16:40:00',
'19:26:40'
]
'19:26:40']
def test_datetime():
@ -96,8 +94,7 @@ def test_datetime():
'2013-02-04T18:46:40',
'2013-02-09T09:53:20',
'2013-02-14T01:00:00',
'2013-02-18T16:06:40'
]
'2013-02-18T16:06:40']
def test_timedelta():
@ -113,13 +110,12 @@ def test_timedelta():
assert list(
t for t in q(".axis.x text").map(texts) if t != '0:00:00'
) == [
'1 day, 3:46:40',
'2 days, 7:33:20',
'3 days, 11:20:00',
'4 days, 15:06:40',
'5 days, 18:53:20',
'6 days, 22:40:00'
]
'1 day, 3:46:40',
'2 days, 7:33:20',
'3 days, 11:20:00',
'4 days, 15:06:40',
'5 days, 18:53:20',
'6 days, 22:40:00']
def test_date_xrange():
@ -142,5 +138,4 @@ def test_date_xrange():
'2013-01-24',
'2013-02-04',
'2013-02-16',
'2013-02-27'
]
'2013-02-27']

1
pygal/test/test_interpolate.py

@ -73,6 +73,7 @@ def test_hermite_cardinal(Chart, datas):
chart = make_data(chart, datas)
assert chart.render()
def test_hermite_catmull_rom(Chart, datas):
chart = Chart(interpolate='hermite',
interpolation_parameters={'type': 'catmull_rom'})

2
pygal/test/test_pie.py

@ -16,8 +16,6 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>.
import os
import uuid
from pygal import Pie

2
pygal/test/test_stacked.py

@ -34,7 +34,7 @@ def test_stacked_line_reverse():
stacked.add('ten_twelve', [10, 12])
q = stacked.render_pyquery()
assert set(q("desc.value").text().split(' ')) == set(
('11', '14', '1', '2'))
('11', '14', '10', '12'))
def test_stacked_line_log():

31
pygal/test/test_style.py

@ -44,34 +44,37 @@ def test_parametric_styles_with_parameters():
line.x_labels = 'abc'
assert line.render()
def test_stroke_style():
s = Style(stroke_style = 'round')
s = Style(stroke_style='round')
assert s.stroke_style == 'round'
s = Style(stroke_style = 'bevel')
s = Style(stroke_style='bevel')
assert s.stroke_style == 'bevel'
s = Style(stroke_style = 'miter')
s = Style(stroke_style='miter')
assert s.stroke_style == 'miter'
s = Style(stroke_style = 'rounded')
s = Style(stroke_style='rounded')
assert s.stroke_style == 'round'
s = Style(stroke_style = 'invalid derp')
s = Style(stroke_style='invalid derp')
assert s.stroke_style == 'round'
def test_stroke_dasharray():
s = Style(stroke_dasharray = (0,0))
s = Style(stroke_dasharray=(0, 0))
assert s.stroke_dasharray == '0,0'
s = Style(stroke_dasharray = (.5,.5))
s = Style(stroke_dasharray=(.5, .5))
assert s.stroke_dasharray == '0,0'
s = Style(stroke_dasharray = (.9,.9))
s = Style(stroke_dasharray=(.9, .9))
assert s.stroke_dasharray == '0,0'
s = Style(stroke_dasharray = (1.9,1.9))
s = Style(stroke_dasharray=(1.9, 1.9))
assert s.stroke_dasharray == '1,1'
def test_stroke_dasharray_input_types():
s = Style(stroke_dasharray = (0,0))
s = Style(stroke_dasharray=(0, 0))
assert s.stroke_dasharray == '0,0'
s = Style(stroke_dasharray='0,0')
assert s.stroke_dasharray == '0,0'
s = Style(stroke_dasharray = '0,0')
s = Style(stroke_dasharray='0x0')
assert s.stroke_dasharray == '0,0'
s = Style(stroke_dasharray = '0x0')
s = Style(stroke_dasharray='0 0')
assert s.stroke_dasharray == '0,0'
s = Style(stroke_dasharray = '0 0')
assert s.stroke_dasharray == '0,0'

1
pygal/test/test_util.py

@ -16,7 +16,6 @@
#
# 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 datetime import time
from pygal._compat import u
from pygal.util import (
round_to_int, round_to_float, _swap_curly, template, humanize,

2
pygal/test/test_view.py

@ -17,8 +17,6 @@
# 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 make_data
def test_all_logarithmic(Chart):
chart = Chart(logarithmic=True)

5
setup.cfg

@ -0,0 +1,5 @@
[pytest]
flake8-ignore =
pygal/__init__.py F401
pygal/_compat.py F821
docs/conf.py ALL

3
tox.ini

@ -4,6 +4,7 @@ envlist = py26,py27,py32,py33,py34,pypy
[testenv]
deps =
pytest
pytest-flake8
coverage
lxml
pyquery
@ -13,5 +14,5 @@ setenv =
COVERAGE_FILE=.cov-{envname}
commands =
coverage run --source=pygal {envbindir}/py.test pygal/test --junitxml=junit-{envname}.xml
coverage run --source=pygal {envbindir}/py.test pygal/test --junitxml=junit-{envname}.xml --flake8
coverage xml -o coverage-{envname}.xml

Loading…
Cancel
Save