Browse Source

Add flake8 to tests. Fix style

pull/242/head
Florian Mounier 10 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/svg.py
  7. 4
      pygal/test/test_box.py
  8. 15
      pygal/test/test_date.py
  9. 1
      pygal/test/test_interpolate.py
  10. 2
      pygal/test/test_pie.py
  11. 2
      pygal/test/test_stacked.py
  12. 3
      pygal/test/test_style.py
  13. 1
      pygal/test/test_util.py
  14. 2
      pygal/test/test_view.py
  15. 5
      setup.cfg
  16. 3
      tox.ini

1
.gitignore vendored

@ -9,3 +9,4 @@ dist
coverage-py* coverage-py*
junit-py* junit-py*
docs/_build 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.colors import rotate
from pygal.graph.horizontal import HorizontalGraph from pygal.graph.horizontal import HorizontalGraph
from random import randint, choice from random import randint, choice
from datetime import datetime, date, time from datetime import datetime, date
def get_test_routes(app): def get_test_routes(app):
@ -369,9 +369,9 @@ def get_test_routes(app):
@app.route('/test/stacked') @app.route('/test/stacked')
def test_stacked(): def test_stacked():
stacked = StackedBar() stacked = StackedLine(stack_from_top=True, logarithmic=True)
stacked.add('1', [1, 2, 3]) stacked.add('1', [1, 2])
stacked.add('2', [4, 5, 6]) stacked.add('2', [10, 12])
return stacked.render_response() return stacked.render_response()
@app.route('/test/stacked/reverse') @app.route('/test/stacked/reverse')

1
docs/changelog.rst

@ -24,6 +24,7 @@ Changelog
* Transform min_scale and max_scale as options * Transform min_scale and max_scale as options
* mode option has been renamed to a less generic name: box_mode * mode option has been renamed to a less generic name: box_mode
* fix stack_from_top for stacked lines * fix stack_from_top for stacked lines
* Add flake8 test to py.test in tox
1.7.0 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 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 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 .. 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``. 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: if '--bench' in sys.argv:
bench = True bench = True
def prt(s): def prt(s):
pass pass
@ -49,6 +50,7 @@ if '--bench' in sys.argv:
sys.stdout.write(s) sys.stdout.write(s)
else: else:
bench = False bench = False
def prt(s): def prt(s):
sys.stdout.write(s) sys.stdout.write(s)
sys.stdout.flush() sys.stdout.flush()

4
pygal/svg.py

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

4
pygal/test/test_box.py

