diff --git a/.gitignore b/.gitignore
index 19d071c..b9f7d91 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@ dist
coverage-py*
junit-py*
docs/_build
+.cache
diff --git a/demo/moulinrouge/tests.py b/demo/moulinrouge/tests.py
index 955c36e..6927a95 100644
--- a/demo/moulinrouge/tests.py
+++ b/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')
diff --git a/docs/changelog.rst b/docs/changelog.rst
index d90a65c..ccc86ad 100644
--- a/docs/changelog.rst
+++ b/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
=====
diff --git a/docs/contributing.rst b/docs/contributing.rst
index 2843b6e..c1f3ca8 100644
--- a/docs/contributing.rst
+++ b/docs/contributing.rst
@@ -12,7 +12,7 @@ Submit your bug reports and feature requests to the `github bug tracker `_ please keep that in mind when writing code for pygal.
+The pygal code tries to respect the `pep8 `_ 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``.
diff --git a/perf.py b/perf.py
index 7f9a212..0a9fc2c 100644
--- a/perf.py
+++ b/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()
diff --git a/pygal/graph/base.py b/pygal/graph/base.py
index 8d8e80d..54add4e 100644
--- a/pygal/graph/base.py
+++ b/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),
diff --git a/pygal/graph/box.py b/pygal/graph/box.py
index 5ccc660..c7846d6 100644
--- a/pygal/graph/box.py
+++ b/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 = []
diff --git a/pygal/graph/graph.py b/pygal/graph/graph.py
index 6b74f1f..0997dcd 100644
--- a/pygal/graph/graph.py
+++ b/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):
diff --git a/pygal/graph/public.py b/pygal/graph/public.py
index c1dfbd2..7736a54 100644
--- a/pygal/graph/public.py
+++ b/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
diff --git a/pygal/state.py b/pygal/state.py
index 7633443..eafcc7a 100644
--- a/pygal/state.py
+++ b/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
diff --git a/pygal/svg.py b/pygal/svg.py
index 4323927..5b7b2ed 100644
--- a/pygal/svg.py
+++ b/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,
diff --git a/pygal/test/test_box.py b/pygal/test/test_box.py
index e247900..84c5ce3 100644
--- a/pygal/test/test_box.py
+++ b/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])
diff --git a/pygal/test/test_date.py b/pygal/test/test_date.py
index 97be33d..2a99215 100644
--- a/pygal/test/test_date.py
+++ b/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']
diff --git a/pygal/test/test_interpolate.py b/pygal/test/test_interpolate.py
index 0eec521..54481d7 100644
--- a/pygal/test/test_interpolate.py
+++ b/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'})
diff --git a/pygal/test/test_pie.py b/pygal/test/test_pie.py
index 69df384..f0e94a1 100644
--- a/pygal/test/test_pie.py
+++ b/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 .
-import os
-import uuid
from pygal import Pie
diff --git a/pygal/test/test_stacked.py b/pygal/test/test_stacked.py
index 7508b9c..74886ab 100644
--- a/pygal/test/test_stacked.py
+++ b/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():
diff --git a/pygal/test/test_style.py b/pygal/test/test_style.py
index 639044c..502e0d3 100644
--- a/pygal/test/test_style.py
+++ b/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'
\ No newline at end of file
diff --git a/pygal/test/test_util.py b/pygal/test/test_util.py
index 7ece4d8..53da1fc 100644
--- a/pygal/test/test_util.py
+++ b/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 .
-from datetime import time
from pygal._compat import u
from pygal.util import (
round_to_int, round_to_float, _swap_curly, template, humanize,
diff --git a/pygal/test/test_view.py b/pygal/test/test_view.py
index 35db0a2..e9a6dc5 100644
--- a/pygal/test/test_view.py
+++ b/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 .
-from pygal.test import make_data
-
def test_all_logarithmic(Chart):
chart = Chart(logarithmic=True)
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..7ce5bf0
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,5 @@
+[pytest]
+flake8-ignore =
+ pygal/__init__.py F401
+ pygal/_compat.py F821
+ docs/conf.py ALL
diff --git a/tox.ini b/tox.ini
index 3aa5da4..4e7dfb5 100644
--- a/tox.ini
+++ b/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