File: testcase.py

package info (click to toggle)
python-leather 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 652 kB
  • sloc: python: 2,385; makefile: 117; sh: 5
file content (29 lines) | stat: -rw-r--r-- 847 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import unittest


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"', '').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)