Browse Source

Fix 'No data' when the serie only contains Nones + add some tests

pull/8/head
Florian Mounier 12 years ago
parent
commit
8f5ececb98
  1. 2
      pygal/__init__.py
  2. 2
      pygal/graph/base.py
  3. 6
      pygal/test/test_config.py
  4. 49
      pygal/test/test_graph.py
  5. 4
      pygal/test/test_util.py
  6. 2
      pygal/util.py

2
pygal/__init__.py

@ -21,7 +21,7 @@ Pygal - A python svg graph plotting library
"""
__version__ = '0.12.1'
__version__ = '0.12.2'
import sys
from pygal.config import Config
from pygal.ghost import Ghost

2
pygal/graph/base.py

@ -150,7 +150,7 @@ class BaseGraph(object):
def _has_data(self):
"""Check if there is any data"""
return sum(map(len, map(lambda s: s.values, self.series))) != 0
return sum(map(len, map(lambda s: s.safe_values, self.series))) != 0
def render(self, is_unicode):
"""Render the graph, and return the svg string"""

6
pygal/test/test_config.py

@ -180,9 +180,9 @@ def test_logarithmic_small_scale():
def test_human_readable():
line = Line()
line.add('_', [10 ** 4, 10 ** 5, 23 * 10 ** 4])
# q = line.render_pyquery()
# assert q(".axis.y text").map(texts) == map(
# str, range(20000, 240000, 20000))
q = line.render_pyquery()
assert q(".axis.y text").map(texts) == map(
str, map(float, range(20000, 240000, 20000)))
line.human_readable = True
q = line.render_pyquery()
assert q(".axis.y text").map(texts) == map(

49
pygal/test/test_graph.py

@ -93,14 +93,16 @@ def test_empty_lists(Chart):
chart.add('B', [])
chart.x_labels = ('red', 'green', 'blue')
q = chart.render_pyquery()
assert len(q(".legend")) == 2
assert len(q(".legend")) == 1
def test_empty_lists_with_nones(Chart):
chart = Chart()
chart.add('A', [None, None])
chart.add('B', [None, 4, 4])
chart.x_labels = ('red', 'green', 'blue')
q = chart.render_pyquery()
assert len(q(".legend")) == 2
assert len(q(".legend")) == 1
def test_non_iterable_value(Chart):
@ -151,3 +153,46 @@ def test_values_by_dict(Chart):
chart.x_labels = ('red', 'green', 'blue')
chart2 = chart.render()
assert chart1 == chart2
def test_no_data_with_no_values(Chart):
chart = Chart()
q = chart.render_pyquery()
assert q("text").text() == "No data"
def test_no_data_with_empty_serie(Chart):
chart = Chart()
chart.add('Serie', [])
q = chart.render_pyquery()
assert q("text").text() == "No data"
def test_no_data_with_empty_series(Chart):
chart = Chart()
chart.add('Serie1', [])
chart.add('Serie2', [])
q = chart.render_pyquery()
assert q("text").text() == "No data"
def test_no_data_with_none(Chart):
chart = Chart()
chart.add('Serie', None)
q = chart.render_pyquery()
assert q("text").text() == "No data"
def test_no_data_with_list_of_none(Chart):
chart = Chart()
chart.add('Serie', [None])
q = chart.render_pyquery()
assert q("text").text() == "No data"
def test_no_data_with_lists_of_nones(Chart):
chart = Chart()
chart.add('Serie1', [None, None, None, None])
chart.add('Serie2', [None, None, None])
q = chart.render_pyquery()
assert q("text").text() == "No data"

4
pygal/test/test_util.py

@ -125,7 +125,7 @@ def test_truncate():
def test_minify_css():
css = '''
/*
/*
* Font-sizes from config, override with care
*/
@ -136,7 +136,7 @@ def test_minify_css():
}
.legends .legend text {
font-family: monospace;
font-family: monospace;
font-size: 14 ;}
'''
assert minify_css(css) == (

2
pygal/util.py

@ -316,6 +316,8 @@ def prepare_values(raw, config, cls):
else:
raw_values = list(raw_values)
if not filter(lambda x: x is not None, raw_values):
continue
for index, raw_value in enumerate(
raw_values + (
(width - len(raw_values)) * [None] # aligning values

Loading…
Cancel
Save