mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	tests: Fix handling of subdirs and backup files in test-backend.
Fixes #1950.
This commit is contained in:
		@@ -89,13 +89,16 @@ if __name__ == "__main__":
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def rewrite_arguments(search_key):
 | 
					    def rewrite_arguments(search_key):
 | 
				
			||||||
        # type: (str) -> None
 | 
					        # type: (str) -> None
 | 
				
			||||||
        for file_name in os.listdir(zerver_test_dir):
 | 
					        for root, dirs, files_names in os.walk(zerver_test_dir, topdown=False):
 | 
				
			||||||
            if file_name.endswith(".py"):
 | 
					            for file_name in files_names:
 | 
				
			||||||
                filepath = zerver_test_dir + file_name
 | 
					                # Check for files starting with alphanumeric characters and ending with '.py'
 | 
				
			||||||
                if os.path.isdir(filepath):
 | 
					                # Ignore backup files if any
 | 
				
			||||||
 | 
					                if not file_name[0].isalnum() or not file_name.endswith(".py"):
 | 
				
			||||||
                    continue
 | 
					                    continue
 | 
				
			||||||
 | 
					                filepath = os.path.join(root, file_name)
 | 
				
			||||||
                for line in open(filepath):
 | 
					                for line in open(filepath):
 | 
				
			||||||
                    if search_key in line:
 | 
					                    if search_key not in line:
 | 
				
			||||||
 | 
					                        continue
 | 
				
			||||||
                    new_suite = filepath.replace(".py", ".") + suite
 | 
					                    new_suite = filepath.replace(".py", ".") + suite
 | 
				
			||||||
                    args[args.index(suite)] = new_suite
 | 
					                    args[args.index(suite)] = new_suite
 | 
				
			||||||
                    return
 | 
					                    return
 | 
				
			||||||
@@ -109,8 +112,12 @@ if __name__ == "__main__":
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    for suite in args:
 | 
					    for suite in args:
 | 
				
			||||||
        if suite.startswith('test'):
 | 
					        if suite.startswith('test'):
 | 
				
			||||||
            new_suite = "zerver.tests." + 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
 | 
					                        args[args.index(suite)] = new_suite
 | 
				
			||||||
 | 
					                        break
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for suite in args:
 | 
					    for suite in args:
 | 
				
			||||||
        args[args.index(suite)] = suite.replace(".py", "")
 | 
					        args[args.index(suite)] = suite.replace(".py", "")
 | 
				
			||||||
@@ -120,7 +127,6 @@ if __name__ == "__main__":
 | 
				
			|||||||
    for suite in args:
 | 
					    for suite in args:
 | 
				
			||||||
        args[args.index(suite)] = suite.replace("/", ".")
 | 
					        args[args.index(suite)] = suite.replace("/", ".")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    if len(args) == 0:
 | 
					    if len(args) == 0:
 | 
				
			||||||
        suites = ["zerver.tests",
 | 
					        suites = ["zerver.tests",
 | 
				
			||||||
                  "analytics.tests"]
 | 
					                  "analytics.tests"]
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user