Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_linear(self):
series = leather.Series([
(0, 0),
(5, 5),
(10, 10)
])
group = self.shape.to_svg(200, 100, self.linear, self.linear, series, self.palette)
circles = list(group)
self.assertEqual(len(circles), 3)
self.assertEqual(float(circles[1].get('cx')), 100)
self.assertEqual(float(circles[1].get('cy')), 50)
def test_ordinal(self):
series = leather.Series([
('foo', 0),
('bar', 5),
('bing', 10)
])
group = self.shape.to_svg(200, 100, self.ordinal, self.linear, series, self.palette)
circles = list(group)
self.assertEqual(len(circles), 3)
self.assertEqual(float(circles[1].get('cx')), 100)
self.assertEqual(float(circles[1].get('cy')), 50)
def test_validate(self):
series = leather.Series([
(1, 1)
])
self.shape.validate_series(series)
series = leather.Series([
(1, 'foo')
])
with self.assertRaises(ValueError):
self.shape.validate_series(series)
def test_dicts(self):
data = [
{'a': 'foo', 'b': 1, 'c': 4},
{'a': 'bar', 'b': 2, 'c': 5},
{'a': 'baz', 'b': 3, 'c': 6}
]
with self.assertRaises(KeyError):
series = leather.Series(data)
series = leather.Series(data, x='c', y='a')
self.assertSequenceEqual(series.values(X), [4, 5, 6])
self.assertSequenceEqual(series.values(Y), ['foo', 'bar', 'baz'])
def test_to_svg(self):
series = leather.Series([
(0, 'foo'),
(5, 'bar'),
(10, 'bing')
])
group = self.shape.to_svg(200, 100, self.linear, self.ordinal, series, self.palette)
rects = list(group)
self.assertEqual(len(rects), 3)
self.assertEqual(float(rects[2].get('x')), 0)
self.assertEqual(float(rects[2].get('width')), 200)
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c =c
data = [
Obj('foo', 1, 4),
Obj('bar', 2, 5),
Obj('baz', 3, 6)
]
with self.assertRaises(TypeError):
series = leather.Series(data)
with self.assertRaises(TypeError):
series = leather.Series(data, x='words', y='more')
def get_x(row, i):
return row.b
def get_y(row, i):
return row.c
series = leather.Series(data, x=get_x, y=get_y)
self.assertSequenceEqual(series.values(X), [1, 2, 3])
self.assertSequenceEqual(series.values(Y), [4, 5, 6])
def test_zeros(self):
series = leather.Series([
(0, 'foo'),
(0, None),
(0, 'bing')
])
linear = leather.Linear(0, 0)
group = self.shape.to_svg(200, 100, linear, self.ordinal, series, self.palette)
rects = list(group)
self.assertEqual(len(rects), 2)
self.assertEqual(float(rects[1].get('x')), 0)
self.assertEqual(float(rects[1].get('width')), 0)
def test_custom(self):
class Obj(object):
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c =c
data = [
Obj('foo', 1, 4),
Obj('bar', 2, 5),
Obj('baz', 3, 6)
]
with self.assertRaises(TypeError):
series = leather.Series(data)
with self.assertRaises(TypeError):
series = leather.Series(data, x='words', y='more')
def get_x(row, i):
return row.b
def get_y(row, i):
return row.c
series = leather.Series(data, x=get_x, y=get_y)
self.assertSequenceEqual(series.values(X), [1, 2, 3])
self.assertSequenceEqual(series.values(Y), [4, 5, 6])
def test_dicts(self):
data = [
{'a': 'foo', 'b': 1, 'c': 4},
{'a': 'bar', 'b': 2, 'c': 5},
{'a': 'baz', 'b': 3, 'c': 6}
]
with self.assertRaises(KeyError):
series = leather.Series(data)
series = leather.Series(data, x='c', y='a')
self.assertSequenceEqual(series.values(X), [4, 5, 6])
self.assertSequenceEqual(series.values(Y), ['foo', 'bar', 'baz'])
def test_lists(self):
data = [
('foo', 1, 4),
('bar', 2, 5),
('baz', 3, 6)
]
series = leather.Series(data)
self.assertSequenceEqual(series.values(X), ['foo', 'bar', 'baz'])
self.assertSequenceEqual(series.values(Y), [1, 2, 3])
series = leather.Series(data, x=2, y=0)
self.assertSequenceEqual(series.values(X), [4, 5, 6])
self.assertSequenceEqual(series.values(Y), ['foo', 'bar', 'baz'])
with self.assertRaises(TypeError):
series = leather.Series(data, x='words')