From d5894c2a9dfa60e275a5048a06b565c34b7f77ef Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Wed, 15 Jul 2015 11:18:50 +0200 Subject: [PATCH] Document all tests --- pygal/test/__init__.py | 12 +++--- pygal/test/conftest.py | 4 ++ pygal/test/test_bar.py | 4 ++ pygal/test/test_box.py | 11 +++++- pygal/test/test_colors.py | 66 +++++++++++++++++++++++++++++++++ pygal/test/test_config.py | 29 +++++++++++++++ pygal/test/test_date.py | 8 ++++ pygal/test/test_donut.py | 60 ------------------------------ pygal/test/test_graph.py | 29 +++++++++++++++ pygal/test/test_histogram.py | 4 ++ pygal/test/test_interpolate.py | 12 ++++++ pygal/test/test_line.py | 14 +++++++ pygal/test/test_maps.py | 21 +++++++++++ pygal/test/test_pie.py | 6 +++ pygal/test/test_serie_config.py | 19 ++++++++-- pygal/test/test_sparktext.py | 15 +++++++- pygal/test/test_stacked.py | 7 ++++ pygal/test/test_style.py | 5 +++ pygal/test/test_table.py | 4 ++ pygal/test/test_util.py | 13 ++++++- pygal/test/test_view.py | 6 +++ pygal/test/test_xml_filters.py | 10 +++++ pygal/test/utils.py | 4 ++ 23 files changed, 289 insertions(+), 74 deletions(-) delete mode 100644 pygal/test/test_donut.py diff --git a/pygal/test/__init__.py b/pygal/test/__init__.py index 11b75ed..fc0ac30 100644 --- a/pygal/test/__init__.py +++ b/pygal/test/__init__.py @@ -17,6 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . +"""Pygal test package""" + import pygal from pygal.util import cut from pygal.graph.map import BaseMap @@ -24,6 +26,7 @@ from decimal import Decimal def get_data(i): + """Return sample test data for an index""" return [ [(-1, 1), (2, 0), (0, 4)], [(0, 1), (None, 2), (3, 2)], @@ -33,13 +36,7 @@ def get_data(i): def adapt(chart, data): - # if isinstance(chart, pygal.DateY): - # # Convert to a credible datetime - # return list(map( - # lambda t: - # (datetime.fromtimestamp(1360000000 + t[0] * 987654) - # if t[0] is not None else None, t[1]), data)) - + """Adapt data to chart type""" if isinstance(chart, pygal.XY): return data @@ -53,6 +50,7 @@ def adapt(chart, data): def make_data(chart, datas): + """Add sample data to the test chart""" for i, data in enumerate(datas): chart.add(data[0], adapt(chart, data[1]), diff --git a/pygal/test/conftest.py b/pygal/test/conftest.py index ddb0136..4ea113b 100644 --- a/pygal/test/conftest.py +++ b/pygal/test/conftest.py @@ -17,6 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . +"""pytest fixtures""" + import pytest import pygal from pygal.etree import etree @@ -26,6 +28,7 @@ from . import get_data @pytest.fixture def etreefx(request): + """Fixture allowing to test with builtin etree and lxml""" if request.param == 'etree': etree.to_etree() if request.param == 'lxml': @@ -33,6 +36,7 @@ def etreefx(request): def pytest_generate_tests(metafunc): + """Generate the tests for etree and lxml""" if etree._lxml_etree and sys.version_info[:2] != (2, 6): metafunc.fixturenames.append('etreefx') metafunc.parametrize('etreefx', ['lxml', 'etree'], indirect=True) diff --git a/pygal/test/test_bar.py b/pygal/test/test_bar.py index 7907d68..dfc24ea 100644 --- a/pygal/test/test_bar.py +++ b/pygal/test/test_bar.py @@ -16,10 +16,14 @@ # # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . + +"""Bar chart related tests""" + from pygal import Bar def test_simple_bar(): + """Simple bar test""" bar = Bar() rng = [-3, -32, -39] bar.add('test1', rng) diff --git a/pygal/test/test_box.py b/pygal/test/test_box.py index 84c5ce3..b2976db 100644 --- a/pygal/test/test_box.py +++ b/pygal/test/test_box.py @@ -16,11 +16,14 @@ # # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . + +"""Box chart related tests""" + from pygal.graph.box import Box -from pygal import Box as ghostedBox def test_quartiles(): + """Test box points for the 1.5IQR computation method""" a = [-2.0, 3.0, 4.0, 5.0, 8.0] # odd test data (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points( a, mode='1.5IQR') @@ -55,6 +58,7 @@ def test_quartiles(): def test_quartiles_min_extremes(): + """Test box points for the extremes computation method""" a = [-2.0, 3.0, 4.0, 5.0, 8.0] # odd test data (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points( a, mode='extremes') @@ -89,6 +93,7 @@ def test_quartiles_min_extremes(): def test_quartiles_tukey(): + """Test box points for the tukey computation method""" a = [] # empty data (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points( a, mode='tukey') @@ -131,6 +136,7 @@ def test_quartiles_tukey(): def test_quartiles_stdev(): + """Test box points for the stdev computation method""" 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 @@ -151,7 +157,8 @@ def test_quartiles_stdev(): def test_simple_box(): - box = ghostedBox() + """Simple box test""" + box = Box() box.add('test1', [-1, 2, 3, 3.1, 3.2, 4, 5]) box.add('test2', [2, 3, 5, 6, 6, 4]) box.title = 'Box test' diff --git a/pygal/test/test_colors.py b/pygal/test/test_colors.py index 2ef9bf3..22b3edf 100644 --- a/pygal/test/test_colors.py +++ b/pygal/test/test_colors.py @@ -1,3 +1,24 @@ +# -*- coding: utf-8 -*- +# This file is part of pygal +# +# A python svg graph plotting library +# Copyright © 2012-2015 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 . + +"""Color utility functions tests""" + from __future__ import division from pygal.colors import ( @@ -6,6 +27,7 @@ from pygal.colors import ( def test_parse_color(): + """Test color parse function""" assert parse_color('#123') == (17, 34, 51, 1., '#rgb') assert parse_color('#cdf') == (204, 221, 255, 1., '#rgb') assert parse_color('#a3d7') == (170, 51, 221, 119 / 255, '#rgba') @@ -19,6 +41,7 @@ def test_parse_color(): def test_unparse_color(): + """Test color unparse function""" assert unparse_color(17, 34, 51, 1., '#rgb') == '#123' assert unparse_color(204, 221, 255, 1., '#rgb') == '#cdf' assert unparse_color(170, 51, 221, 119 / 255, '#rgba') == '#a3d7' @@ -32,6 +55,7 @@ def test_unparse_color(): def test_darken(): + """Test darken color function""" assert darken('#800', 20) == '#200' assert darken('#800e', 20) == '#200e' assert darken('#800', 0) == '#800' @@ -48,6 +72,7 @@ def test_darken(): def test_lighten(): + """Test lighten color function""" assert lighten('#800', 20) == '#e00' assert lighten('#800', 0) == '#800' assert lighten('#ffffff', 10) == '#ffffff' @@ -59,6 +84,7 @@ def test_lighten(): def test_saturate(): + """Test color saturation function""" assert saturate('#000', 20) == '#000' assert saturate('#fff', 20) == '#fff' assert saturate('#8a8', 100) == '#3f3' @@ -66,6 +92,7 @@ def test_saturate(): def test_desaturate(): + """Test color desaturation function""" assert desaturate('#000', 20) == '#000' assert desaturate('#fff', 20) == '#fff' assert desaturate('#8a8', 100) == '#999' @@ -73,6 +100,7 @@ def test_desaturate(): def test_rotate(): + """Test color rotation function""" assert rotate('#000', 45) == '#000' assert rotate('#fff', 45) == '#fff' assert rotate('#811', 45) == '#886a11' @@ -82,6 +110,7 @@ def test_rotate(): def test_hsl_to_rgb_part_0(): + """Test hsl to rgb color function""" assert hsl_to_rgb(0, 100, 50) == (255, 0, 0) assert hsl_to_rgb(60, 100, 50) == (255, 255, 0) assert hsl_to_rgb(120, 100, 50) == (0, 255, 0) @@ -91,6 +120,7 @@ def test_hsl_to_rgb_part_0(): def test_rgb_to_hsl_part_0(): + """Test rgb to hsl color function""" assert rgb_to_hsl(255, 0, 0) == (0, 100, 50) assert rgb_to_hsl(255, 255, 0) == (60, 100, 50) assert rgb_to_hsl(0, 255, 0) == (120, 100, 50) @@ -100,6 +130,7 @@ def test_rgb_to_hsl_part_0(): def test_hsl_to_rgb_part_1(): + """Test hsl to rgb color function""" assert hsl_to_rgb(-360, 100, 50) == (255, 0, 0) assert hsl_to_rgb(-300, 100, 50) == (255, 255, 0) assert hsl_to_rgb(-240, 100, 50) == (0, 255, 0) @@ -109,6 +140,7 @@ def test_hsl_to_rgb_part_1(): def test_rgb_to_hsl_part_1(): + """Test rgb to hsl color function""" # assert rgb_to_hsl(255, 0, 0) == (-360, 100, 50) # assert rgb_to_hsl(255, 255, 0) == (-300, 100, 50) # assert rgb_to_hsl(0, 255, 0) == (-240, 100, 50) @@ -119,6 +151,7 @@ def test_rgb_to_hsl_part_1(): def test_hsl_to_rgb_part_2(): + """Test hsl to rgb color function""" assert hsl_to_rgb(360, 100, 50) == (255, 0, 0) assert hsl_to_rgb(420, 100, 50) == (255, 255, 0) assert hsl_to_rgb(480, 100, 50) == (0, 255, 0) @@ -128,6 +161,7 @@ def test_hsl_to_rgb_part_2(): def test_rgb_to_hsl_part_2(): + """Test rgb to hsl color function""" # assert rgb_to_hsl(255, 0, 0) == (360, 100, 50) # assert rgb_to_hsl(255, 255, 0) == (420, 100, 50) # assert rgb_to_hsl(0, 255, 0) == (480, 100, 50) @@ -138,6 +172,7 @@ def test_rgb_to_hsl_part_2(): def test_hsl_to_rgb_part_3(): + """Test hsl to rgb color function""" assert hsl_to_rgb(6120, 100, 50) == (255, 0, 0) assert hsl_to_rgb(-9660, 100, 50) == (255, 255, 0) assert hsl_to_rgb(99840, 100, 50) == (0, 255, 0) @@ -147,6 +182,7 @@ def test_hsl_to_rgb_part_3(): def test_rgb_to_hsl_part_3(): + """Test rgb to hsl color function""" # assert rgb_to_hsl(255, 0, 0) == (6120, 100, 50) # assert rgb_to_hsl(255, 255, 0) == (-9660, 100, 50) # assert rgb_to_hsl(0, 255, 0) == (99840, 100, 50) @@ -157,6 +193,7 @@ def test_rgb_to_hsl_part_3(): def test_hsl_to_rgb_part_4(): + """Test hsl to rgb color function""" assert hsl_to_rgb(0, 100, 50) == (255, 0, 0) assert hsl_to_rgb(12, 100, 50) == (255, 51, 0) assert hsl_to_rgb(24, 100, 50) == (255, 102, 0) @@ -171,6 +208,7 @@ def test_hsl_to_rgb_part_4(): def test_rgb_to_hsl_part_4(): + """Test rgb to hsl color function""" assert rgb_to_hsl(255, 0, 0) == (0, 100, 50) assert rgb_to_hsl(255, 51, 0) == (12, 100, 50) assert rgb_to_hsl(255, 102, 0) == (24, 100, 50) @@ -185,6 +223,7 @@ def test_rgb_to_hsl_part_4(): def test_hsl_to_rgb_part_5(): + """Test hsl to rgb color function""" assert hsl_to_rgb(120, 100, 50) == (0, 255, 0) assert hsl_to_rgb(132, 100, 50) == (0, 255, 51) assert hsl_to_rgb(144, 100, 50) == (0, 255, 102) @@ -199,6 +238,7 @@ def test_hsl_to_rgb_part_5(): def test_rgb_to_hsl_part_5(): + """Test rgb to hsl color function""" assert rgb_to_hsl(0, 255, 0) == (120, 100, 50) assert rgb_to_hsl(0, 255, 51) == (132, 100, 50) assert rgb_to_hsl(0, 255, 102) == (144, 100, 50) @@ -213,6 +253,7 @@ def test_rgb_to_hsl_part_5(): def test_hsl_to_rgb_part_6(): + """Test hsl to rgb color function""" assert hsl_to_rgb(240, 100, 50) == (0, 0, 255) assert hsl_to_rgb(252, 100, 50) == (51, 0, 255) assert hsl_to_rgb(264, 100, 50) == (102, 0, 255) @@ -227,6 +268,7 @@ def test_hsl_to_rgb_part_6(): def test_rgb_to_hsl_part_6(): + """Test rgb to hsl color function""" assert rgb_to_hsl(0, 0, 255) == (240, 100, 50) assert rgb_to_hsl(51, 0, 255) == (252, 100, 50) assert rgb_to_hsl(102, 0, 255) == (264, 100, 50) @@ -241,78 +283,91 @@ def test_rgb_to_hsl_part_6(): def test_hsl_to_rgb_part_7(): + """Test hsl to rgb color function""" assert hsl_to_rgb(0, 20, 50) == (153, 102, 102) assert hsl_to_rgb(0, 60, 50) == (204, 51, 51) assert hsl_to_rgb(0, 100, 50) == (255, 0, 0) def test_rgb_to_hsl_part_7(): + """Test rgb to hsl color function""" assert rgb_to_hsl(153, 102, 102) == (0, 20, 50) assert rgb_to_hsl(204, 51, 51) == (0, 60, 50) assert rgb_to_hsl(255, 0, 0) == (0, 100, 50) def test_hsl_to_rgb_part_8(): + """Test hsl to rgb color function""" assert hsl_to_rgb(60, 20, 50) == (153, 153, 102) assert hsl_to_rgb(60, 60, 50) == (204, 204, 51) assert hsl_to_rgb(60, 100, 50) == (255, 255, 0) def test_rgb_to_hsl_part_8(): + """Test rgb to hsl color function""" assert rgb_to_hsl(153, 153, 102) == (60, 20, 50) assert rgb_to_hsl(204, 204, 51) == (60, 60, 50) assert rgb_to_hsl(255, 255, 0) == (60, 100, 50) def test_hsl_to_rgb_part_9(): + """Test hsl to rgb color function""" assert hsl_to_rgb(120, 20, 50) == (102, 153, 102) assert hsl_to_rgb(120, 60, 50) == (51, 204, 51) assert hsl_to_rgb(120, 100, 50) == (0, 255, 0) def test_rgb_to_hsl_part_9(): + """Test rgb to hsl color function""" assert rgb_to_hsl(102, 153, 102) == (120, 20, 50) assert rgb_to_hsl(51, 204, 51) == (120, 60, 50) assert rgb_to_hsl(0, 255, 0) == (120, 100, 50) def test_hsl_to_rgb_part_10(): + """Test hsl to rgb color function""" assert hsl_to_rgb(180, 20, 50) == (102, 153, 153) assert hsl_to_rgb(180, 60, 50) == (51, 204, 204) assert hsl_to_rgb(180, 100, 50) == (0, 255, 255) def test_rgb_to_hsl_part_10(): + """Test rgb to hsl color function""" assert rgb_to_hsl(102, 153, 153) == (180, 20, 50) assert rgb_to_hsl(51, 204, 204) == (180, 60, 50) assert rgb_to_hsl(0, 255, 255) == (180, 100, 50) def test_hsl_to_rgb_part_11(): + """Test hsl to rgb color function""" assert hsl_to_rgb(240, 20, 50) == (102, 102, 153) assert hsl_to_rgb(240, 60, 50) == (51, 51, 204) assert hsl_to_rgb(240, 100, 50) == (0, 0, 255) def test_rgb_to_hsl_part_11(): + """Test rgb to hsl color function""" assert rgb_to_hsl(102, 102, 153) == (240, 20, 50) assert rgb_to_hsl(51, 51, 204) == (240, 60, 50) assert rgb_to_hsl(0, 0, 255) == (240, 100, 50) def test_hsl_to_rgb_part_12(): + """Test hsl to rgb color function""" assert hsl_to_rgb(300, 20, 50) == (153, 102, 153) assert hsl_to_rgb(300, 60, 50) == (204, 51, 204) assert hsl_to_rgb(300, 100, 50) == (255, 0, 255) def test_rgb_to_hsl_part_12(): + """Test rgb to hsl color function""" assert rgb_to_hsl(153, 102, 153) == (300, 20, 50) assert rgb_to_hsl(204, 51, 204) == (300, 60, 50) assert rgb_to_hsl(255, 0, 255) == (300, 100, 50) def test_hsl_to_rgb_part_13(): + """Test hsl to rgb color function""" assert hsl_to_rgb(0, 100, 0) == (0, 0, 0) assert hsl_to_rgb(0, 100, 10) == (51, 0, 0) assert hsl_to_rgb(0, 100, 20) == (102, 0, 0) @@ -327,6 +382,7 @@ def test_hsl_to_rgb_part_13(): def test_rgb_to_hsl_part_13(): + """Test rgb to hsl color function""" assert rgb_to_hsl(0, 0, 0) == (0, 0, 0) assert rgb_to_hsl(51, 0, 0) == (0, 100, 10) assert rgb_to_hsl(102, 0, 0) == (0, 100, 20) @@ -341,6 +397,7 @@ def test_rgb_to_hsl_part_13(): def test_hsl_to_rgb_part_14(): + """Test hsl to rgb color function""" assert hsl_to_rgb(60, 100, 0) == (0, 0, 0) assert hsl_to_rgb(60, 100, 10) == (51, 51, 0) assert hsl_to_rgb(60, 100, 20) == (102, 102, 0) @@ -355,6 +412,7 @@ def test_hsl_to_rgb_part_14(): def test_rgb_to_hsl_part_14(): + """Test rgb to hsl color function""" # assert rgb_to_hsl(0, 0, 0) == (60, 100, 0) assert rgb_to_hsl(51, 51, 0) == (60, 100, 10) assert rgb_to_hsl(102, 102, 0) == (60, 100, 20) @@ -369,6 +427,7 @@ def test_rgb_to_hsl_part_14(): def test_hsl_to_rgb_part_15(): + """Test hsl to rgb color function""" assert hsl_to_rgb(120, 100, 0) == (0, 0, 0) assert hsl_to_rgb(120, 100, 10) == (0, 51, 0) assert hsl_to_rgb(120, 100, 20) == (0, 102, 0) @@ -383,6 +442,7 @@ def test_hsl_to_rgb_part_15(): def test_rgb_to_hsl_part_15(): + """Test rgb to hsl color function""" # assert rgb_to_hsl(0, 0, 0) == (120, 100, 0) assert rgb_to_hsl(0, 51, 0) == (120, 100, 10) assert rgb_to_hsl(0, 102, 0) == (120, 100, 20) @@ -397,6 +457,7 @@ def test_rgb_to_hsl_part_15(): def test_hsl_to_rgb_part_16(): + """Test hsl to rgb color function""" assert hsl_to_rgb(180, 100, 0) == (0, 0, 0) assert hsl_to_rgb(180, 100, 10) == (0, 51, 51) assert hsl_to_rgb(180, 100, 20) == (0, 102, 102) @@ -411,6 +472,7 @@ def test_hsl_to_rgb_part_16(): def test_rgb_to_hsl_part_16(): + """Test rgb to hsl color function""" # assert rgb_to_hsl(0, 0, 0) == (180, 100, 0) assert rgb_to_hsl(0, 51, 51) == (180, 100, 10) assert rgb_to_hsl(0, 102, 102) == (180, 100, 20) @@ -425,6 +487,7 @@ def test_rgb_to_hsl_part_16(): def test_hsl_to_rgb_part_17(): + """Test hsl to rgb color function""" assert hsl_to_rgb(240, 100, 0) == (0, 0, 0) assert hsl_to_rgb(240, 100, 10) == (0, 0, 51) assert hsl_to_rgb(240, 100, 20) == (0, 0, 102) @@ -439,6 +502,7 @@ def test_hsl_to_rgb_part_17(): def test_rgb_to_hsl_part_17(): + """Test rgb to hsl color function""" # assert rgb_to_hsl(0, 0, 0) == (240, 100, 0) assert rgb_to_hsl(0, 0, 51) == (240, 100, 10) assert rgb_to_hsl(0, 0, 102) == (240, 100, 20) @@ -453,6 +517,7 @@ def test_rgb_to_hsl_part_17(): def test_hsl_to_rgb_part_18(): + """Test hsl to rgb color function""" assert hsl_to_rgb(300, 100, 0) == (0, 0, 0) assert hsl_to_rgb(300, 100, 10) == (51, 0, 51) assert hsl_to_rgb(300, 100, 20) == (102, 0, 102) @@ -467,6 +532,7 @@ def test_hsl_to_rgb_part_18(): def test_rgb_to_hsl_part_18(): + """Test rgb to hsl color function""" # assert rgb_to_hsl(0, 0, 0) == (300, 100, 0) assert rgb_to_hsl(51, 0, 51) == (300, 100, 10) assert rgb_to_hsl(102, 0, 102) == (300, 100, 20) diff --git a/pygal/test/test_config.py b/pygal/test/test_config.py index 7b648bf..374d6ed 100644 --- a/pygal/test/test_config.py +++ b/pygal/test/test_config.py @@ -17,6 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . +"""Various config options tested on one chart type or more""" + from pygal import ( Line, Dot, Pie, Treemap, Radar, Config, Bar, Funnel, Histogram, Gauge, Box, XY, @@ -29,6 +31,7 @@ from tempfile import NamedTemporaryFile def test_config_behaviours(): + """Test that all different way to set config produce same results""" line1 = Line() line1.show_legend = False line1.fill = True @@ -89,6 +92,7 @@ def test_config_behaviours(): def test_config_alterations_class(): + """Assert a config can be changed on config class""" class LineConfig(Config): no_prefix = True show_legend = False @@ -111,6 +115,7 @@ def test_config_alterations_class(): def test_config_alterations_instance(): + """Assert a config can be changed on instance""" class LineConfig(Config): no_prefix = True show_legend = False @@ -134,6 +139,7 @@ def test_config_alterations_instance(): def test_config_alterations_kwargs(): + """Assert a config can be changed with keyword args""" class LineConfig(Config): no_prefix = True show_legend = False @@ -167,6 +173,7 @@ def test_config_alterations_kwargs(): def test_logarithmic(): + """Test logarithmic option""" line = Line(logarithmic=True) line.add('_', [1, 10 ** 10, 1]) q = line.render_pyquery() @@ -180,6 +187,7 @@ def test_logarithmic(): def test_interpolation(Chart): + """Test interpolation option""" chart = Chart(interpolate='cubic') chart.add('1', [1, 3, 12, 3, 4]) chart.add('2', [7, -4, 10, None, 8, 3, 1]) @@ -188,12 +196,14 @@ def test_interpolation(Chart): def test_no_data_interpolation(Chart): + """Test interpolation option with no data""" chart = Chart(interpolate='cubic') q = chart.render_pyquery() assert q(".text-overlay text").text() == "No data" def test_no_data_with_empty_serie_interpolation(Chart): + """Test interpolation option with an empty serie""" chart = Chart(interpolate='cubic') chart.add('Serie', []) q = chart.render_pyquery() @@ -201,6 +211,7 @@ def test_no_data_with_empty_serie_interpolation(Chart): def test_logarithmic_bad_interpolation(): + """Test interpolation option with a logarithmic chart""" line = Line(logarithmic=True, interpolate='cubic') line.add('_', [.001, .00000001, 1]) q = line.render_pyquery() @@ -208,6 +219,7 @@ def test_logarithmic_bad_interpolation(): def test_logarithmic_big_scale(): + """Test logarithmic option with a large range of value""" line = Line(logarithmic=True) line.add('_', [10 ** -10, 10 ** 10, 1]) q = line.render_pyquery() @@ -215,6 +227,7 @@ def test_logarithmic_big_scale(): def test_value_formatter(): + """Test value formatter option""" line = Line(value_formatter=lambda x: str(x) + u('‰')) line.add('_', [10 ** 4, 10 ** 5, 23 * 10 ** 4]) q = line.render_pyquery() @@ -224,6 +237,7 @@ def test_value_formatter(): def test_logarithmic_small_scale(): + """Test logarithmic with a small range of values""" line = Line(logarithmic=True) line.add('_', [1 + 10 ** 10, 3 + 10 ** 10, 2 + 10 ** 10]) q = line.render_pyquery() @@ -231,6 +245,7 @@ def test_logarithmic_small_scale(): def test_human_readable(): + """Test human readable option""" line = Line() line.add('_', [10 ** 4, 10 ** 5, 23 * 10 ** 4]) q = line.render_pyquery() @@ -243,6 +258,7 @@ def test_human_readable(): def test_show_legend(): + """Test show legend option""" line = Line() line.add('_', [1, 2, 3]) q = line.render_pyquery() @@ -253,6 +269,7 @@ def test_show_legend(): def test_show_dots(): + """Test show dots option""" line = Line() line.add('_', [1, 2, 3]) q = line.render_pyquery() @@ -263,6 +280,7 @@ def test_show_dots(): def test_no_data(): + """Test no data and no data text option""" line = Line() q = line.render_pyquery() assert q(".text-overlay text").text() == "No data" @@ -272,6 +290,7 @@ def test_no_data(): def test_include_x_axis(Chart): + """Test x axis inclusion option""" chart = Chart() if Chart in ( Pie, Treemap, Radar, Funnel, Dot, Gauge, Histogram, Box @@ -296,6 +315,7 @@ def test_include_x_axis(Chart): def test_css(Chart): + """Test css file option""" css = "{{ id }}text { fill: #bedead; }\n" with NamedTemporaryFile('w') as f: f.write(css) @@ -311,6 +331,7 @@ def test_css(Chart): def test_inline_css(Chart): + """Test inline css option""" css = "{{ id }}text { fill: #bedead; }\n" config = Config() @@ -322,11 +343,13 @@ def test_inline_css(Chart): def test_meta_config(): + """Test config metaclass""" from pygal.config import CONFIG_ITEMS assert all(c.name != 'Unbound' for c in CONFIG_ITEMS) def test_label_rotation(Chart): + """Test label rotation option""" chart = Chart(x_label_rotation=28, y_label_rotation=76) chart.add('1', [4, -5, 123, 59, 38]) chart.add('2', [89, 0, 8, .12, 8]) @@ -339,6 +362,7 @@ def test_label_rotation(Chart): def test_legend_at_bottom(Chart): + """Test legend at bottom option""" chart = Chart(legend_at_bottom=True) chart.add('1', [4, -5, 123, 59, 38]) chart.add('2', [89, 0, 8, .12, 8]) @@ -348,6 +372,7 @@ def test_legend_at_bottom(Chart): def test_x_y_title(Chart): + """Test x title and y title options""" chart = Chart(title='I Am A Title', x_title="I am a x title", y_title="I am a y title") @@ -358,6 +383,7 @@ def test_x_y_title(Chart): def test_x_label_major(Chart): + """Test x label major option""" if Chart in ( Pie, Treemap, Funnel, Dot, Gauge, Histogram, Box, Pyramid, DateTimeLine, TimeLine, DateLine, @@ -402,6 +428,7 @@ def test_x_label_major(Chart): def test_y_label_major(Chart): + """Test y label major option""" if Chart in ( Pie, Treemap, Funnel, Dot, Gauge, Histogram, Box, HorizontalBar, HorizontalStackedBar, @@ -450,6 +477,7 @@ def test_y_label_major(Chart): def test_no_y_labels(Chart): + """Test no y labels chart""" chart = Chart() chart.y_labels = [] chart.add('_', [1, 2, 3]) @@ -458,6 +486,7 @@ def test_no_y_labels(Chart): def test_fill(Chart): + """Test fill option""" chart = Chart(fill=True) chart.add('_', [1, 2, 3]) chart.add('?', [10, 21, 5]) diff --git a/pygal/test/test_date.py b/pygal/test/test_date.py index 810bb1c..86b3b5e 100644 --- a/pygal/test/test_date.py +++ b/pygal/test/test_date.py @@ -16,12 +16,16 @@ # # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . + +"""Date related charts tests""" + from pygal import DateLine, TimeLine, DateTimeLine, TimeDeltaLine from pygal.test.utils import texts from datetime import datetime, date, time, timedelta def test_date(): + """Test a simple dateline""" date_chart = DateLine(truncate_label=1000) date_chart.add('dates', [ (date(2013, 1, 2), 300), @@ -42,6 +46,7 @@ def test_date(): def test_time(): + """Test a simple timeline""" time_chart = TimeLine(truncate_label=1000) time_chart.add('times', [ (time(1, 12, 29), 2), @@ -64,6 +69,7 @@ def test_time(): def test_datetime(): + """Test a simple datetimeline""" datetime_chart = DateTimeLine(truncate_label=1000) datetime_chart.add('datetimes', [ (datetime(2013, 1, 2, 1, 12, 29), 300), @@ -84,6 +90,7 @@ def test_datetime(): def test_timedelta(): + """Test a simple timedeltaline""" timedelta_chart = TimeDeltaLine(truncate_label=1000) timedelta_chart.add('timedeltas', [ (timedelta(seconds=1), 10), @@ -105,6 +112,7 @@ def test_timedelta(): def test_date_xrange(): + """Test dateline with xrange""" datey = DateLine(truncate_label=1000) datey.add('dates', [ (date(2013, 1, 2), 300), diff --git a/pygal/test/test_donut.py b/pygal/test/test_donut.py deleted file mode 100644 index f0e94a1..0000000 --- a/pygal/test/test_donut.py +++ /dev/null @@ -1,60 +0,0 @@ -# -*- coding: utf-8 -*- -# This file is part of pygal -# -# A python svg graph plotting library -# Copyright © 2012-2015 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 . -from pygal import Pie - - -def test_donut(): - chart = Pie(inner_radius=.3, pretty_print=True) - chart.title = 'Browser usage in February 2012 (in %)' - chart.add('IE', 19.5) - chart.add('Firefox', 36.6) - chart.add('Chrome', 36.3) - chart.add('Safari', 4.5) - chart.add('Opera', 2.3) - assert chart.render() - - -def test_multiseries_donut(): - # this just demos that the multiseries pie does not respect - # the inner_radius - chart = Pie(inner_radius=.3, pretty_print=True) - chart.title = 'Browser usage by version in February 2012 (in %)' - chart.add('IE', [5.7, 10.2, 2.6, 1]) - chart.add('Firefox', [.6, 16.8, 7.4, 2.2, 1.2, 1, 1, 1.1, 4.3, 1]) - chart.add('Chrome', [.3, .9, 17.1, 15.3, .6, .5, 1.6]) - chart.add('Safari', [4.4, .1]) - chart.add('Opera', [.1, 1.6, .1, .5]) - assert chart.render() - - -def test_half_pie(): - pie = Pie() - pie.add('IE', 19.5) - pie.add('Firefox', 36.6) - pie.add('Chrome', 36.3) - pie.add('Safari', 4.5) - pie.add('Opera', 2.3) - - half = Pie(half_pie=True) - half.add('IE', 19.5) - half.add('Firefox', 36.6) - half.add('Chrome', 36.3) - half.add('Safari', 4.5) - half.add('Opera', 2.3) - assert pie.render() != half.render() diff --git a/pygal/test/test_graph.py b/pygal/test/test_graph.py index 455daab..a7d6e15 100644 --- a/pygal/test/test_graph.py +++ b/pygal/test/test_graph.py @@ -17,6 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . +"""Generate tests for different chart types with different data""" + import os import pygal import uuid @@ -34,6 +36,7 @@ except ImportError: def test_multi_render(Chart, datas): + """Check that a chart always render the same""" chart = Chart() chart = make_data(chart, datas) svg = chart.render() @@ -42,6 +45,7 @@ def test_multi_render(Chart, datas): def test_render_to_file(Chart, datas): + """Test in file rendering""" file_name = '/tmp/test_graph-%s.svg' % uuid.uuid4() if os.path.exists(file_name): os.remove(file_name) @@ -56,6 +60,7 @@ def test_render_to_file(Chart, datas): @pytest.mark.skipif(not cairosvg, reason="CairoSVG not installed") def test_render_to_png(Chart, datas): + """Test in file png rendering""" file_name = '/tmp/test_graph-%s.png' % uuid.uuid4() if os.path.exists(file_name): os.remove(file_name) @@ -71,6 +76,7 @@ def test_render_to_png(Chart, datas): def test_metadata(Chart): + """Test metadata values""" chart = Chart() v = range(7) if Chart in (pygal.Box,): @@ -110,6 +116,7 @@ def test_metadata(Chart): def test_empty_lists(Chart): + """Test chart rendering with an empty serie""" chart = Chart() chart.add('A', [1, 2]) chart.add('B', []) @@ -120,6 +127,7 @@ def test_empty_lists(Chart): def test_empty_lists_with_nones(Chart): + """Test chart rendering with a None filled serie""" chart = Chart() chart.add('A', [None, None]) chart.add('B', [None, 4, 4]) @@ -128,6 +136,7 @@ def test_empty_lists_with_nones(Chart): def test_only_one_value(Chart): + """Test chart rendering with only one value""" chart = Chart() chart.add('S', [1]) q = chart.render_pyquery() @@ -135,6 +144,7 @@ def test_only_one_value(Chart): def test_only_one_value_log(Chart): + """Test logarithmic chart rendering with only one value""" chart = Chart(logarithmic=True) chart.add('S', [1]) if not chart._dual: @@ -144,6 +154,7 @@ def test_only_one_value_log(Chart): def test_only_one_value_intrp(Chart): + """Test interpolated chart rendering with only one value""" chart = Chart(interpolate='cubic') chart.add('S', [1]) q = chart.render_pyquery() @@ -151,6 +162,7 @@ def test_only_one_value_intrp(Chart): def test_non_iterable_value(Chart): + """Test serie as non iterable""" chart = Chart(no_prefix=True) chart.add('A', 1) chart.add('B', 2) @@ -167,6 +179,7 @@ def test_non_iterable_value(Chart): def test_iterable_types(Chart): + """Test serie as various iterable""" chart = Chart(no_prefix=True) chart.add('A', [1, 2]) chart.add('B', []) @@ -184,6 +197,7 @@ def test_iterable_types(Chart): def test_values_by_dict(Chart): + """Test serie as dict""" chart1 = Chart(no_prefix=True) chart2 = Chart(no_prefix=True) @@ -214,18 +228,21 @@ def test_values_by_dict(Chart): def test_no_data_with_no_values(Chart): + """Test no data""" chart = Chart() q = chart.render_pyquery() assert q(".text-overlay text").text() == "No data" def test_no_data_with_no_values_with_include_x_axis(Chart): + """Test no data and include_x_axis""" chart = Chart(include_x_axis=True) q = chart.render_pyquery() assert q(".text-overlay text").text() == "No data" def test_no_data_with_empty_serie(Chart): + """Test no data for empty serie""" chart = Chart() chart.add('Serie', []) q = chart.render_pyquery() @@ -233,6 +250,7 @@ def test_no_data_with_empty_serie(Chart): def test_no_data_with_empty_series(Chart): + """Test no data for 2 empty series""" chart = Chart() chart.add('Serie1', []) chart.add('Serie2', []) @@ -241,6 +259,7 @@ def test_no_data_with_empty_series(Chart): def test_no_data_with_none(Chart): + """Test no data for a None containing serie""" chart = Chart() chart.add('Serie', None) q = chart.render_pyquery() @@ -248,6 +267,7 @@ def test_no_data_with_none(Chart): def test_no_data_with_list_of_none(Chart): + """Test no data for a None containing serie""" chart = Chart() chart.add('Serie', [None]) q = chart.render_pyquery() @@ -255,6 +275,7 @@ def test_no_data_with_list_of_none(Chart): def test_no_data_with_lists_of_nones(Chart): + """Test no data for several None containing series""" chart = Chart() chart.add('Serie1', [None, None, None, None]) chart.add('Serie2', [None, None, None]) @@ -263,6 +284,7 @@ def test_no_data_with_lists_of_nones(Chart): def test_unicode_labels_decode(Chart): + """Test unicode labels""" chart = Chart() chart.add(u('Série1'), [{ 'value': 1, @@ -284,6 +306,7 @@ def test_unicode_labels_decode(Chart): def test_unicode_labels_python2(Chart): + """Test unicode labels in python 2""" if sys.version_info[0] == 3: return chart = Chart() @@ -307,6 +330,7 @@ def test_unicode_labels_python2(Chart): def test_unicode_labels_python3(Chart): + """Test unicode labels in python 3""" if sys.version_info[0] == 2: return chart = Chart() @@ -330,6 +354,7 @@ def test_unicode_labels_python3(Chart): def test_labels_with_links(Chart): + """Test values with links""" chart = Chart() # link on chart and label chart.add({ @@ -381,12 +406,14 @@ def test_labels_with_links(Chart): def test_sparkline(Chart, datas): + """Test sparkline""" chart = Chart() chart = make_data(chart, datas) assert chart.render_sparkline() def test_secondary(Chart): + """Test secondary chart""" chart = Chart() rng = [83, .12, -34, 59] chart.add('First serie', rng) @@ -397,12 +424,14 @@ def test_secondary(Chart): def test_ipython_notebook(Chart, datas): + """Test ipython notebook""" chart = Chart() chart = make_data(chart, datas) assert chart._repr_svg_() def test_long_title(Chart, datas): + """Test chart rendering with a long title""" chart = Chart( title="A chart is a graphical representation of data, in which " "'the data is represented by symbols, such as bars in a bar chart, " diff --git a/pygal/test/test_histogram.py b/pygal/test/test_histogram.py index a8a7655..7fbc5dd 100644 --- a/pygal/test/test_histogram.py +++ b/pygal/test/test_histogram.py @@ -17,10 +17,14 @@ # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . +"""Histogram chart related tests""" + + from pygal import Histogram def test_histogram(): + """Simple histogram test""" hist = Histogram() hist.add('1', [ (2, 0, 1), diff --git a/pygal/test/test_interpolate.py b/pygal/test/test_interpolate.py index 54481d7..30797f1 100644 --- a/pygal/test/test_interpolate.py +++ b/pygal/test/test_interpolate.py @@ -17,16 +17,20 @@ # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . +"""Interpolations tests""" + from pygal.test import make_data def test_cubic(Chart, datas): + """Test cubic interpolation""" chart = Chart(interpolate='cubic') chart = make_data(chart, datas) assert chart.render() def test_cubic_prec(Chart, datas): + """Test cubic interpolation precision""" chart = Chart(interpolate='cubic', interpolation_precision=200) chart = make_data(chart, datas) @@ -37,30 +41,35 @@ def test_cubic_prec(Chart, datas): def test_quadratic(Chart, datas): + """Test quadratic interpolation""" chart = Chart(interpolate='quadratic') chart = make_data(chart, datas) assert chart.render() def test_lagrange(Chart, datas): + """Test lagrange interpolation""" chart = Chart(interpolate='lagrange') chart = make_data(chart, datas) assert chart.render() def test_trigonometric(Chart, datas): + """Test trigonometric interpolation""" chart = Chart(interpolate='trigonometric') chart = make_data(chart, datas) assert chart.render() def test_hermite(Chart, datas): + """Test hermite interpolation""" chart = Chart(interpolate='hermite') chart = make_data(chart, datas) assert chart.render() def test_hermite_finite(Chart, datas): + """Test hermite finite difference interpolation""" chart = Chart(interpolate='hermite', interpolation_parameters={'type': 'finite_difference'}) chart = make_data(chart, datas) @@ -68,6 +77,7 @@ def test_hermite_finite(Chart, datas): def test_hermite_cardinal(Chart, datas): + """Test hermite cardinal interpolation""" chart = Chart(interpolate='hermite', interpolation_parameters={'type': 'cardinal', 'c': .75}) chart = make_data(chart, datas) @@ -75,6 +85,7 @@ def test_hermite_cardinal(Chart, datas): def test_hermite_catmull_rom(Chart, datas): + """Test hermite catmull rom interpolation""" chart = Chart(interpolate='hermite', interpolation_parameters={'type': 'catmull_rom'}) chart = make_data(chart, datas) @@ -82,6 +93,7 @@ def test_hermite_catmull_rom(Chart, datas): def test_hermite_kochanek_bartels(Chart, datas): + """Test hermite kochanek bartels interpolation""" chart = Chart(interpolate='hermite', interpolation_parameters={ 'type': 'kochanek_bartels', 'b': -1, 'c': 1, 't': 1}) diff --git a/pygal/test/test_line.py b/pygal/test/test_line.py index d99aa30..466e0fb 100644 --- a/pygal/test/test_line.py +++ b/pygal/test/test_line.py @@ -16,6 +16,9 @@ # # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . + +"""Line chart related tests""" + from __future__ import division from pygal import Line from pygal.test.utils import texts @@ -23,6 +26,7 @@ from math import cos, sin def test_simple_line(): + """Simple line test""" line = Line() rng = range(-30, 31, 5) line.add('test1', [cos(x / 10) for x in rng]) @@ -49,6 +53,7 @@ def test_simple_line(): def test_line(): + """Another simple line test""" line = Line() rng = [8, 12, 23, 73, 39, 57] line.add('Single serie', rng) @@ -62,6 +67,7 @@ def test_line(): def test_one_dot(): + """Line test with an unique value""" line = Line() line.add('one dot', [12]) line.x_labels = ['one'] @@ -72,6 +78,7 @@ def test_one_dot(): def test_no_dot(): + """Line test with an empty serie""" line = Line() line.add('no dot', []) q = line.render_pyquery() @@ -79,11 +86,13 @@ def test_no_dot(): def test_no_dot_at_all(): + """Line test with no value""" q = Line().render_pyquery() assert q(".text-overlay text").text() == 'No data' def test_not_equal_x_labels(): + """Test x_labels""" line = Line() line.add('test1', range(100)) line.x_labels = map(str, range(11)) @@ -95,6 +104,7 @@ def test_not_equal_x_labels(): def test_only_major_dots_every(): + """Test major dots""" line = Line(show_only_major_dots=True, x_labels_major_every=3) line.add('test', range(12)) line.x_labels = map(str, range(12)) @@ -103,6 +113,7 @@ def test_only_major_dots_every(): def test_only_major_dots_no_labels(): + """Test major dots with no labels""" line = Line(show_only_major_dots=True) line.add('test', range(12)) q = line.render_pyquery() @@ -110,6 +121,7 @@ def test_only_major_dots_no_labels(): def test_only_major_dots_count(): + """Test major dots with a major label count""" line = Line(show_only_major_dots=True) line.add('test', range(12)) line.x_labels = map(str, range(12)) @@ -119,6 +131,7 @@ def test_only_major_dots_count(): def test_only_major_dots(): + """Test major dots with specified major labels""" line = Line(show_only_major_dots=True,) line.add('test', range(12)) line.x_labels = map(str, range(12)) @@ -128,6 +141,7 @@ def test_only_major_dots(): def test_line_secondary(): + """Test line with a secondary serie""" line = Line() rng = [8, 12, 23, 73, 39, 57] line.add('First serie', rng) diff --git a/pygal/test/test_maps.py b/pygal/test/test_maps.py index d211630..260db21 100644 --- a/pygal/test/test_maps.py +++ b/pygal/test/test_maps.py @@ -1,3 +1,24 @@ +# -*- coding: utf-8 -*- +# This file is part of pygal +# +# A python svg graph plotting library +# Copyright © 2012-2015 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 . + +"""Map plugins tests are imported here""" + import pkg_resources diff --git a/pygal/test/test_pie.py b/pygal/test/test_pie.py index f0e94a1..01fd391 100644 --- a/pygal/test/test_pie.py +++ b/pygal/test/test_pie.py @@ -16,10 +16,14 @@ # # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . + +"""Donut chart related tests""" + from pygal import Pie def test_donut(): + """Test a donut pie chart""" chart = Pie(inner_radius=.3, pretty_print=True) chart.title = 'Browser usage in February 2012 (in %)' chart.add('IE', 19.5) @@ -31,6 +35,7 @@ def test_donut(): def test_multiseries_donut(): + """Test a donut pie chart with multiserie""" # this just demos that the multiseries pie does not respect # the inner_radius chart = Pie(inner_radius=.3, pretty_print=True) @@ -44,6 +49,7 @@ def test_multiseries_donut(): def test_half_pie(): + """Test a half pie chart""" pie = Pie() pie.add('IE', 19.5) pie.add('Firefox', 36.6) diff --git a/pygal/test/test_serie_config.py b/pygal/test/test_serie_config.py index 8547ad7..83c94c4 100644 --- a/pygal/test/test_serie_config.py +++ b/pygal/test/test_serie_config.py @@ -17,13 +17,17 @@ # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . +"""Test per serie configuration""" + from pygal import Line -def test_serie_config(): - s1 = [1, 3, 12, 3, 4] - s2 = [7, -4, 10, None, 8, 3, 1] +s1 = [1, 3, 12, 3, 4] +s2 = [7, -4, 10, None, 8, 3, 1] + +def test_no_serie_config(): + """Test per serie no configuration""" chart = Line() chart.add('1', s1) chart.add('2', s2) @@ -33,6 +37,9 @@ def test_serie_config(): assert len(q('.serie-0 .dot')) == 5 assert len(q('.serie-1 .dot')) == 6 + +def test_global_config(): + """Test global configuration""" chart = Line(stroke=False) chart.add('1', s1) chart.add('2', s2) @@ -42,6 +49,9 @@ def test_serie_config(): assert len(q('.serie-0 .dot')) == 5 assert len(q('.serie-1 .dot')) == 6 + +def test_serie_config(): + """Test per serie configuration""" chart = Line() chart.add('1', s1, stroke=False) chart.add('2', s2) @@ -51,6 +61,9 @@ def test_serie_config(): assert len(q('.serie-0 .dot')) == 5 assert len(q('.serie-1 .dot')) == 6 + +def test_serie_precedence_over_global_config(): + """Test that per serie configuration overide global configuration""" chart = Line(stroke=False) chart.add('1', s1, stroke=True) chart.add('2', s2) diff --git a/pygal/test/test_sparktext.py b/pygal/test/test_sparktext.py index 6deba46..af7cb3a 100644 --- a/pygal/test/test_sparktext.py +++ b/pygal/test/test_sparktext.py @@ -16,23 +16,29 @@ # # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . + +"""Test sparktext rendering""" + from pygal import Line, Bar from pygal._compat import u def test_basic_sparktext(): + """Test basic sparktext""" chart = Line() chart.add('_', [1, 5, 22, 13, 53]) assert chart.render_sparktext() == u('▁▁▃▂█') def test_all_sparktext(): + """Test all character sparktext""" chart = Line() chart.add('_', range(8)) assert chart.render_sparktext() == u('▁▂▃▄▅▆▇█') def test_shifted_sparktext(): + """Test relative_to option in sparktext""" chart = Line() chart.add('_', list(map(lambda x: x + 10000, range(8)))) assert chart.render_sparktext() == u('▁▂▃▄▅▆▇█') @@ -40,6 +46,7 @@ def test_shifted_sparktext(): def test_another_sparktext(): + """Test that same data produces same sparktext""" chart = Line() chart.add('_', [0, 30, 55, 80, 33, 150]) assert chart.render_sparktext() == u('▁▂▃▄▂█') @@ -49,11 +56,16 @@ def test_another_sparktext(): assert chart2.render_sparktext() == chart.render_sparktext() -def test_negative_and_float_and_no_data_sparktext(): +def test_negative_and_float__sparktext(): + """Test negative values""" + """Test negative values""" chart = Line() chart.add('_', [0.1, 0.2, 0.9, -0.5]) assert chart.render_sparktext() == u('▁▂█▁') + +def test_no_data_sparktext(): + """Test no data sparktext""" chart2 = Line() chart2.add('_', []) assert chart2.render_sparktext() == u('') @@ -63,6 +75,7 @@ def test_negative_and_float_and_no_data_sparktext(): def test_same_max_and_relative_values_sparktext(): + """Test flat sparktexts""" chart = Line() chart.add('_', [0, 0, 0, 0, 0]) assert chart.render_sparktext() == u('▁▁▁▁▁') diff --git a/pygal/test/test_stacked.py b/pygal/test/test_stacked.py index 74886ab..9751575 100644 --- a/pygal/test/test_stacked.py +++ b/pygal/test/test_stacked.py @@ -16,10 +16,14 @@ # # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . + +"""Stacked chart related tests""" + from pygal import StackedLine def test_stacked_line(): + """Test stacked line""" stacked = StackedLine() stacked.add('one_two', [1, 2]) stacked.add('ten_twelve', [10, 12]) @@ -29,6 +33,7 @@ def test_stacked_line(): def test_stacked_line_reverse(): + """Test stack from top stacked line""" stacked = StackedLine(stack_from_top=True) stacked.add('one_two', [1, 2]) stacked.add('ten_twelve', [10, 12]) @@ -38,6 +43,7 @@ def test_stacked_line_reverse(): def test_stacked_line_log(): + """Test logarithmic stacked line""" stacked = StackedLine(logarithmic=True) stacked.add('one_two', [1, 2]) stacked.add('ten_twelve', [10, 12]) @@ -47,6 +53,7 @@ def test_stacked_line_log(): def test_stacked_line_interpolate(): + """Test interpolated stacked line""" stacked = StackedLine(interpolate='cubic') stacked.add('one_two', [1, 2]) stacked.add('ten_twelve', [10, 12]) diff --git a/pygal/test/test_style.py b/pygal/test/test_style.py index f6fd148..9934a90 100644 --- a/pygal/test/test_style.py +++ b/pygal/test/test_style.py @@ -16,6 +16,9 @@ # # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . + +"""Style related tests""" + from pygal import Line from pygal.style import ( LightStyle, @@ -26,6 +29,7 @@ STYLES = LightenStyle, DarkenStyle, SaturateStyle, DesaturateStyle, RotateStyle def test_parametric_styles(): + """Test that no parametric produce the same result""" chart = None for style in STYLES: line = Line(style=style('#f4e83a')) @@ -37,6 +41,7 @@ def test_parametric_styles(): def test_parametric_styles_with_parameters(): + """Test a parametric style with parameters""" line = Line(style=RotateStyle( '#de3804', step=12, max_=180, base_style=LightStyle)) line.add('_', [1, 2, 3]) diff --git a/pygal/test/test_table.py b/pygal/test/test_table.py index e11ccb3..68c44d8 100644 --- a/pygal/test/test_table.py +++ b/pygal/test/test_table.py @@ -16,11 +16,15 @@ # # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . + +"""Box chart related tests""" + from pygal import Pie from pyquery import PyQuery as pq def test_pie_table(): + """Test rendering a table for a pie""" chart = Pie(inner_radius=.3, pretty_print=True) chart.title = 'Browser usage in February 2012 (in %)' chart.add('IE', 19.5) diff --git a/pygal/test/test_util.py b/pygal/test/test_util.py index 53da1fc..19e4a84 100644 --- a/pygal/test/test_util.py +++ b/pygal/test/test_util.py @@ -16,6 +16,9 @@ # # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . + +"""Utility functions tests""" + from pygal._compat import u from pygal.util import ( round_to_int, round_to_float, _swap_curly, template, humanize, @@ -24,6 +27,7 @@ from pytest import raises def test_round_to_int(): + """Test round to int function""" assert round_to_int(154231, 1000) == 154000 assert round_to_int(154231, 10) == 154230 assert round_to_int(154231, 100000) == 200000 @@ -34,6 +38,7 @@ def test_round_to_int(): def test_round_to_float(): + """Test round to float function""" assert round_to_float(12.01934, .01) == 12.02 assert round_to_float(12.01134, .01) == 12.01 assert round_to_float(12.1934, .1) == 12.2 @@ -45,6 +50,7 @@ def test_round_to_float(): def test_swap_curly(): + """Test swap curly function""" for str in ( 'foo', u('foo foo foo bar'), @@ -64,6 +70,7 @@ def test_swap_curly(): def test_format(): + """Test format function""" assert template('foo {{ baz }}', baz='bar') == 'foo bar' with raises(KeyError): assert template('foo {{ baz }}') == 'foo baz' @@ -80,6 +87,7 @@ def test_format(): def test_humanize(): + """Test humanize function""" assert humanize(1) == '1' assert humanize(1.) == '1' assert humanize(10) == '10' @@ -109,6 +117,7 @@ def test_humanize(): def test_truncate(): + """Test truncate function""" assert truncate('1234567890', 50) == '1234567890' assert truncate('1234567890', 5) == u('1234…') assert truncate('1234567890', 1) == u('…') @@ -119,6 +128,7 @@ def test_truncate(): def test_minify_css(): + """Test css minifier function""" css = ''' /* * Font-sizes from config, override with care @@ -139,7 +149,8 @@ def test_minify_css(): '.legends .legend text{font-family:monospace;font-size:14}') -def test_major(): +def test_majorize(): + """Test majorize function""" assert majorize(()) == [] assert majorize((0,)) == [] assert majorize((0, 1)) == [] diff --git a/pygal/test/test_view.py b/pygal/test/test_view.py index e9a6dc5..4359c4e 100644 --- a/pygal/test/test_view.py +++ b/pygal/test/test_view.py @@ -18,7 +18,13 @@ # along with pygal. If not, see . +"""View related tests""" + +# TODO + + def test_all_logarithmic(Chart): + """Test logarithmic view rendering""" chart = Chart(logarithmic=True) chart.add('1', [1, 30, 8, 199, -23]) chart.add('2', [87, 42, .9, 189, 81]) diff --git a/pygal/test/test_xml_filters.py b/pygal/test/test_xml_filters.py index 6f4860a..fbfd1c6 100644 --- a/pygal/test/test_xml_filters.py +++ b/pygal/test/test_xml_filters.py @@ -16,14 +16,22 @@ # # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . + +"""Xml filter tests""" + from pygal import Bar class ChangeBarsXMLFilter(object): + + """xml filter that insert a subplot""" + def __init__(self, a, b): + """Generate data""" self.data = [b[i] - a[i] for i in range(len(a))] def __call__(self, T): + """Apply the filter on the tree""" subplot = Bar(legend_at_bottom=True, explicit_size=True, width=800, height=150) subplot.add("Difference", self.data) @@ -35,6 +43,7 @@ class ChangeBarsXMLFilter(object): def test_xml_filters_round_trip(): + """Ensure doing nothing does nothing""" plot = Bar() plot.add("A", [60, 75, 80, 78, 83, 90]) plot.add("B", [92, 87, 81, 73, 68, 55]) @@ -45,6 +54,7 @@ def test_xml_filters_round_trip(): def test_xml_filters_change_bars(): + """Test the use a xml filter""" plot = Bar(legend_at_bottom=True, explicit_size=True, width=800, height=600) A = [60, 75, 80, 78, 83, 90] diff --git a/pygal/test/utils.py b/pygal/test/utils.py index 6b552c5..3a126d5 100644 --- a/pygal/test/utils.py +++ b/pygal/test/utils.py @@ -16,8 +16,12 @@ # # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . + +"""Tests helpers""" + from pyquery import PyQuery as pq def texts(i, e): + """Helper for getting the text of an element""" return pq(e).text()