Skip to content

Commit 1bcd643

Browse files
committed
Lower case test names, blob matching test names, and sort test names for prints
1 parent f622c59 commit 1bcd643

File tree

2 files changed

+25
-57
lines changed

2 files changed

+25
-57
lines changed

tools/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@
103103
# Filter tests by name if specified
104104
if options.names:
105105
all_names = options.names.split(",")
106+
all_names = [x.lower() for x in all_names]
106107

107-
all_tests_keys = all_tests.keys()
108108
for name in all_names:
109109
if any(fnmatch.fnmatch(testname, name) for testname in all_tests):
110110
for testname, test in all_tests.items():

tools/test_api.py

Lines changed: 24 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,76 +1961,44 @@ def test_path_to_name(path):
19611961
name_parts.insert(0, tail)
19621962
head, tail = os.path.split(head)
19631963

1964-
return "-".join(name_parts)
1964+
return "-".join(name_parts).lower()
19651965

19661966
def find_tests(base_dir):
19671967
"""Given any directory, walk through the subdirectories and find all tests"""
19681968

1969-
def is_subdir(path, directory):
1970-
path = os.path.realpath(path)
1971-
directory = os.path.realpath(directory)
1972-
relative = os.path.relpath(path, directory)
1973-
return not (relative.startswith(os.pardir + os.sep) and relative.startswith(os.pardir))
1974-
1975-
def find_tests_in_tests_directory(directory):
1969+
def find_test_in_directory(directory, tests_path):
19761970
"""Given a 'TESTS' directory, return a dictionary of test names and test paths.
19771971
The formate of the dictionary is {"test-name": "./path/to/test"}"""
1978-
tests = {}
1979-
1980-
for d in os.listdir(directory):
1981-
# dir name host_tests is reserved for host python scripts.
1982-
if d != "host_tests":
1983-
# Loop on test case directories
1984-
for td in os.listdir(os.path.join(directory, d)):
1985-
# Add test case to the results if it is a directory and not "host_tests"
1986-
if td != "host_tests":
1987-
test_case_path = os.path.join(directory, d, td)
1988-
if os.path.isdir(test_case_path):
1989-
tests[test_path_to_name(test_case_path)] = test_case_path
1972+
test = None
1973+
if tests_path in directory:
1974+
head, test_case_directory = os.path.split(directory)
1975+
if test_case_directory != tests_path and test_case_directory != "host_tests":
1976+
head, test_group_directory = os.path.split(head)
1977+
if test_group_directory != tests_path and test_case_directory != "host_tests":
1978+
test = {
1979+
"name": test_path_to_name(directory),
1980+
"path": directory
1981+
}
19901982

1991-
return tests
1992-
1983+
return test
1984+
19931985
tests_path = 'TESTS'
1986+
tests = {}
1987+
dirs = scan_for_source_paths(base_dir)
19941988

1995-
# Determine if "base_dir" is already a "TESTS" directory
1996-
_, top_folder = os.path.split(base_dir)
1989+
for directory in dirs:
1990+
test = find_test_in_directory(directory, tests_path)
1991+
if test:
1992+
tests[test['name']] = test['path']
19971993

1998-
if top_folder == tests_path:
1999-
# Already pointing at a "TESTS" directory
2000-
return find_tests_in_tests_directory(base_dir)
2001-
else:
2002-
# Not pointing at a "TESTS" directory, so go find one!
2003-
tests = {}
2004-
2005-
dirs = scan_for_source_paths(base_dir)
2006-
2007-
test_and_sub_dirs = [x for x in dirs if tests_path in x]
2008-
test_dirs = []
2009-
for potential_test_dir in test_and_sub_dirs:
2010-
good_to_add = True
2011-
if test_dirs:
2012-
for test_dir in test_dirs:
2013-
if is_subdir(potential_test_dir, test_dir):
2014-
good_to_add = False
2015-
break
2016-
2017-
if good_to_add:
2018-
test_dirs.append(potential_test_dir)
2019-
2020-
# Only look at valid paths
2021-
for path in test_dirs:
2022-
# Get the tests inside of the "TESTS" directory
2023-
new_tests = find_tests_in_tests_directory(path)
2024-
if new_tests:
2025-
tests.update(new_tests)
2026-
2027-
return tests
1994+
return tests
20281995

2029-
def print_tests(tests, format="list"):
1996+
def print_tests(tests, format="list", sort=True):
20301997
"""Given a dictionary of tests (as returned from "find_tests"), print them
20311998
in the specified format"""
20321999
if format == "list":
2033-
for test_name, test_path in tests.iteritems():
2000+
for test_name in sorted(tests.keys()):
2001+
test_path = tests[test_name]
20342002
print "Test Case:"
20352003
print " Name: %s" % test_name
20362004
print " Path: %s" % test_path

0 commit comments

Comments
 (0)