diff --git a/setup.py b/setup.py index 4355fa9..8931515 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- import os +import sys from setuptools import setup +from setuptools.command.test import test as TestCommand # Utility function to read the README file. # Used for the long_description. It's nice, because now @@ -9,6 +11,17 @@ from setuptools import setup def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() +class PyTest(TestCommand): + def finalize_options(self): + TestCommand.finalize_options(self) + self.test_args = [] + self.test_suite = True + + def run_tests(self): + import pytest + errno = pytest.main(self.test_args) + sys.exit(errno) + setup( name='secretary', version='0.0.1', @@ -24,6 +37,9 @@ setup( install_requires=[ 'Jinja2', ], + tests_require=['pytest'], + cmdclass={'test': PyTest}, + test_suite='test_secretary', classifiers=[ 'Environment :: Web Environment', 'Intended Audience :: End Users/Desktop', @@ -33,5 +49,8 @@ setup( 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Office/Business', 'Topic :: Utilities', - ] + ], + extras_require={ + 'testing': ['pytest'] + } ) diff --git a/test_secretary.py b/test_secretary.py new file mode 100644 index 0000000..759b5c7 --- /dev/null +++ b/test_secretary.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +import os +from xml.dom.minidom import getDOMImplementation +from unittest import TestCase +from secretary import UndefinedSilently, pad_string, Render + +def test_undefined_silently(): + undefined = UndefinedSilently() + + assert isinstance(undefined(), UndefinedSilently) + assert isinstance(undefined.attribute, UndefinedSilently) + assert unicode(undefined) == u'' + assert str(undefined) == '' + +def test_pad_string(): + assert pad_string('TEST') == '0TEST' + assert pad_string('TEST', 4) == 'TEST' + assert pad_string(1) == '00001' + +class RenderTestCase(TestCase): + def setUp(self): + root = os.path.dirname(__file__) + impl = getDOMImplementation() + template = os.path.join(root, 'simple_template.odt') + + self.document = impl.createDocument(None, "some_tag", None) + self.render = Render(template) + + def test_create_test_node(self): + assert self.render.create_text_node(self.document, 'text').toxml() == 'text' + + def test_create_text_span_node(self): + assert self.render.create_text_span_node(self.document, 'text').toxml() == 'text' +