Skip to content

Commit

Permalink
distribute tests within source package
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtepkeev committed Nov 7, 2015
1 parent 9d5ec89 commit b2a29f2
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
0.5.3 (2015-11-XX)
++++++++++++++++++

- Added: Tests are now built-in into source package distributed via PyPI
- Fixed: Django: `Issue #21 <https://github.com/maxtepkeev/architect/issues/21>`__ (Unable to partition a
model with non-lazy translations)

Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
recursive-include tests *.py
include README.rst CHANGELOG.rst LICENSE NOTICE
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[nosetests]
with-coverage=1
cover-erase=1
cover-package=architect

[bdist_wheel]
universal=1
52 changes: 50 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
import os
import sys

from setuptools import setup, find_packages
from setuptools.command.test import test, DistutilsOptionError

for name in ('multiprocessing', 'pony'): # https://bugs.python.org/issue15881
try:
__import__(name)
except ImportError:
pass


class NoseTests(test):
user_options = test.user_options + [
('orm=', None, 'Sets ORM to run tests for'), ('db=', None, 'Sets DB to be used by ORM')]

def initialize_options(self):
test.initialize_options(self)
self.db = None
self.orm = None

def finalize_options(self):
test.finalize_options(self)
self.test_args = []
self.test_suite = True
if self.orm is not None:
if self.db is None:
raise DistutilsOptionError("--orm option can't be used without --db option")
os.environ['DB'] = self.db
os.environ[self.orm.upper()] = '1'

def run_tests(self):
import nose
nose.run(argv=['nosetests'])
if self.orm is not None:
del os.environ['DB']
del os.environ[self.orm.upper()]

tests_require = ['nose', 'coverage']

if sys.version_info[:2] < (3, 3):
tests_require.append('mock')
if sys.version_info[:2] == (3, 2):
tests_require[1] = 'coverage<4.0'
if sys.version_info[:2] == (2, 6):
tests_require.append('unittest2')

exec(open('architect/version.py').read())

Expand All @@ -7,19 +53,21 @@
try:
import argparse
except ImportError:
requirements.append('argparse >= 1.2.1')
requirements.append('argparse>=1.2.1')

setup(
name='architect',
version=globals()['__version__'],
packages=find_packages(exclude=('tests', 'tests.*')),
packages=find_packages(exclude=('tests',)),
url='https://github.com/maxtepkeev/architect',
license=open('LICENSE').read(),
author='Max Tepkeev',
author_email='[email protected]',
description='A set of tools which enhances ORMs written in Python with more features',
long_description=open('README.rst').read() + '\n\n' + open('CHANGELOG.rst').read(),
keywords='architect,django,pony,peewee,sqlalchemy,sqlobject,partition,partitioning,database,table',
tests_require=tests_require,
cmdclass={'test': NoseTests},
zip_safe=False,
install_requires=requirements,
entry_points={'console_scripts': ['architect = architect.commands:main']},
Expand Down
10 changes: 10 additions & 0 deletions tests/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ unittest package so you don't need to install it. For Python 2.6 you also need t
.. code-block:: bash
$ nosetests --with-coverage --cover-erase --cover-package=architect
Alternatively, starting from v0.5.3 you can use

.. code-block:: bash
$ python setup.py test --orm=ORM --db=DB
where ORM is one of the supported ORMs (django, peewee, pony, sqlalchemy, sqlobject) and DB is one
of the supported databases (mysql, postgresql, sqlite). Using the above command will automatically
install all the needed dependencies needed for running tests, so you don't have to do it by hand.

0 comments on commit b2a29f2

Please sign in to comment.