Skip to content

Commit

Permalink
Add basic test hooks. Add tox config. Closes #7. Closes #5.
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxfish committed May 18, 2016
1 parent c906e47 commit 140b1e3
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 149 deletions.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
# command to install dependencies
install:
- if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then pip install -r requirements-py3.txt; else pip install -r requirements-py2.txt; fi
# command to run tests
script: nosetests tests
sudo: false
1 change: 0 additions & 1 deletion leather/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def to_svg(self, path, width=600, height=600, margin=None):

f.write(svg.HEADER)
f.write(ET.tostring(root, encoding='unicode'))
f.close()
finally:
if close and f is not None:
f.close()
1 change: 1 addition & 0 deletions leather/shapes/bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def to_svg(self, width, height, x_scale, y_scale, series):
Render columns to SVG elements.
"""
group = ET.Element('g')
group.set('class', 'series bars')

for x, y in series.data:
proj_x = x_scale.project(x, [0, width])
Expand Down
1 change: 1 addition & 0 deletions leather/shapes/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def to_svg(self, width, height, x_scale, y_scale, series):
Render columns to SVG elements.
"""
group = ET.Element('g')
group.set('class', 'series columns')

for x, y in series.data:
x1, x2 = x_scale.project_interval(x, [0, width])
Expand Down
1 change: 1 addition & 0 deletions leather/shapes/dots.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def to_svg(self, width, height, x_scale, y_scale, series):
Render dots to SVG elements.
"""
group = ET.Element('g')
group.set('class', 'series dots')

for x, y in series.data:
proj_x = x_scale.project(x, [0, width])
Expand Down
7 changes: 6 additions & 1 deletion leather/shapes/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def to_svg(self, width, height, x_scale, y_scale, series):
"""
Render lines to SVG elements.
"""
group = ET.Element('g')
group.set('class', 'series lines')

path = ET.Element('path',
stroke=self.color,
fill='none'
Expand All @@ -44,4 +47,6 @@ def to_svg(self, width, height, x_scale, y_scale, series):

path.set('d', ','.join(d))

return path
group.append(path)

return group
9 changes: 9 additions & 0 deletions requirements-py2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
six>=1.10.0
nose>=1.3.7
wheel>=0.24.0
lxml>=3.6.0
cssselect>=0.9.1
tox>=1.3
Sphinx>=1.2.2
coverage>=3.7.1
unittest2>=0.5.1
8 changes: 8 additions & 0 deletions requirements-py3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
six>=1.10.0
nose>=1.3.7
wheel>=0.24.0
lxml>=3.6.0
cssselect>=0.9.1
tox>=1.3
Sphinx>=1.2.2
coverage>=3.7.1
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

48 changes: 48 additions & 0 deletions tests/test_chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python

try:
import unittest2 as unittest
except ImportError:
import unittest

import leather
from tests.utils import XMLTest


class TestChart(XMLTest):
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_simple(self):
chart = leather.Chart()
chart.add_dots(self.data1)

svg = self.render_chart(chart)

self.assertElementCount(svg, '.series', 1)
self.assertElementCount(svg, '.dots', 1)
self.assertElementCount(svg, 'circle', 4)

def test_multiple(self):
chart = leather.Chart()
chart.add_dots(self.data1)
chart.add_dots(self.data2)

svg = self.render_chart(chart)

self.assertElementCount(svg, '.series', 2)
self.assertElementCount(svg, '.dots', 2)
self.assertElementCount(svg, 'circle', 9)
145 changes: 0 additions & 145 deletions tests/test_leather.py

This file was deleted.

30 changes: 30 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python

try:
import unittest2 as unittest
except ImportError:
import unittest

from lxml import etree
import six


class XMLTest(unittest.TestCase):
"""
Unittest case for quickly asserting logic about tables.
"""
def render_chart(self, chart):
"""
Verify the column names in the given table match what is expected.
"""
output = six.StringIO()
chart.to_svg(output)
text = output.getvalue()

text = text.replace(' xmlns="http://www.w3.org/2000/svg"', '')

return etree.fromstring(text)

def assertElementCount(self, svg, selector, count):
series = svg.cssselect(selector)
self.assertEqual(len(series), count)
37 changes: 37 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[tox]
envlist = py27,py33,py34,py35,pypy

[testenv]
deps=
nose>=1.1.2
six>=1.6.1
lxml>=3.6.0
cssselect>=0.9.1
commands=nosetests tests

[testenv:py27]
deps=
{[testenv]deps}

[testenv:py33]
deps=
{[testenv]deps}

[testenv:py34]
deps=
{[testenv:py33]deps}

[testenv:py35]
deps=
{[testenv:py33]deps}

[testenv:pypy]
deps=
{[testenv:py27]deps}

[flake8]
ignore=E128,E402,E501,F403
# E128 continuation line under-indented for visual indent
# E402 module level import not at top of file
# E501 line too long (X > 79 characters)
# F403 'from xyz import *' used; unable to detect undefined names

0 comments on commit 140b1e3

Please sign in to comment.