@@ -1961,76 +1961,44 @@ def test_path_to_name(path):
1961
1961
name_parts .insert (0 , tail )
1962
1962
head , tail = os .path .split (head )
1963
1963
1964
- return "-" .join (name_parts )
1964
+ return "-" .join (name_parts ). lower ()
1965
1965
1966
1966
def find_tests (base_dir ):
1967
1967
"""Given any directory, walk through the subdirectories and find all tests"""
1968
1968
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 ):
1976
1970
"""Given a 'TESTS' directory, return a dictionary of test names and test paths.
1977
1971
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
+ }
1990
1982
1991
- return tests
1992
-
1983
+ return test
1984
+
1993
1985
tests_path = 'TESTS'
1986
+ tests = {}
1987
+ dirs = scan_for_source_paths (base_dir )
1994
1988
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' ]
1997
1993
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
2028
1995
2029
- def print_tests (tests , format = "list" ):
1996
+ def print_tests (tests , format = "list" , sort = True ):
2030
1997
"""Given a dictionary of tests (as returned from "find_tests"), print them
2031
1998
in the specified format"""
2032
1999
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 ]
2034
2002
print "Test Case:"
2035
2003
print " Name: %s" % test_name
2036
2004
print " Path: %s" % test_path
0 commit comments