/usr/lib/python2.7/dist-packages/pygal/test/test_line.py is in python-pygal 2.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | # -*- coding: utf-8 -*-
# This file is part of pygal
#
# A python svg graph plotting library
# Copyright © 2012-2016 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/>.
"""Line chart related tests"""
from __future__ import division
from math import cos, sin
from pygal import Line
from pygal.test.utils import texts
def test_simple_line():
"""Simple line test"""
line = Line()
rng = range(-30, 31, 5)
line.add('test1', [cos(x / 10) for x in rng])
line.add('test2', [sin(x / 10) for x in rng])
line.add('test3', [cos(x / 10) - sin(x / 10) for x in rng])
line.x_labels = map(str, rng)
line.title = "cos sin and cos - sin"
q = line.render_pyquery()
assert len(q(".axis.x")) == 1
assert len(q(".axis.y")) == 1
assert len(q(".plot .series path")) == 3
assert len(q(".legend")) == 3
assert len(q(".x.axis .guides")) == 13
assert len(q(".y.axis .guides")) == 13
assert len(q(".dots")) == 3 * 13
assert q(".axis.x text").map(texts) == [
'-30', '-25', '-20', '-15', '-10', '-5',
'0', '5', '10', '15', '20', '25', '30']
assert q(".axis.y text").map(texts) == [
'-1.2', '-1', '-0.8', '-0.6', '-0.4', '-0.2',
'0', '0.2', '0.4', '0.6', '0.8', '1', '1.2']
assert q(".title").text() == 'cos sin and cos - sin'
assert q(".legend text").map(texts) == ['test1', 'test2', 'test3']
def test_line():
"""Another simple line test"""
line = Line()
rng = [8, 12, 23, 73, 39, 57]
line.add('Single serie', rng)
line.title = "One serie"
q = line.render_pyquery()
assert len(q(".axis.x")) == 0
assert len(q(".axis.y")) == 1
assert len(q(".plot .series path")) == 1
assert len(q(".x.axis .guides")) == 0
assert len(q(".y.axis .guides")) == 7
def test_one_dot():
"""Line test with an unique value"""
line = Line()
line.add('one dot', [12])
line.x_labels = ['one']
q = line.render_pyquery()
assert len(q(".axis.x")) == 1
assert len(q(".axis.y")) == 1
assert len(q(".y.axis .guides")) == 1
def test_no_dot():
"""Line test with an empty serie"""
line = Line()
line.add('no dot', [])
q = line.render_pyquery()
assert q(".text-overlay text").text() == 'No data'
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.truncate_label = -1
line.x_labels = map(str, range(11))
q = line.render_pyquery()
assert len(q(".dots")) == 100
assert len(q(".axis.x")) == 1
assert q(".axis.x text").map(texts) == [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
def test_int_x_labels():
"""Test x_labels"""
line = Line()
line.add('test1', range(100))
line.truncate_label = -1
line.x_labels = list(range(11))
q = line.render_pyquery()
assert len(q(".dots")) == 100
assert len(q(".axis.x")) == 1
assert q(".axis.x text").map(texts) == [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
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))
q = line.render_pyquery()
assert len(q(".dots")) == 4
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()
assert len(q(".dots")) == 12
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))
line.x_labels_major_count = 2
q = line.render_pyquery()
assert len(q(".dots")) == 2
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))
line.x_labels_major = ['1', '5', '11']
q = line.render_pyquery()
assert len(q(".dots")) == 3
def test_line_secondary():
"""Test line with a secondary serie"""
line = Line()
rng = [8, 12, 23, 73, 39, 57]
line.add('First serie', rng)
line.add('Secondary serie',
map(lambda x: x * 2, rng),
secondary=True)
line.title = "One serie"
q = line.render_pyquery()
assert len(q(".axis.x")) == 0
assert len(q(".axis.y")) == 1
assert len(q(".plot .series path")) == 2
assert len(q(".x.axis .guides")) == 0
assert len(q(".y.axis .guides")) == 7
|