tests: Fix handling of subdirs and backup files in test-backend.

Fixes #1950.
This commit is contained in:
sonali0901
2016-11-04 02:08:06 +05:30
committed by Tim Abbott
parent 19b01d74fa
commit df4b777b35

View File

@@ -89,16 +89,19 @@ if __name__ == "__main__":
def rewrite_arguments(search_key):
# type: (str) -> None
for file_name in os.listdir(zerver_test_dir):
if file_name.endswith(".py"):
filepath = zerver_test_dir + file_name
if os.path.isdir(filepath):
for root, dirs, files_names in os.walk(zerver_test_dir, topdown=False):
for file_name in files_names:
# Check for files starting with alphanumeric characters and ending with '.py'
# Ignore backup files if any
if not file_name[0].isalnum() or not file_name.endswith(".py"):
continue
filepath = os.path.join(root, file_name)
for line in open(filepath):
if search_key in line:
new_suite = filepath.replace(".py", ".") + suite
args[args.index(suite)] = new_suite
return
if search_key not in line:
continue
new_suite = filepath.replace(".py", ".") + suite
args[args.index(suite)] = new_suite
return
for suite in args:
if suite[0].isupper() and "test_" in suite:
@@ -109,8 +112,12 @@ if __name__ == "__main__":
for suite in args:
if suite.startswith('test'):
new_suite = "zerver.tests." + suite
args[args.index(suite)] = new_suite
for root, dirs, files_names in os.walk(zerver_test_dir):
for file_name in files_names:
if file_name == suite or file_name == suite + ".py":
new_suite = os.path.join(root, file_name)
args[args.index(suite)] = new_suite
break
for suite in args:
args[args.index(suite)] = suite.replace(".py", "")
@@ -120,7 +127,6 @@ if __name__ == "__main__":
for suite in args:
args[args.index(suite)] = suite.replace("/", ".")
if len(args) == 0:
suites = ["zerver.tests",
"analytics.tests"]