Skip to content

Commit

Permalink
Fix tests of datey and worldmap
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Sep 18, 2013
1 parent 07facb7 commit 447ddf6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
12 changes: 0 additions & 12 deletions pygal/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions pygal/graph/worldmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
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

Expand All @@ -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):
Expand Down
19 changes: 15 additions & 4 deletions pygal/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 447ddf6

Please sign in to comment.