change: add typing

This commit is contained in:
debugtalk
2020-05-15 15:01:43 +08:00
parent c54b15d29e
commit 98cfa79258

View File

@@ -5,7 +5,7 @@ import json
import os import os
import sys import sys
import types import types
from typing import Tuple, Dict from typing import Tuple, Dict, Union, Text, List, Callable
import yaml import yaml
from loguru import logger from loguru import logger
@@ -23,11 +23,11 @@ except AttributeError:
pass pass
project_meta_cached_mapping: Dict[str, ProjectMeta] = {} project_meta_cached_mapping: Dict[Text, ProjectMeta] = {}
project_working_directory: str = None project_working_directory: Union[Text, None] = None
def _load_yaml_file(yaml_file): def _load_yaml_file(yaml_file: Text) -> Dict:
""" load yaml file and check file content format """ load yaml file and check file content format
""" """
with io.open(yaml_file, "r", encoding="utf-8") as stream: with io.open(yaml_file, "r", encoding="utf-8") as stream:
@@ -40,7 +40,7 @@ def _load_yaml_file(yaml_file):
return yaml_content return yaml_content
def _load_json_file(json_file): def _load_json_file(json_file: Text) -> Dict:
""" load json file and check file content format """ load json file and check file content format
""" """
with io.open(json_file, encoding="utf-8") as data_file: with io.open(json_file, encoding="utf-8") as data_file:
@@ -54,7 +54,7 @@ def _load_json_file(json_file):
return json_content return json_content
def load_testcase_file(testcase_file) -> Tuple[Dict, TestCase]: def load_testcase_file(testcase_file: Text) -> Tuple[Dict, TestCase]:
"""load testcase file and validate with pydantic model""" """load testcase file and validate with pydantic model"""
file_suffix = os.path.splitext(testcase_file)[1].lower() file_suffix = os.path.splitext(testcase_file)[1].lower()
if file_suffix == ".json": if file_suffix == ".json":
@@ -81,7 +81,7 @@ def load_testcase_file(testcase_file) -> Tuple[Dict, TestCase]:
return testcase_content, testcase_obj return testcase_content, testcase_obj
def load_dot_env_file(dot_env_path): def load_dot_env_file(dot_env_path: Text) -> Dict:
""" load .env file. """ load .env file.
Args: Args:
@@ -122,7 +122,7 @@ def load_dot_env_file(dot_env_path):
return env_variables_mapping return env_variables_mapping
def load_csv_file(csv_file): def load_csv_file(csv_file: Text) -> List[Dict]:
""" load csv file and check file content format """ load csv file and check file content format
Args: Args:
@@ -168,7 +168,7 @@ def load_csv_file(csv_file):
return csv_content_list return csv_content_list
def load_folder_files(folder_path, recursive=True): def load_folder_files(folder_path: Text, recursive: bool = True) -> List:
""" load folder path, return all files endswith yml/yaml/json in list. """ load folder path, return all files endswith yml/yaml/json in list.
Args: Args:
@@ -209,7 +209,7 @@ def load_folder_files(folder_path, recursive=True):
return file_list return file_list
def load_module_functions(module): def load_module_functions(module) -> Dict[Text, Callable]:
""" load python module functions. """ load python module functions.
Args: Args:
@@ -233,13 +233,13 @@ def load_module_functions(module):
return module_functions return module_functions
def load_builtin_functions(): def load_builtin_functions() -> Dict[Text, Callable]:
""" load builtin module functions """ load builtin module functions
""" """
return load_module_functions(builtin) return load_module_functions(builtin)
def locate_file(start_path, file_name): def locate_file(start_path: Text, file_name: Text) -> Text:
""" locate filename and return absolute file path. """ locate filename and return absolute file path.
searching will be recursive upward until current working directory or system root dir. searching will be recursive upward until current working directory or system root dir.
@@ -280,7 +280,7 @@ def locate_file(start_path, file_name):
return locate_file(parent_dir, file_name) return locate_file(parent_dir, file_name)
def locate_debugtalk_py(start_path): def locate_debugtalk_py(start_path: Text) -> Text:
""" locate debugtalk.py file """ locate debugtalk.py file
Args: Args:
@@ -300,7 +300,7 @@ def locate_debugtalk_py(start_path):
return debugtalk_path return debugtalk_path
def init_project_working_directory(test_path): def init_project_working_directory(test_path: Text) -> Tuple[Text, Text]:
""" this should be called at startup """ this should be called at startup
run test file: run test file:
@@ -346,7 +346,7 @@ def init_project_working_directory(test_path):
return debugtalk_path, project_working_directory return debugtalk_path, project_working_directory
def load_debugtalk_functions(): def load_debugtalk_functions() -> Dict[Text, Callable]:
""" load project debugtalk.py module functions """ load project debugtalk.py module functions
debugtalk.py should be located in project working directory. debugtalk.py should be located in project working directory.
@@ -363,7 +363,7 @@ def load_debugtalk_functions():
return load_module_functions(imported_module) return load_module_functions(imported_module)
def load_project_meta(test_path: str) -> ProjectMeta: def load_project_meta(test_path: Text) -> ProjectMeta:
""" load api, testcases, .env, debugtalk.py functions. """ load api, testcases, .env, debugtalk.py functions.
api/testcases folder is relative to project_working_directory api/testcases folder is relative to project_working_directory