@ -129,8 +129,9 @@ def test_quartiles_tukey():
assert 75 in outliers assert 75 in outliers
assert 77 in outliers assert 77 in outliers
def test_quartiles_stdev(): def test_quartiles_stdev():
a = [35, 42, 35, 41, 36, 6, 12, 51, 33, 27, 46, 36, 44, 53, 75, 46, 16,\ 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] 51, 45, 29, 25, 26, 54, 61, 27, 40, 23, 34, 51, 37]
SD = 14.67 SD = 14.67
(min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points( (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(
@ -148,6 +149,7 @@ def test_quartiles_stdev():
assert min_s == q0 == q1 == q2 == q3 == q4 == max_s == b[0] assert min_s == q0 == q1 == q2 == q3 == q4 == max_s == b[0]
assert outliers == [] assert outliers == []
def test_simple_box(): def test_simple_box():
box = ghostedBox() box = ghostedBox()
box.add('test1', [-1, 2, 3, 3.1, 3.2, 4, 5]) box.add('test1', [-1, 2, 3, 3.1, 3.2, 4, 5])

15
pygal/test/test_date.py

@ -45,8 +45,7 @@ def test_date():
'2013-02-04', '2013-02-04',
'2013-02-09', '2013-02-09',
'2013-02-14', '2013-02-14',
'2013-02-18' '2013-02-18']
]
def test_time(): def test_time():
@ -68,8 +67,7 @@ def test_time():
'11:06:40', '11:06:40',
'13:53:20', '13:53:20',
'16:40:00', '16:40:00',
'19:26:40' '19:26:40']
]
def test_datetime(): def test_datetime():
@ -96,8 +94,7 @@ def test_datetime():
'2013-02-04T18:46:40', '2013-02-04T18:46:40',
'2013-02-09T09:53:20', '2013-02-09T09:53:20',
'2013-02-14T01:00:00', '2013-02-14T01:00:00',
'2013-02-18T16:06:40' '2013-02-18T16:06:40']
]
def test_timedelta(): def test_timedelta():
@ -118,8 +115,7 @@ def test_timedelta():
'3 days, 11:20:00', '3 days, 11:20:00',
'4 days, 15:06:40', '4 days, 15:06:40',
'5 days, 18:53:20', '5 days, 18:53:20',
'6 days, 22:40:00' '6 days, 22:40:00']
]
def test_date_xrange(): def test_date_xrange():
@ -142,5 +138,4 @@ def test_date_xrange():
'2013-01-24', '2013-01-24',
'2013-02-04', '2013-02-04',
'2013-02-16', '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) chart = make_data(chart, datas)
assert chart.render() assert chart.render()
def test_hermite_catmull_rom(Chart, datas): def test_hermite_catmull_rom(Chart, datas):
chart = Chart(interpolate='hermite', chart = Chart(interpolate='hermite',
interpolation_parameters={'type': 'catmull_rom'}) 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 # You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>. # along with pygal. If not, see <http://www.gnu.org/licenses/>.
import os
import uuid
from pygal import Pie 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]) stacked.add('ten_twelve', [10, 12])
q = stacked.render_pyquery() q = stacked.render_pyquery()
assert set(q("desc.value").text().split(' ')) == set( assert set(q("desc.value").text().split(' ')) == set(
('11', '14', '1', '2')) ('11', '14', '10', '12'))
def test_stacked_line_log(): def test_stacked_line_log():

3
pygal/test/test_style.py

@ -44,6 +44,7 @@ def test_parametric_styles_with_parameters():
line.x_labels = 'abc' line.x_labels = 'abc'
assert line.render() assert line.render()
def test_stroke_style(): def test_stroke_style():
s = Style(stroke_style='round') s = Style(stroke_style='round')
assert s.stroke_style == 'round' assert s.stroke_style == 'round'
@ -56,6 +57,7 @@ def test_stroke_style():
s = Style(stroke_style='invalid derp') s = Style(stroke_style='invalid derp')
assert s.stroke_style == 'round' assert s.stroke_style == 'round'
def test_stroke_dasharray(): def test_stroke_dasharray():
s = Style(stroke_dasharray=(0, 0)) s = Style(stroke_dasharray=(0, 0))
assert s.stroke_dasharray == '0,0' assert s.stroke_dasharray == '0,0'
@ -66,6 +68,7 @@ def test_stroke_dasharray():
s = Style(stroke_dasharray=(1.9, 1.9)) s = Style(stroke_dasharray=(1.9, 1.9))
assert s.stroke_dasharray == '1,1' assert s.stroke_dasharray == '1,1'
def test_stroke_dasharray_input_types(): def test_stroke_dasharray_input_types():
s = Style(stroke_dasharray=(0, 0)) s = Style(stroke_dasharray=(0, 0))
assert s.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 # You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>. # along with pygal. If not, see <http://www.gnu.org/licenses/>.
from datetime import time
from pygal._compat import u from pygal._compat import u
from pygal.util import ( from pygal.util import (
round_to_int, round_to_float, _swap_curly, template, humanize, 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 # You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>. # along with pygal. If not, see <http://www.gnu.org/licenses/>.
from pygal.test import make_data
def test_all_logarithmic(Chart): def test_all_logarithmic(Chart):
chart = Chart(logarithmic=True) 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] [testenv]
deps = deps =
pytest pytest
pytest-flake8
coverage coverage
lxml lxml
pyquery pyquery
@ -13,5 +14,5 @@ setenv =
COVERAGE_FILE=.cov-{envname} COVERAGE_FILE=.cov-{envname}
commands = 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 coverage xml -o coverage-{envname}.xml

Loading…
Cancel
Save