Skip to content

Commit

Permalink
Add GroupedBars tests. wireservice#26
Browse files Browse the repository at this point in the history
  • Loading branch information
nbedi committed Jun 9, 2016
1 parent 6ce0fda commit c423a09
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion leather/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
from leather.lattice import Lattice
from leather.scales import Scale, Linear, Months, Ordinal, Temporal, Years
from leather.series import Series, CategorySeries, key_function
from leather.shapes import Shape, Bars, Columns, Dots, Line, style_function
from leather.shapes import Shape, Bars, Columns, Dots, Line, GroupedBars, style_function
from leather.testcase import LeatherTestCase
from leather import theme
41 changes: 41 additions & 0 deletions tests/test_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,44 @@ def test_nulls(self):
paths = list(group)

self.assertEqual(len(paths), 2)

class TestGroupedBars(leather.LeatherTestCase):
def setUp(self):
self.shape = leather.GroupedBars()
self.linear = leather.Linear(0, 10)
self.ordinal = leather.Ordinal(['first', 'second', 'third'])
self.palette = (color for color in ['red', 'white', 'blue'])
self.rows = [
(1, 'foo', 'first'),
(5, 'bar', 'first'),
(7, 'foo', 'second'),
(4, 'bing', 'second'),
(7, 'foo', 'third'),
(3, 'bar', 'third'),
(4, 'buzz', 'third')
]

def test_to_svg(self):
series = leather.CategorySeries(self.rows)

group = self.shape.to_svg(200, 100, self.linear, self.ordinal, series, self.palette)
rects = list(group)

self.assertEqual(len(rects), 7)
self.assertEqual(float(rects[1].get('x')), 0)
self.assertEqual(float(rects[1].get('width')), 100)
self.assertEqual(rects[1].get('fill'), 'white')

def test_nulls(self):
series = leather.CategorySeries([
(0, 'foo', 'first'),
(None, None, None),
(10, 'bing', 'third')
])

group = self.shape.to_svg(200, 100, self.linear, self.ordinal, series, self.palette)
rects = list(group)

self.assertEqual(len(rects), 2)
self.assertEqual(float(rects[0].get('x')), 0)
self.assertEqual(float(rects[0].get('width')), 0)

0 comments on commit c423a09

Please sign in to comment.