Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Unified Diff: expect_tests/pipeline.py

Issue 587493002: Config files (Closed) Base URL: https://chromium.googlesource.com/infra/testing/expect_tests@serial_exec
Patch Set: More cleanup Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: expect_tests/pipeline.py
diff --git a/expect_tests/pipeline.py b/expect_tests/pipeline.py
index a82f49de4b13c04159fd08bda8c4bba1744e66dd..c2d71cf48a20b5ce6a0d567ceb0774bfa6fbf381 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 = parser.get('expect_tests', 'skip').splitlines()
dnj 2014/09/19 23:56:05 This should be 'black_list.update(...)'. Function
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,20 +125,26 @@ 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')
+ sys.path[:] = sys.path.insert(0, 'some/directory')
__import__(modules[0])
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 += ['.'.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)
@@ -215,7 +231,9 @@ def get_test_gens_package(package, update_syspath=True):
sys.path.insert(0, path)
package_name = os.path.split(package.rstrip(os.path.sep))[-1]
- for modname in walk_package(package_name, path):
+ test_modules = walk_package(package_name, path)
+
+ for modname in test_modules:
dnj 2014/09/19 23:56:05 nit: Why split this? I think it was fine before.
pgervais 2014/09/20 00:26:55 merge problem I think. will fix.
mod = load_module(modname)
for obj in mod.__dict__.values():
if util.is_test_generator(obj):
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698