Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/usr/bin/env python
import leather
class TestBars(leather.LeatherTestCase):
def setUp(self):
self.shape = leather.Bars('red')
self.linear = leather.Linear(0, 10)
self.ordinal = leather.Ordinal(['foo', 'bar', 'bing'])
self.palette = (color for color in ['red', 'white', 'blue'])
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)
#!/usr/bin/env python
# -*- coding: utf8 -*-
try:
import unittest2 as unittest
except ImportError:
import unittest
import leather
from agate import Table
from agate.data_types import Number, Text
class TestTableCharts(leather.LeatherTestCase):
def setUp(self):
self.rows = (
(1, 4, 'a'),
(2, 3, 'b'),
(None, 2, u'👍')
)
self.number_type = Number()
self.text_type = Text()
self.column_names = ['one', 'two', 'three']
self.column_types = [self.number_type, self.number_type, self.text_type]
self.table = Table(self.rows, self.column_names, self.column_types)
def test_bar_chart(self):
def test_ticks(self):
scale = leather.Ordinal(['a', 'b', 'c', 'd'])
self.assertEqual(scale.ticks(), ['a', 'b', 'c', 'd'])
def test_contains(self):
scale = leather.Ordinal(['a', 'b', 'c', 'd'])
self.assertTrue(scale.contains('a'))
self.assertFalse(scale.contains('aa'))
self.assertFalse(scale.contains('e'))
self.assertFalse(scale.contains(5))
class TestTemporal(leather.LeatherTestCase):
"""
Note: due to leap-year calculations, it's almost impossible to write
exact tests for this scale which are not trivial.
"""
def test_project(self):
scale = leather.Temporal(date(2010, 1, 1), date(2014, 1, 1))
self.assertAlmostEqual(scale.project(date(2011, 1, 1), 0, 20), 5, 1)
self.assertAlmostEqual(scale.project(date(2012, 1, 1), 0, 20), 10, 1)
self.assertAlmostEqual(scale.project(date(2009, 1, 1), 0, 20), -5, 1)
scale = leather.Temporal(datetime(2010, 1, 1), datetime(2014, 1, 1))
self.assertAlmostEqual(scale.project(datetime(2011, 1, 1), 0, 20), 5, 1)
self.assertAlmostEqual(scale.project(datetime(2012, 1, 1), 0, 20), 10, 1)
self.assertAlmostEqual(scale.project(datetime(2009, 1, 1), 0, 20), -5, 1)
#!/usr/bin/env python
import leather
class TestLattice(leather.LeatherTestCase):
def setUp(self):
self.data1 = [
(0, 3),
(4, 5),
(7, 9),
(8, 4)
]
self.data2 = [
(0, 4),
(1, 3),
(2, 5),
(5, 6),
(9, 10)
]
self.assertEqual(scale.project(Decimal(5), Decimal(10), Decimal(40)), Decimal(25))
self.assertEqual(scale.project(Decimal(5), Decimal(10), Decimal(41)), Decimal(25.5))
self.assertEqual(scale.ticks()[1], Decimal(2.5))
def test_contains(self):
scale = leather.Linear(-5, 5)
self.assertTrue(scale.contains(-5))
self.assertTrue(scale.contains(0))
self.assertTrue(scale.contains(5))
self.assertFalse(scale.contains(-6))
self.assertFalse(scale.contains(6))
class TestOrdinal(leather.LeatherTestCase):
def test_project(self):
scale = leather.Ordinal(['a', 'b', 'c', 'd'])
self.assertEqual(scale.project('b', 0, 20), 7.5)
scale = leather.Ordinal(['a', 'd', 'c', 'b'])
self.assertEqual(scale.project('b', 0, 20), 17.5)
def test_project_interval(self):
scale = leather.Ordinal(['a', 'b', 'c', 'd'])
self.assertEqual(scale.project_interval('b', 0, 20), (5.25, 9.75))
scale = leather.Ordinal(['a', 'd', 'c', 'b'])
from datetime import date, datetime
from decimal import Decimal
import leather
from leather.ticks.score_time import ScoreTicker, ScoreTimeTicker
from leather import utils
class TestScoreTicker(leather.LeatherTestCase):
def test_years(self):
ticker = ScoreTicker(Decimal(0), Decimal(10))
self.assertIsInstance(ticker.ticks[0], Decimal)
class TestScoreTimeTicker(leather.LeatherTestCase):
def test_years(self):
ticker = ScoreTimeTicker(
date(2010, 1, 1),
date(2015, 1, 1)
)
self.assertIsInstance(ticker.ticks[0], date)
self.assertIs(ticker._to_unit, utils.to_year_count)
def test_years_datetime(self):
ticker = ScoreTimeTicker(
datetime(2011, 1, 1),
datetime(2015, 1, 1)
)
self.assertIsInstance(ticker.ticks[0], datetime)
# -*- coding: utf8 -*-
from collections import OrderedDict
try:
import unittest2 as unittest
except ImportError:
import unittest
import leather
from agate import Table, TableSet
from agate.data_types import Number, Text
class TestTableSetCharts(leather.LeatherTestCase):
def setUp(self):
self.table1 = (
('a', 1, 4),
('b', 3, 7),
('c', 2, 2)
)
self.table2 = (
('a', 0, 3),
('b', 2, 3),
('c', 5, 3)
)
self.table3 = (
('a', 1, 10),
('b', 2, 1),
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)
class TestLine(leather.LeatherTestCase):
def setUp(self):
self.shape = leather.Line('red')
self.linear = leather.Linear(0, 10)
self.ordinal = leather.Ordinal(['foo', 'bar', 'bing'])
self.palette = (color for color in ['red', 'white', 'blue'])
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)
paths = list(group)
#!/usr/bin/env python
import os
import leather
TEST_SVG = '.test.svg'
class TestGrid(leather.LeatherTestCase):
def setUp(self):
self.data1 = [
(0, 3),
(4, 5),
(7, 9),
(8, 4)
]
self.data2 = [
(0, 4),
(1, 3),
(2, 5),
(5, 6),
(9, 10)
]
def test_validate(self):
series = leather.Series([
('foo', 1)
])
self.shape.validate_series(series)
series = leather.Series([
(1, 'foo')
])
with self.assertRaises(ValueError):
self.shape.validate_series(series)
class TestDots(leather.LeatherTestCase):
def setUp(self):
self.shape = leather.Dots('red')
self.linear = leather.Linear(0, 10)
self.ordinal = leather.Ordinal(['foo', 'bar', 'bing'])
self.palette = (color for color in ['red', 'white', 'blue'])
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)