Lower case test names, blob matching test names, and sort test names for prints

pull/1925/head
Brian Daniels 2016-06-14 00:32:22 +01:00
parent f622c591e8
commit 1bcd64301a
2 changed files with 25 additions and 57 deletions

View File

@ -103,8 +103,8 @@ if __name__ == '__main__':
# Filter tests by name if specified # Filter tests by name if specified
if options.names: if options.names:
all_names = options.names.split(",") all_names = options.names.split(",")
all_names = [x.lower() for x in all_names]
all_tests_keys = all_tests.keys()
for name in all_names: for name in all_names:
if any(fnmatch.fnmatch(testname, name) for testname in all_tests): if any(fnmatch.fnmatch(testname, name) for testname in all_tests):
for testname, test in all_tests.items(): for testname, test in all_tests.items():

View File

@ -1961,76 +1961,44 @@ def test_path_to_name(path):
name_parts.insert(0, tail) name_parts.insert(0, tail)
head, tail = os.path.split(head) head, tail = os.path.split(head)
return "-".join(name_parts) return "-".join(name_parts).lower()
def find_tests(base_dir): def find_tests(base_dir):
"""Given any directory, walk through the subdirectories and find all tests""" """Given any directory, walk through the subdirectories and find all tests"""
def is_subdir(path, directory): def find_test_in_directory(directory, tests_path):
path = os.path.realpath(path)
directory = os.path.realpath(directory)
relative = os.path.relpath(path, directory)
return not (relative.startswith(os.pardir + os.sep) and relative.startswith(os.pardir))
def find_tests_in_tests_directory(directory):
"""Given a 'TESTS' directory, return a dictionary of test names and test paths. """Given a 'TESTS' directory, return a dictionary of test names and test paths.
The formate of the dictionary is {"test-name": "./path/to/test"}""" The formate of the dictionary is {"test-name": "./path/to/test"}"""
tests = {} test = None
if tests_path in directory:
head, test_case_directory = os.path.split(directory)
if test_case_directory != tests_path and test_case_directory != "host_tests":
head, test_group_directory = os.path.split(head)
if test_group_directory != tests_path and test_case_directory != "host_tests":
test = {
"name": test_path_to_name(directory),
"path": directory
}
for d in os.listdir(directory): return test
# dir name host_tests is reserved for host python scripts.
if d != "host_tests":
# Loop on test case directories
for td in os.listdir(os.path.join(directory, d)):
# Add test case to the results if it is a directory and not "host_tests"
if td != "host_tests":
test_case_path = os.path.join(directory, d, td)
if os.path.isdir(test_case_path):
tests[test_path_to_name(test_case_path)] = test_case_path
return tests
tests_path = 'TESTS' tests_path = 'TESTS'
tests = {}
dirs = scan_for_source_paths(base_dir)
# Determine if "base_dir" is already a "TESTS" directory for directory in dirs:
_, top_folder = os.path.split(base_dir) test = find_test_in_directory(directory, tests_path)
if test:
tests[test['name']] = test['path']
if top_folder == tests_path: return tests
# Already pointing at a "TESTS" directory
return find_tests_in_tests_directory(base_dir)
else:
# Not pointing at a "TESTS" directory, so go find one!
tests = {}
dirs = scan_for_source_paths(base_dir)
test_and_sub_dirs = [x for x in dirs if tests_path in x]
test_dirs = []
for potential_test_dir in test_and_sub_dirs:
good_to_add = True
if test_dirs:
for test_dir in test_dirs:
if is_subdir(potential_test_dir, test_dir):
good_to_add = False
break
if good_to_add:
test_dirs.append(potential_test_dir)
# Only look at valid paths
for path in test_dirs:
# Get the tests inside of the "TESTS" directory
new_tests = find_tests_in_tests_directory(path)
if new_tests:
tests.update(new_tests)
return tests
def print_tests(tests, format="list"): def print_tests(tests, format="list", sort=True):
"""Given a dictionary of tests (as returned from "find_tests"), print them """Given a dictionary of tests (as returned from "find_tests"), print them
in the specified format""" in the specified format"""
if format == "list": if format == "list":
for test_name, test_path in tests.iteritems(): for test_name in sorted(tests.keys()):
test_path = tests[test_name]
print "Test Case:" print "Test Case:"
print " Name: %s" % test_name print " Name: %s" % test_name
print " Path: %s" % test_path print " Path: %s" % test_path