Commit ff14fddc authored by eckhart's avatar eckhart

- small refactorings

parent e459a8d5
......@@ -586,7 +586,7 @@ def run_test_function(func_name, namespace):
exec(func_name + '()', namespace)
def runner(test_classes, namespace):
def runner(tests, namespace):
"""
Runs all or some selected Python unit tests found in the
namespace. To run all tests in a module, call
......@@ -597,10 +597,12 @@ def runner(test_classes, namespace):
in such classes or functions, the name of which starts with "test".
Args:
test_classes: Either a string or a list of strings that contains
the names of test or test classes. Each test and, in the case
of a test class, all tests within the test class will be
run.
tests: String or list of strings with the names of tests to
run. If empty, runner searches by itself all objects the
of which starts with 'test' and runs it (if its a function)
or all of its methods that start with "test" if its a class
plus the "setup" and "teardown" methods if they exist.
namespace: The namespace for running the test, usually
``globals()`` should be used.
......@@ -617,21 +619,22 @@ def runner(test_classes, namespace):
from DHParser.testing import runner
runner("", globals())
"""
test_classes = []
test_functions = []
if test_classes:
if isinstance(test_classes, str):
test_classes = test_classes.split(" ")
if tests:
if isinstance(tests, str):
tests = tests.split(' ')
assert all(test.lower().startswith('test') for test in tests)
else:
# collect all test classes, in case no methods or classes have been passed explicitly
test_classes = []
test_functions = []
for name in namespace.keys():
if name.lower().startswith('test'):
if inspect.isclass(namespace[name]):
test_classes.append(name)
elif inspect.isfunction(namespace[name]):
test_functions.append(name)
tests = namespace.keys()
for name in tests:
if name.lower().startswith('test'):
if inspect.isclass(namespace[name]):
test_classes.append(name)
elif inspect.isfunction(namespace[name]):
test_functions.append(name)
for test in test_classes:
run_tests_in_class(test, namespace)
......
#cython: infer_types=True
#cython: language_level=3
#cython: c_string_type=unicode
#cython: c_string_encoding=utf-8
......@@ -46,8 +46,9 @@ from typing import Any, Iterable, Sequence, Set, Union, Dict, Hashable, cast
try:
import cython
cython_optimized = cython.compiled # type: bool
if cython_optimized:
import DHParser.shadow_cython as cython
except ImportError:
# import DHParser.Shadow as cython
cython_optimized = False # type: bool
import DHParser.shadow_cython as cython
......
......@@ -15,7 +15,8 @@ setup(
name='DHParser',
version=__version__,
packages=['DHParser'],
ext_modules=cythonize(['DHParser/stringview.py',
ext_modules=cythonize(['DHParser/toolkit.py',
'DHParser/stringview.py',
'DHParser/preprocess.py',
'DHParser/error.py',
'DHParser/syntaxtree.py',
......
......@@ -7,8 +7,8 @@ import doctest
import multiprocessing
import os
import platform
import subprocess
import sys
#import subprocess
#import sys
import time
import threading
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment