You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.3 KiB
Python

5 years ago
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import nose
from nose.plugins.manager import PluginManager
from nose.plugins.doctests import Doctest
from nose.plugins import builtin
NLTK_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
5 years ago
sys.path.insert(0, NLTK_ROOT)
NLTK_TEST_DIR = os.path.join(NLTK_ROOT, "nltk")
5 years ago
if __name__ == "__main__":
5 years ago
# there shouldn't be import from NLTK for coverage to work properly
try:
# Import RedNose plugin for colored test output
from rednose import RedNose
rednose_available = True
except ImportError:
rednose_available = False
class NltkPluginManager(PluginManager):
"""
Nose plugin manager that replaces standard doctest plugin
with a patched version and adds RedNose plugin for colored test output.
"""
def loadPlugins(self):
for plug in builtin.plugins:
self.addPlugin(plug())
5 years ago
if rednose_available:
self.addPlugin(RedNose())
super(NltkPluginManager, self).loadPlugins()
manager = NltkPluginManager()
manager.loadPlugins()
# allow passing extra options and running individual tests
# Examples:
#
# python runtests.py semantics.doctest
# python runtests.py --with-id -v
# python runtests.py --with-id -v nltk.featstruct
args = sys.argv[1:]
if not args:
args = [NLTK_TEST_DIR]
if all(arg.startswith("-") for arg in args):
5 years ago
# only extra options were passed
args += [NLTK_TEST_DIR]
# Activate RedNose and hide skipped test messages from output
if rednose_available:
args += ["--rednose", "--hide-skips"]
5 years ago
arguments = [
"--exclude=", # why is this needed?
5 years ago
# '--with-xunit',
# '--xunit-file=$WORKSPACE/nosetests.xml',
# '--nocapture',
"--with-doctest",
5 years ago
# '--doctest-tests',
# '--debug=nose,nose.importer,nose.inspector,nose.plugins,nose.result,nose.selector',
"--doctest-extension=.doctest",
"--doctest-fixtures=_fixt",
"--doctest-options=+ELLIPSIS,+NORMALIZE_WHITESPACE,+IGNORE_EXCEPTION_DETAIL",
5 years ago
# '--verbosity=3',
] + args
nose.main(argv=arguments, plugins=manager.plugins)