mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add setup.py command to run unit tests.
Use "python setup.py test" to run unit tests.
This commit is contained in:
parent
57a68859ba
commit
1e1e80955c
1 changed files with 48 additions and 0 deletions
48
setup.py
48
setup.py
|
@ -4,6 +4,9 @@ The setup script for salt
|
||||||
'''
|
'''
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import unittest
|
||||||
|
from distutils import log
|
||||||
|
from distutils.cmd import Command
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
from distutils.extension import Extension
|
from distutils.extension import Extension
|
||||||
from distutils.sysconfig import get_python_lib, PREFIX
|
from distutils.sysconfig import get_python_lib, PREFIX
|
||||||
|
@ -21,8 +24,53 @@ if os.environ.has_key('SYSCONFDIR'):
|
||||||
else:
|
else:
|
||||||
etc_path = os.path.join(os.path.dirname(PREFIX), 'etc')
|
etc_path = os.path.join(os.path.dirname(PREFIX), 'etc')
|
||||||
|
|
||||||
|
class UnitTest(Command):
|
||||||
|
description = "run unit tests"
|
||||||
|
user_options = []
|
||||||
|
|
||||||
|
def initialize_options(self):
|
||||||
|
self.test_dirs = None
|
||||||
|
|
||||||
|
def finalize_options(self):
|
||||||
|
if self.test_dirs is None:
|
||||||
|
self.test_dirs = ["test"]
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
errors = 0
|
||||||
|
failures = 0
|
||||||
|
for path in self.test_dirs:
|
||||||
|
for root, dirs, files in os.walk(path):
|
||||||
|
for filename in files:
|
||||||
|
if filename.startswith("test_") and \
|
||||||
|
filename.endswith(".py"):
|
||||||
|
results = self._run_test(os.path.join(root, filename))
|
||||||
|
errors += results[0]
|
||||||
|
failures += results[1]
|
||||||
|
self.announce(
|
||||||
|
"unit test: {} errors and {} failures".format(errors, failures),
|
||||||
|
level=log.INFO)
|
||||||
|
|
||||||
|
def _run_test(self, path):
|
||||||
|
self.announce("run tests in " + path, log.INFO)
|
||||||
|
dirname, basename = os.path.split(path)
|
||||||
|
sys.path.insert(0, dirname)
|
||||||
|
try:
|
||||||
|
modname = os.path.splitext(basename)[0]
|
||||||
|
mod = __import__(modname)
|
||||||
|
if hasattr(mod, "test_suite"):
|
||||||
|
suite = mod.test_suite()
|
||||||
|
runner = unittest.TextTestRunner(verbosity=2)
|
||||||
|
results = runner.run(suite)
|
||||||
|
return len(results.errors), len(results.failures)
|
||||||
|
else:
|
||||||
|
return (0, 0)
|
||||||
|
finally:
|
||||||
|
if sys.path[0] == dirname:
|
||||||
|
del sys.path[0]
|
||||||
|
|
||||||
setup(name=NAME,
|
setup(name=NAME,
|
||||||
version=VER,
|
version=VER,
|
||||||
|
cmdclass={"test":UnitTest},
|
||||||
description=DESC,
|
description=DESC,
|
||||||
author='Thomas S Hatch',
|
author='Thomas S Hatch',
|
||||||
author_email='thatch45@gmail.com',
|
author_email='thatch45@gmail.com',
|
||||||
|
|
Loading…
Add table
Reference in a new issue