diff --git a/pygal/adapters.py b/pygal/adapters.py index a952eb4..e7bca90 100644 --- a/pygal/adapters.py +++ b/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): diff --git a/pygal/graph/worldmap.py b/pygal/graph/worldmap.py index ad5e295..4f637ad 100644 --- a/pygal/graph/worldmap.py +++ b/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): diff --git a/pygal/test/__init__.py b/pygal/test/__init__.py index fdac292..f73533b 100644 --- a/pygal/test/__init__.py +++ b/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):