Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from extras import safe_hasattr
from testtools import TextTestResult
from testtools.compat import classtypes, istext, unicode_output_stream
from testtools.testsuite import filter_by_ids, iterate_tests, sorted_tests
defaultTestLoader = unittest.defaultTestLoader
defaultTestLoaderCls = unittest.TestLoader
if getattr(defaultTestLoader, 'discover', None) is None:
try:
import discover
defaultTestLoader = discover.DiscoveringTestLoader()
defaultTestLoaderCls = discover.DiscoveringTestLoader
have_discover = True
except ImportError:
have_discover = False
else:
have_discover = True
def list_test(test):
"""Return the test ids that would be run if test() was run.
When things fail to import they can be represented as well, though
we use an ugly hack (see http://bugs.python.org/issue19746 for details)
to determine that. The difference matters because if a user is
filtering tests to run on the returned ids, a failed import can reduce
the visible tests but it can be impossible to tell that the selected
test would have been one of the imported ones.
import sys
from extras import safe_hasattr
from testtools import TextTestResult
from testtools.compat import classtypes, istext, unicode_output_stream
from testtools.testsuite import filter_by_ids, iterate_tests, sorted_tests
defaultTestLoader = unittest.defaultTestLoader
defaultTestLoaderCls = unittest.TestLoader
if getattr(defaultTestLoader, 'discover', None) is None:
try:
import discover
defaultTestLoader = discover.DiscoveringTestLoader()
defaultTestLoaderCls = discover.DiscoveringTestLoader
have_discover = True
except ImportError:
have_discover = False
else:
have_discover = True
def list_test(test):
"""Return the test ids that would be run if test() was run.
When things fail to import they can be represented as well, though
we use an ugly hack (see http://bugs.python.org/issue19746 for details)
to determine that. The difference matters because if a user is
filtering tests to run on the returned ids, a failed import can reduce
the visible tests but it can be impossible to tell that the selected
import os
import unittest
import sys
from testtools import TextTestResult
from testtools.compat import classtypes, istext, unicode_output_stream
from testtools.testsuite import iterate_tests, sorted_tests
defaultTestLoader = unittest.defaultTestLoader
defaultTestLoaderCls = unittest.TestLoader
if getattr(defaultTestLoader, 'discover', None) is None:
try:
import discover
defaultTestLoader = discover.DiscoveringTestLoader()
defaultTestLoaderCls = discover.DiscoveringTestLoader
have_discover = True
except ImportError:
have_discover = False
else:
have_discover = True
class TestToolsTestRunner(object):
""" A thunk object to support unittest.TestProgram."""
def __init__(self, verbosity=None, failfast=None, buffer=None):
"""Create a TestToolsTestRunner.
:param verbosity: Ignored.
:param failfast: Stop running tests at the first failure.
import unittest
import sys
from testtools import TextTestResult
from testtools.compat import classtypes, istext, unicode_output_stream
from testtools.testsuite import iterate_tests, sorted_tests
defaultTestLoader = unittest.defaultTestLoader
defaultTestLoaderCls = unittest.TestLoader
if getattr(defaultTestLoader, 'discover', None) is None:
try:
import discover
defaultTestLoader = discover.DiscoveringTestLoader()
defaultTestLoaderCls = discover.DiscoveringTestLoader
have_discover = True
except ImportError:
have_discover = False
else:
have_discover = True
class TestToolsTestRunner(object):
""" A thunk object to support unittest.TestProgram."""
def __init__(self, verbosity=None, failfast=None, buffer=None):
"""Create a TestToolsTestRunner.
:param verbosity: Ignored.
:param failfast: Stop running tests at the first failure.
:param buffer: Ignored.
def get_tests():
start_dir = os.path.dirname(__file__)
test_loader = DiscoveringTestLoader()
return test_loader.discover(start_dir, pattern="*.py")
def main(argv=None, testRunner=None, testLoader=None, exit=True, verbosity=1):
if testLoader is None:
testLoader = DiscoveringTestLoader
if testRunner is None:
testRunner = unittest.TextTestRunner
if argv is None:
argv = sys.argv[1:]
tests, verbosity = _do_discovery(argv, verbosity, testLoader)
return _run_tests(tests, testRunner, verbosity, exit)
except TypeError:
yield test_suite_or_case
else:
for test in suite:
for subtest in iterate_tests(test):
yield subtest
defaultTestLoader = unittest.defaultTestLoader
defaultTestLoaderCls = unittest.TestLoader
if getattr(defaultTestLoader, 'discover', None) is None:
try:
import discover
defaultTestLoader = discover.DiscoveringTestLoader()
defaultTestLoaderCls = discover.DiscoveringTestLoader
have_discover = True
except ImportError:
have_discover = False
else:
have_discover = True
####################
# Taken from python 2.7 and slightly modified for compatibility with
# older versions. Delete when 2.7 is the oldest supported version.
# Modifications:
# - Use have_discover to raise an error if the user tries to use
# discovery on an old version and doesn't have discover installed.
# - If --catch is given check that installHandler is available, as
# it won't be on old python versions.
# - print calls have been been made single-source python3 compatibile.
suite = iter(test_suite_or_case)
except TypeError:
yield test_suite_or_case
else:
for test in suite:
for subtest in iterate_tests(test):
yield subtest
defaultTestLoader = unittest.defaultTestLoader
defaultTestLoaderCls = unittest.TestLoader
if getattr(defaultTestLoader, 'discover', None) is None:
try:
import discover
defaultTestLoader = discover.DiscoveringTestLoader()
defaultTestLoaderCls = discover.DiscoveringTestLoader
have_discover = True
except ImportError:
have_discover = False
else:
have_discover = True
####################
# Taken from python 2.7 and slightly modified for compatibility with
# older versions. Delete when 2.7 is the oldest supported version.
# Modifications:
# - Use have_discover to raise an error if the user tries to use
# discovery on an old version and doesn't have discover installed.
# - If --catch is given check that installHandler is available, as
# it won't be on old python versions.