|
@@ -16,10 +16,50 @@ import collections
|
|
|
import re
|
|
|
|
|
|
|
|
|
+def fnmatch_exclude_with_base(files, base, exclude):
|
|
|
+ """Return list of files not matching any exclusion pattern
|
|
|
+
|
|
|
+ :param files: list of file names
|
|
|
+ :param base: directory (path) where the files are
|
|
|
+ :param exclude: list of fnmatch glob patterns for exclusion
|
|
|
+ """
|
|
|
+ not_excluded = []
|
|
|
+ patterns = []
|
|
|
+ # Make all dir separators slashes and drop leading current dir
|
|
|
+ # for both patterns and (later) for files.
|
|
|
+ for pattern in exclude:
|
|
|
+ pattern = pattern.replace(os.sep, "/")
|
|
|
+ if pattern.startswith("./"):
|
|
|
+ patterns.append(pattern[2:])
|
|
|
+ else:
|
|
|
+ patterns.append(pattern)
|
|
|
+ for filename in files:
|
|
|
+ full_file_path = os.path.join(base, filename)
|
|
|
+ test_filename = full_file_path.replace(os.sep, "/")
|
|
|
+ if full_file_path.startswith("./"):
|
|
|
+ test_filename = full_file_path[2:]
|
|
|
+ matches = False
|
|
|
+ for pattern in patterns:
|
|
|
+ if fnmatch.fnmatch(test_filename, pattern):
|
|
|
+ matches = True
|
|
|
+ break
|
|
|
+ if not matches:
|
|
|
+ not_excluded.append(filename)
|
|
|
+ return not_excluded
|
|
|
+
|
|
|
+
|
|
|
# TODO: resolve test file versus test module
|
|
|
GrassTestPythonModule = collections.namedtuple(
|
|
|
"GrassTestPythonModule",
|
|
|
- ["name", "module", "file_type", "tested_dir", "file_dir", "abs_file_path"],
|
|
|
+ [
|
|
|
+ "name",
|
|
|
+ "module",
|
|
|
+ "file_type",
|
|
|
+ "tested_dir",
|
|
|
+ "file_dir",
|
|
|
+ "file_path",
|
|
|
+ "abs_file_path",
|
|
|
+ ],
|
|
|
)
|
|
|
|
|
|
|
|
@@ -35,6 +75,7 @@ def discover_modules(
|
|
|
add_failed_imports=True,
|
|
|
file_pattern=None,
|
|
|
file_regexp=None,
|
|
|
+ exclude=None,
|
|
|
):
|
|
|
"""Find all test files (modules) in a directory tree.
|
|
|
|
|
@@ -80,6 +121,8 @@ def discover_modules(
|
|
|
files = fnmatch.filter(all_files, file_pattern)
|
|
|
if file_regexp:
|
|
|
files = [f for f in all_files if re.match(file_regexp, f)]
|
|
|
+ if exclude:
|
|
|
+ files = fnmatch_exclude_with_base(files, full, exclude)
|
|
|
files = sorted(files)
|
|
|
# get test/module name without .py
|
|
|
# extpecting all files to end with .py
|
|
@@ -146,6 +189,7 @@ def discover_modules(
|
|
|
tested_dir=root,
|
|
|
file_dir=full,
|
|
|
abs_file_path=abs_file_path,
|
|
|
+ file_path=os.path.join(full, file_name),
|
|
|
file_type=file_type,
|
|
|
)
|
|
|
)
|
|
@@ -158,7 +202,7 @@ def discover_modules(
|
|
|
class GrassTestLoader(unittest.TestLoader):
|
|
|
"""Class handles GRASS-specific loading of test modules."""
|
|
|
|
|
|
- skip_dirs = [".svn", "dist.*", "bin.*", "OBJ.*"]
|
|
|
+ skip_dirs = [".git", ".svn", "dist.*", "bin.*", "OBJ.*"]
|
|
|
testsuite_dir = "testsuite"
|
|
|
files_in_testsuite = "*.py"
|
|
|
all_tests_value = "all"
|