Browse Source

Fix tests of datey and worldmap

pull/63/merge
Florian Mounier 11 years ago
parent
commit
447ddf68ee
  1. 12
      pygal/adapters.py
  2. 2
      pygal/graph/worldmap.py
  3. 19
      pygal/test/__init__.py

12
pygal/adapters.py

@ -43,18 +43,6 @@ def none_to_zero(x):
return x or 0
def int_to_country(x):
# This is used for test compatibility
if isinstance(x, Number):
try:
x = int(x)
except:
return x
if x >= 0 and x < len(COUNTRIES):
return list(COUNTRIES.keys())[x]
return x
def date(x):
# Make int work for date graphs by counting days number from now
if isinstance(x, Number):

2
pygal/graph/worldmap.py

@ -25,7 +25,6 @@ from __future__ import division
from pygal.util import cut, cached_property, decorate
from pygal.graph.graph import Graph
from pygal.i18n import COUNTRIES
from pygal.adapters import int_to_country
from lxml import etree
import os
@ -40,7 +39,6 @@ class Worldmap(Graph):
_dual = True
x_labels = list(COUNTRIES.keys())
country_names = COUNTRIES
_adapters = [int_to_country]
@cached_property
def countries(self):

19
pygal/test/__init__.py

@ -20,6 +20,8 @@
import pygal
from pygal.util import cut
from datetime import datetime
from pygal.i18n import COUNTRIES
COUNTRY_KEYS = list(COUNTRIES.keys())
def get_data(i):
@ -44,12 +46,21 @@ def pytest_generate_tests(metafunc):
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))
if isinstance(chart, pygal.XY):
if isinstance(chart, pygal.DateY):
# Convert to a credible datetime
return datetime.fromtimestamp(1360000000 + data * 987654)
return data
return cut(data)
data = cut(data)
if isinstance(chart, pygal.Worldmap):
return list(map(lambda x: COUNTRY_KEYS[x % len(COUNTRIES)]
if x is not None else None, data))
return data
def make_data(chart, datas):

Loading…
Cancel
Save