de-nova the test runner

This commit is contained in:
Jason Kölker 2011-11-01 12:56:44 -05:00
parent adf11f731c
commit 3db4d8dc3b
2 changed files with 29 additions and 27 deletions

View File

@ -57,19 +57,18 @@ To run a single test module:
import gettext import gettext
import heapq import heapq
import logging
import os import os
import unittest import unittest
import sys import sys
import time import time
gettext.install('nova', unicode=1) gettext.install('melange', unicode=1)
from nose import config from nose import config
from nose import core from nose import core
from nose import result from nose import result
from nova import log as logging
class _AnsiColorizer(object): class _AnsiColorizer(object):
""" """
@ -193,7 +192,7 @@ def get_elapsed_time_color(elapsed_time):
return 'green' return 'green'
class NovaTestResult(result.TextTestResult): class MelangeTestResult(result.TextTestResult):
def __init__(self, *args, **kw): def __init__(self, *args, **kw):
self.show_elapsed = kw.pop('show_elapsed') self.show_elapsed = kw.pop('show_elapsed')
result.TextTestResult.__init__(self, *args, **kw) result.TextTestResult.__init__(self, *args, **kw)
@ -304,17 +303,17 @@ class NovaTestResult(result.TextTestResult):
self.stream.flush() self.stream.flush()
class NovaTestRunner(core.TextTestRunner): class MelangeTestRunner(core.TextTestRunner):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.show_elapsed = kwargs.pop('show_elapsed') self.show_elapsed = kwargs.pop('show_elapsed')
core.TextTestRunner.__init__(self, *args, **kwargs) core.TextTestRunner.__init__(self, *args, **kwargs)
def _makeResult(self): def _makeResult(self):
return NovaTestResult(self.stream, return MelangeTestResult(self.stream,
self.descriptions, self.descriptions,
self.verbosity, self.verbosity,
self.config, self.config,
show_elapsed=self.show_elapsed) show_elapsed=self.show_elapsed)
def _writeSlowTests(self, result_): def _writeSlowTests(self, result_):
# Pare out 'fast' tests # Pare out 'fast' tests
@ -336,28 +335,33 @@ class NovaTestRunner(core.TextTestRunner):
if __name__ == '__main__': if __name__ == '__main__':
logging.setup() logger = logging.getLogger()
# If any argument looks like a test name but doesn't have "nova.tests" in hdlr = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.DEBUG)
# If any argument looks like a test name but doesn't have "melange.tests" in
# front of it, automatically add that so we don't have to type as much # front of it, automatically add that so we don't have to type as much
show_elapsed = True show_elapsed = True
argv = [] argv = []
for x in sys.argv: for x in sys.argv:
if x.startswith('test_'): if x.startswith('test_'):
argv.append('nova.tests.%s' % x) argv.append('melange.tests.%s' % x)
elif x.startswith('--hide-elapsed'): elif x.startswith('--hide-elapsed'):
show_elapsed = False show_elapsed = False
else: else:
argv.append(x) argv.append(x)
testdir = os.path.abspath(os.path.join("nova", "tests")) testdir = os.path.abspath(os.path.join("melange", "tests"))
c = config.Config(stream=sys.stdout, c = config.Config(stream=sys.stdout,
env=os.environ, env=os.environ,
verbosity=3, verbosity=3,
workingDir=testdir, workingDir=testdir,
plugins=core.DefaultPluginManager()) plugins=core.DefaultPluginManager())
runner = NovaTestRunner(stream=c.stream, runner = MelangeTestRunner(stream=c.stream,
verbosity=c.verbosity, verbosity=c.verbosity,
config=c, config=c,
show_elapsed=show_elapsed) show_elapsed=show_elapsed)
sys.exit(not core.run(config=c, testRunner=runner, argv=argv)) sys.exit(not core.run(config=c, testRunner=runner, argv=argv))

View File

@ -4,7 +4,7 @@ set -eu
function usage { function usage {
echo "Usage: $0 [OPTION]..." echo "Usage: $0 [OPTION]..."
echo "Run Nova's test suite(s)" echo "Run Melange's test suite(s)"
echo "" echo ""
echo " -V, --virtual-env Always use virtualenv. Install automatically if not present" echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment" echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
@ -40,7 +40,7 @@ function process_option {
esac esac
} }
venv=.nova-venv venv=.melange-venv
with_venv=tools/with_venv.sh with_venv=tools/with_venv.sh
always_venv=0 always_venv=0
never_venv=0 never_venv=0
@ -57,9 +57,9 @@ for arg in "$@"; do
process_option $arg process_option $arg
done done
# If enabled, tell nose to collect coverage data # If enabled, tell nose to collect coverage data
if [ $coverage -eq 1 ]; then if [ $coverage -eq 1 ]; then
noseopts="$noseopts --with-coverage --cover-package=nova" noseopts="$noseopts --with-coverage --cover-package=melange"
fi fi
function run_tests { function run_tests {
@ -81,14 +81,12 @@ function run_tests {
function run_pep8 { function run_pep8 {
echo "Running pep8 ..." echo "Running pep8 ..."
# Opt-out files from pep8 # Opt-out files from pep8
ignore_scripts="*.sh:*nova-debug:*clean-vlans" ignore_scripts="*.sh:*melange-debug:*clean-vlans"
ignore_files="*eventlet-patch:*pip-requires" ignore_files="*eventlet-patch:*pip-requires"
ignore_dirs="*ajaxterm*"
GLOBIGNORE="$ignore_scripts:$ignore_files:$ignore_dirs" GLOBIGNORE="$ignore_scripts:$ignore_files:$ignore_dirs"
srcfiles=`find bin -type f ! -name "nova.conf*"` srcfiles=`find bin -type f ! -name "melange.conf*"`
srcfiles+=" `find tools/*`" srcfiles+=" `find tools/*`"
srcfiles+=" nova setup.py plugins/xenserver/xenapi/etc/xapi.d/plugins/glance" srcfiles+=" setup.py bin"
srcfiles+=" bin melange"
# Just run PEP8 in current environment # Just run PEP8 in current environment
# #
# NOTE(sirp): W602 (deprecated 3-arg raise) is being ignored for the # NOTE(sirp): W602 (deprecated 3-arg raise) is being ignored for the