From c423a097f6235288774027503e1b4eddd9b12974 Mon Sep 17 00:00:00 2001 From: Neil Bedi Date: Thu, 9 Jun 2016 14:03:44 -0400 Subject: [PATCH] Add GroupedBars tests. #26 --- leather/__init__.py | 2 +- tests/test_shapes.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/leather/__init__.py b/leather/__init__.py index 9a2827c..a32593d 100644 --- a/leather/__init__.py +++ b/leather/__init__.py @@ -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 diff --git a/tests/test_shapes.py b/tests/test_shapes.py index 0410ca9..2c83937 100644 --- a/tests/test_shapes.py +++ b/tests/test_shapes.py @@ -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)