Skip to content

Commit

Permalink
Add grouped bars test. wireservice#26
Browse files Browse the repository at this point in the history
  • Loading branch information
nbedi committed May 26, 2016
1 parent 1180bd2 commit 66d2829
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions tests/test_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def setUp(self):
self.shape = leather.Bars('red')
self.linear = leather.Linear(0, 10)
self.ordinal = leather.Ordinal(['foo', 'bar', 'bing'])
self.rows = [
(0, 'foo'),
(None, None),
(10, 'bing')
]

def test_to_svg(self):
series = leather.Series([
Expand All @@ -29,11 +34,7 @@ def test_to_svg(self):
self.assertEqual(float(rects[1].get('width')), 100)

def test_nulls(self):
series = leather.Series([
(0, 'foo'),
(None, None),
(10, 'bing')
], self.shape)
series = leather.Series(self.rows, self.shape)

group = self.shape.to_svg(200, 100, self.linear, self.ordinal, series)
rects = list(group)
Expand All @@ -42,6 +43,29 @@ def test_nulls(self):
self.assertEqual(float(rects[1].get('x')), 0)
self.assertEqual(float(rects[1].get('width')), 0)

def test_grouped(self):
shape = leather.Bars(fill_color=['red', 'blue', 'green'], grouped=True)
series = leather.Series([
(0, 'foo'),
(6, 'bar'),
(5, 'bar'),
(7, 'bar'),
(3, 'bing'),
(10, 'bing')
], shape)
group = shape.to_svg(200, 100, self.linear, self.ordinal, series)

base_series = leather.Series(self.rows, shape)
base_group = self.shape.to_svg(200, 100, self.linear, self.ordinal, base_series)
rects = list(group)
base_rects = list(base_group)

self.assertEqual(len(rects), 6)
self.assertEqual(float(rects[1].get('x')), 0)
self.assertEqual(float(rects[1].get('width')), 60)
self.assertEqual(rects[1].get('fill'), 'blue')
self.assertEqual(rects[5].get('y'), base_rects[1].get('y'))


class TestColumns(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit 66d2829

Please sign in to comment.