| Index: expect_tests/pipeline.py
|
| diff --git a/expect_tests/pipeline.py b/expect_tests/pipeline.py
|
| index a82f49de4b13c04159fd08bda8c4bba1744e66dd..9eb5ade27ba3130fef50612cb8145edaabb0201b 100644
|
| --- a/expect_tests/pipeline.py
|
| +++ b/expect_tests/pipeline.py
|
| @@ -2,13 +2,14 @@
|
| # Use of this source code is governed by a BSD-style license that can be
|
| # found in the LICENSE file.
|
|
|
| -import Queue
|
| +import ConfigParser
|
| import glob
|
| import imp
|
| import inspect
|
| import logging
|
| import multiprocessing
|
| import os
|
| +import Queue
|
| import re
|
| import signal
|
| import sys
|
| @@ -26,6 +27,9 @@ from expect_tests.unittest_helper import _is_unittest, UnittestTestCase
|
| from expect_tests import util
|
|
|
|
|
| +CONFIG_FILE_NAME = '.expect_tests.cfg'
|
| +
|
| +
|
| class ResetableStringIO(object):
|
| def __init__(self):
|
| self._stream = StringIO()
|
| @@ -55,29 +59,35 @@ def get_package_path(package_name, path):
|
| return os.path.normpath(package_path) if ispkg else None
|
|
|
|
|
| -def get_blacklist(path):
|
| - """Get blacklisted subdirectories
|
| +def get_config(path):
|
| + """Get configuration values
|
|
|
| - Reads the file called __expect_tests_skip in provided path, remove
|
| - comments, and returns content.
|
| + Reads the config file in provided path, and returns content.
|
| + See Python ConfigParser for general formatting syntax.
|
|
|
| - A comment starts with #, on its own line (no trailing comment).
|
| + Example:
|
| + [expect_tests]
|
| + skip=directory1
|
| + directory2
|
| + directory3
|
|
|
| Args:
|
| path (str): path to a directory.
|
|
|
| Returns:
|
| - blacklist (set of str): name of blacklisted subdirectories.
|
| + black_list (set): blacklisted subdirectories.
|
| """
|
| black_list = set()
|
| - black_list_filename = os.path.join(path, '__expect_tests_skip')
|
| - if os.path.isfile(black_list_filename):
|
| - with open(black_list_filename, 'r') as f:
|
| - for line in f:
|
| - stripped = line.strip()
|
| - if stripped and not stripped.startswith('#'):
|
| - black_list.add(stripped)
|
|
|
| + config_file_name = os.path.join(path, CONFIG_FILE_NAME)
|
| + parser = ConfigParser.ConfigParser()
|
| + parser.read([config_file_name])
|
| +
|
| + if not parser.has_section('expect_tests'):
|
| + return black_list
|
| +
|
| + if parser.has_option('expect_tests', 'skip'):
|
| + black_list.update(parser.get('expect_tests', 'skip').splitlines())
|
| return black_list
|
|
|
|
|
| @@ -94,7 +104,7 @@ def is_test_file(filename):
|
|
|
|
|
| def walk_package(package_name, path):
|
| - """Yield all test files inside a single package.
|
| + """Return all test files inside a single package.
|
|
|
| In all cases, this function returns the full package name of files ending
|
| in '_test.py' found either under the package called <package_name>.
|
| @@ -103,7 +113,7 @@ def walk_package(package_name, path):
|
| Provided that <path> is in sys.path, calling __import__ with one of the
|
| strings returned by this function works.
|
|
|
| - If a __expect_tests_skip file is present somewhere in the search hierarchy,
|
| + If a config file is present somewhere in the search hierarchy,
|
| it is interpreted as a list of subdirectories to ignore. This is the way to
|
| make this function ignore some subpackages.
|
|
|
| @@ -115,6 +125,15 @@ def walk_package(package_name, path):
|
| It is not necessary to change sys.path for the present function to work (it
|
| does not actually import anything).
|
|
|
| + Args:
|
| + package_name (str): name of the package, as expected by import.
|
| + path (str): path containing the above module (optional)
|
| +
|
| + Returns:
|
| + test_modules (list of str): name of modules containing tests. Each element is
|
| + a period-separated string ending with '_test',
|
| + e.g. shiny_package.subpackage.feature_test
|
| +
|
| Example:
|
| modules = walk_package('shiny_package', 'some/directory')
|
| sys.path.insert(0, 'some/directory')
|
| @@ -122,13 +141,10 @@ def walk_package(package_name, path):
|
|
|
| the first line assumes that the directory 'some/directory' is in the
|
| current working directory.
|
| -
|
| - modules[0] is a period-separated string ending with '_test',
|
| - e.g. shiny_package.subpackage.feature_test
|
| """
|
| assert package_name, 'walk_package needs a package_name.'
|
|
|
| - ret = []
|
| + test_modules = []
|
| package_path = get_package_path(package_name, path)
|
| assert package_path, 'no package found.'
|
|
|
| @@ -137,19 +153,19 @@ def walk_package(package_name, path):
|
|
|
| for dirpath, dirnames, filenames in os.walk(package_path):
|
| # Keep only submodules not blacklisted
|
| - blacklist = get_blacklist(dirpath)
|
| -
|
| + blacklist = get_config(dirpath)
|
| dirnames[:] = [d for d in dirnames
|
| if d not in blacklist and
|
| os.path.isfile(os.path.join(dirpath, d, '__init__.py'))]
|
|
|
| assert dirpath.startswith(package_path)
|
| base_module_name = os.path.relpath(dirpath, base_path).split(os.path.sep)
|
| - ret += ['.'.join(base_module_name + [inspect.getmodulename(filename)])
|
| - for filename in filenames
|
| - if is_test_file(filename)]
|
| + test_modules.extend(['.'.join(base_module_name
|
| + + [inspect.getmodulename(filename)])
|
| + for filename in filenames
|
| + if is_test_file(filename)])
|
|
|
| - return ret
|
| + return test_modules
|
|
|
|
|
| def load_module(modname):
|
| @@ -180,7 +196,7 @@ def get_test_gens_directory(path):
|
| sys.path.insert(0, os.path.abspath(path))
|
|
|
| test_gens = []
|
| - black_list = get_blacklist(path)
|
| + black_list = get_config(path)
|
|
|
| for filename in filter(lambda x: x not in black_list, os.listdir(path)):
|
| abs_filename = os.path.join(path, filename)
|
|
|