diff --git a/.gitignore b/.gitignore index 9d3808a..c8637aa 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,7 @@ $~ # temporary data temp + +# packaging and testing +.tox/ +*.egg-info/ diff --git a/setup.py b/setup.py index e031c85..eba6372 100755 --- a/setup.py +++ b/setup.py @@ -1,6 +1,35 @@ #!/usr/bin/python -from distutils.core import setup +import os +import sys +from setuptools import setup +from setuptools.command.test import test as TestCommand + +def read(fname): + """read file from same path as setup.py""" + return open(os.path.join(os.path.dirname(__file__), fname)).read() + +class Tox(TestCommand): + user_options = [('tox-args=', 'a', "Arguments to pass to tox")] + + def initialize_options(self): + TestCommand.initialize_options(self) + self.tox_args = None + + def finalize_options(self): + TestCommand.finalize_options(self) + self.test_args = [] + self.test_suite = True + + def run_tests(self): + #import here, cause outside the eggs aren't loaded + import tox + import shlex + args = self.tox_args + if args: + args = shlex.split(self.tox_args) + errno = tox.cmdline(args=args) + sys.exit(errno) setup( name='escpos', @@ -9,7 +38,7 @@ setup( download_url='https://github.com/manpaz/python-escpos.git', description='Python library to manipulate ESC/POS Printers', license='GNU GPL v3', - long_description=open('README').read(), + long_description=read('README'), author='Manuel F Martinez', author_email='manpaz@bashlinux.com', platforms=['linux'], @@ -32,4 +61,6 @@ setup( 'qrcode>=4.0', 'pyserial', ], + tests_require=['tox'], + cmdclass={'test': Tox}, ) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..880e6cc --- /dev/null +++ b/tox.ini @@ -0,0 +1,7 @@ +[tox] +envlist = py27, py34 + +[testenv] +deps = nose + coverage +# TODO: implement code coverage analysis (and of course tests at first)