mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-06 07:57:27 +08:00
refactor load_folder_files: change filter behavior
This commit is contained in:
+19
-5
@@ -1,5 +1,4 @@
|
|||||||
import codecs
|
import codecs
|
||||||
import fnmatch
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import hmac
|
import hmac
|
||||||
import imp
|
import imp
|
||||||
@@ -57,20 +56,35 @@ def load_testcases(testcase_file_path):
|
|||||||
# '' or other suffix
|
# '' or other suffix
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def load_folder_files(folder_path, match_filter_list=["*"]):
|
def load_folder_files(folder_path, file_type, recursive=False):
|
||||||
""" load folder path, return all files in list format.
|
""" load folder path, return all files in list format.
|
||||||
|
@param
|
||||||
|
folder_path: specified folder path to load
|
||||||
|
file_type: "test" or "api"
|
||||||
|
recursive: if True, will load files recursively
|
||||||
"""
|
"""
|
||||||
file_list = []
|
file_list = []
|
||||||
|
|
||||||
for dirpath, dirnames, filenames in os.walk(folder_path):
|
for dirpath, dirnames, filenames in os.walk(folder_path):
|
||||||
filenames_list = []
|
filenames_list = []
|
||||||
for match_filter in match_filter_list:
|
|
||||||
filenames_list.extend(fnmatch.filter(filenames, match_filter))
|
for filename in filenames:
|
||||||
|
|
||||||
|
if not filename.endswith(('.yml', '.yaml', '.json')):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if file_type == "api" and not filename.startswith(('api.', 'api-')):
|
||||||
|
continue
|
||||||
|
|
||||||
|
filenames_list.append(filename)
|
||||||
|
|
||||||
for filename in filenames_list:
|
for filename in filenames_list:
|
||||||
file_path = os.path.join(dirpath, filename)
|
file_path = os.path.join(dirpath, filename)
|
||||||
file_list.append(file_path)
|
file_list.append(file_path)
|
||||||
|
|
||||||
|
if not recursive:
|
||||||
|
break
|
||||||
|
|
||||||
return file_list
|
return file_list
|
||||||
|
|
||||||
def load_testcases_by_path(path):
|
def load_testcases_by_path(path):
|
||||||
@@ -99,7 +113,7 @@ def load_testcases_by_path(path):
|
|||||||
path = os.path.join(os.getcwd(), path)
|
path = os.path.join(os.getcwd(), path)
|
||||||
|
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
files_list = load_folder_files(path, ["*.yml", "*.yaml", "*.json"])
|
files_list = load_folder_files(path, file_type="test", recursive=True)
|
||||||
return load_testcases_by_path(files_list)
|
return load_testcases_by_path(files_list)
|
||||||
|
|
||||||
elif os.path.isfile(path):
|
elif os.path.isfile(path):
|
||||||
|
|||||||
+8
-2
@@ -36,10 +36,16 @@ class TestUtils(ApiServerUnittest):
|
|||||||
file1 = os.path.join(os.getcwd(), 'tests', 'test_utils.py')
|
file1 = os.path.join(os.getcwd(), 'tests', 'test_utils.py')
|
||||||
file2 = os.path.join(os.getcwd(), 'tests', 'data', 'demo_binds.yml')
|
file2 = os.path.join(os.getcwd(), 'tests', 'data', 'demo_binds.yml')
|
||||||
|
|
||||||
files = utils.load_folder_files(folder, ["*.py"])
|
files = utils.load_folder_files(folder, file_type="test", recursive=False)
|
||||||
self.assertIn(file1, files)
|
|
||||||
self.assertNotIn(file2, files)
|
self.assertNotIn(file2, files)
|
||||||
|
|
||||||
|
files = utils.load_folder_files(folder, file_type="test", recursive=True)
|
||||||
|
self.assertIn(file2, files)
|
||||||
|
self.assertNotIn(file1, files)
|
||||||
|
|
||||||
|
files = utils.load_folder_files(folder, file_type="api", recursive=True)
|
||||||
|
self.assertEqual(files, [])
|
||||||
|
|
||||||
def test_load_testcases_by_path_files(self):
|
def test_load_testcases_by_path_files(self):
|
||||||
testsets_list = []
|
testsets_list = []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user