dbt-selly/dbt-env/lib/python3.8/site-packages/leather/testcase.py

40 lines
989 B
Python

#!/usr/bin/env python
try:
import unittest2 as unittest
except ImportError:
import unittest
import six
class LeatherTestCase(unittest.TestCase):
"""
Unittest case for quickly asserting logic about charts.
"""
def render_chart(self, chart):
"""
Verify the column names in the given table match what is expected.
"""
svg = chart.to_svg()
return self.parse_svg(svg)
def parse_svg(self, text):
from lxml import etree
text = text.replace(' xmlns="http://www.w3.org/2000/svg"', '')
if six.PY3:
text = text.encode('utf-8')
return etree.fromstring(text)
def assertElementCount(self, svg, selector, count):
series = svg.cssselect(selector)
self.assertEqual(len(series), count)
def assertTickLabels(self, svg, orient, compare):
ticks = [t.text for t in svg.cssselect('.%s .tick text' % orient)]
self.assertSequenceEqual(ticks, compare)