From 96711fd069d7b336a4235cf69361f35049d197b9 Mon Sep 17 00:00:00 2001 From: xingwenyang Date: Tue, 25 Jan 2022 14:08:36 +0800 Subject: [PATCH 1/6] add config error --- flybirds/cli/parse_args.py | 77 ++++++++++++++++++++++++ flybirds/core/config_manage.py | 2 + flybirds/core/launch_cycle/run_manage.py | 10 +++ flybirds/report/fail_feature_create.py | 27 ++++++--- flybirds/report/gen/cucumber_gen.py | 4 ++ flybirds/utils/file_helper.py | 3 + 6 files changed, 114 insertions(+), 9 deletions(-) diff --git a/flybirds/cli/parse_args.py b/flybirds/cli/parse_args.py index 0bb5a73d..1f86eeb7 100644 --- a/flybirds/cli/parse_args.py +++ b/flybirds/cli/parse_args.py @@ -22,6 +22,80 @@ def default_report_path(): return report_path +def check_workspace_args_bk(feature_path): + change_base_dir = None + base_dir = os.getcwd() + config_dir = os.path.join(base_dir, "config") + + if feature_path is not None and feature_path != 'features': + temp_path = os.path.normpath(feature_path) + if os.path.isabs(temp_path) is False: + temp_path = os.path.abspath(temp_path) + + if os.path.isfile(temp_path) is False and os.path.isdir( + temp_path) is False: + raise Exception(f"cannot find path:{temp_path}") + + path_array = temp_path.split(os.sep) + if path_array is not None and path_array.index("features") >= 1: + index = path_array.index("features") + config_path = path_array[0] + if path_array[0].find(":") >= 0: + config_path = os.path.join(config_path, os.sep) + for p in path_array[1:index]: + config_path = os.path.join(config_path, p) + + change_base_dir = config_path + else: + raise Exception( + f"cannot find features dir under path: {feature_path}") + + if os.path.isdir(config_dir) is False: + if change_base_dir is not None: + config_path = os.path.join(change_base_dir, "config") + if os.path.isdir(config_path) is False: + raise Exception(f"no config directory {config_path}") + else: + if change_base_dir != base_dir: + raise Exception(f"no config directory {config_path}") + # os.environ['base_dir'] = change_base_dir + else: + raise Exception(f"cannot find config path in {base_dir}") + else: + if change_base_dir is not None and change_base_dir != \ + base_dir: + os.environ['base_feature_dir'] = change_base_dir + + +def check_workspace_args(feature_path): + base_dir = os.getcwd() + config_dir = os.path.join(base_dir, "config") + + if feature_path is not None: + temp_path = os.path.normpath(feature_path) + if os.path.isabs(temp_path) is False: + temp_path = os.path.abspath(temp_path) + + if os.path.isfile(temp_path) is False and os.path.isdir( + temp_path) is False: + raise Exception(f"cannot find path:{temp_path}") + + path_array = temp_path.split(os.sep) + if path_array is not None and path_array.index("features") >= 1: + index = path_array.index("features") + config_path = path_array[0] + if path_array[0].find(":") >= 0: + config_path = os.path.join(config_path, os.sep) + for p in path_array[1:index]: + config_path = os.path.join(config_path, p) + else: + raise Exception( + f"cannot find features dir under path: {feature_path}") + + if os.path.isdir(config_dir) is False: + raise Exception(f"no config directory {config_dir}") + + def parse_args( feature_path, tag, report_format, report_path, define, rerun, es, to_html, run_at @@ -34,6 +108,9 @@ def parse_args( f"flybirds cmd info: {feature_path} {tag} {report_format} {report_path}" f" {define} {rerun} {es} {to_html} {run_at}" ) + + check_workspace_args(feature_path) + use_define = [] tags = [] need_rerun = False diff --git a/flybirds/core/config_manage.py b/flybirds/core/config_manage.py index e99f3914..7ca7614d 100644 --- a/flybirds/core/config_manage.py +++ b/flybirds/core/config_manage.py @@ -59,6 +59,8 @@ def get_config(config, name): c_f = file_helper.get_json_from_file(path) if c_f.__contains__(name): return c_f.get(name) + else: + raise Exception(f"not find path: {path}") elif config.__contains__(name): return config.get(name) diff --git a/flybirds/core/launch_cycle/run_manage.py b/flybirds/core/launch_cycle/run_manage.py index 31b2b9bf..f25dc563 100644 --- a/flybirds/core/launch_cycle/run_manage.py +++ b/flybirds/core/launch_cycle/run_manage.py @@ -70,6 +70,9 @@ def exe(context): cmd_str = context.get("cmd_str") need_rerun_args = context.get("need_rerun_args") report_dir_path = context.get("report_dir_path") + # cwd_pth = os.getcwd() + # if os.environ.get('base_dir') is not None: + # cwd_pth = os.environ.get('base_dir') behave_process = subprocess.Popen( cmd_str, cwd=os.getcwd(), shell=True, stdout=None @@ -78,6 +81,13 @@ def exe(context): behave_process.wait() behave_process.communicate() + # if os.environ.get('base_dir') is not None: + # if report_dir_path is not None and os.path.isabs( \ + # report_dir_path) is \ + # False: + # report_dir_path = os.path.join( + # os.environ.get('base_dir'), report_dir_path) + # Determine whether the failed scenario needs to be re-run rerun_launch(need_rerun_args, report_dir_path, run_args) diff --git a/flybirds/report/fail_feature_create.py b/flybirds/report/fail_feature_create.py index ea9ab767..0f0dc2a5 100644 --- a/flybirds/report/fail_feature_create.py +++ b/flybirds/report/fail_feature_create.py @@ -135,6 +135,9 @@ def rerun_launch(need_rerun_args, report_dir_path, run_args): "rerun_report_dir_path" ) if rerun_cmd_str is not None: + # cwd_pth = os.getcwd() + # if os.environ.get('base_dir') is not None: + # cwd_pth = os.environ.get('base_dir') rerun_behave_process = subprocess.Popen( rerun_cmd_str, cwd=os.getcwd(), @@ -221,8 +224,8 @@ def create_rerun(report_dir, rerun_dir, run_count, max_fail_count=1.0): ) result = False elif ( - isinstance(max_fail_count, float) - and (fail_count / sum_count) > max_fail_count + isinstance(max_fail_count, float) + and (fail_count / sum_count) > max_fail_count ): log.info( "Feature to rerun after creation failure " @@ -384,18 +387,24 @@ def copy_behave_need_file(rerun_root_dir): """ copy step.py and environment.py and other behave files to feature path """ + + cwd_pth = os.getcwd() + # if os.environ.get('base_dir') is not None: + # cwd_pth = os.environ.get('base_dir') + # elif os.environ.get('base_feature_dir') is not None: + # cwd_pth = os.environ.get('base_feature_dir') file_helper.create_dirs(os.path.join(rerun_root_dir, "steps")) file_helper.clear_dirs(os.path.join(rerun_root_dir, "steps")) shutil.copy( - os.path.join(os.getcwd(), "features", "steps", "steps.py"), + os.path.join(cwd_pth, "features", "steps", "steps.py"), os.path.join(rerun_root_dir, "steps", "steps.py"), ) shutil.copy( - os.path.join(os.getcwd(), "features", "environment.py"), + os.path.join(cwd_pth, "features", "environment.py"), os.path.join(rerun_root_dir, "environment.py"), ) shutil.copy( - os.path.join(os.getcwd(), "features", "__init__.py"), + os.path.join(cwd_pth, "features", "__init__.py"), os.path.join(rerun_root_dir, "__init__.py"), ) @@ -407,8 +416,8 @@ def set_rerun_info(user_data, gr): last_fail_scenario_info_obj = {} # get rerun info, add into report if ( - "flybirdsAutoRerun" in user_data.keys() - and user_data["flybirdsAutoRerun"] == "Yes" + "flybirdsAutoRerun" in user_data.keys() + and user_data["flybirdsAutoRerun"] == "Yes" ): log.info("this is rerun case execute") rerun_info_array = user_data["flybirdsAutoRerunInfo"].split(",") @@ -417,8 +426,8 @@ def set_rerun_info(user_data, gr): rerun_info = item_rerun_info.strip() print("rerun_info", rerun_info) if ( - "flybirdsAutoRerunInfo" in user_data.keys() - and os.path.exists(rerun_info) + "flybirdsAutoRerunInfo" in user_data.keys() + and os.path.exists(rerun_info) ): try: last_fail_scenario_info = ( diff --git a/flybirds/report/gen/cucumber_gen.py b/flybirds/report/gen/cucumber_gen.py index 786ceaae..29c1dcf2 100644 --- a/flybirds/report/gen/cucumber_gen.py +++ b/flybirds/report/gen/cucumber_gen.py @@ -30,6 +30,10 @@ def gen(report_path): cmd_str = f"node {gen_path} {report_path} {report_path}" logger.info(f"report cmd:{cmd_str}") + # cwd_pth = os.getcwd() + # if os.environ.get('base_dir') is not None: + # cwd_pth = os.environ.get('base_dir') + report_process = subprocess.Popen( cmd_str, cwd=os.getcwd(), shell=True, stdout=None ) diff --git a/flybirds/utils/file_helper.py b/flybirds/utils/file_helper.py index 4ae0453a..2923a8af 100644 --- a/flybirds/utils/file_helper.py +++ b/flybirds/utils/file_helper.py @@ -77,6 +77,9 @@ def clear_dirs(path): """ Clear all files and folders under a folder """ + # cwd_pth = os.getcwd() + # if os.environ.get('base_dir') is not None: + # cwd_pth = os.environ.get('base_dir') path = os.path.join(os.getcwd(), path) if os.path.exists(path): ls = os.listdir(path) From c12cf94016e290560908e8fc359e9cd513a4bba3 Mon Sep 17 00:00:00 2001 From: xingwenyang Date: Tue, 25 Jan 2022 15:51:59 +0800 Subject: [PATCH 2/6] fix: add features file error --- flybirds/cli/parse_args.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/flybirds/cli/parse_args.py b/flybirds/cli/parse_args.py index 1f86eeb7..8d93eba4 100644 --- a/flybirds/cli/parse_args.py +++ b/flybirds/cli/parse_args.py @@ -71,6 +71,9 @@ def check_workspace_args(feature_path): base_dir = os.getcwd() config_dir = os.path.join(base_dir, "config") + if os.path.isdir(config_dir) is False: + raise Exception(f"no config directory {config_dir}") + if feature_path is not None: temp_path = os.path.normpath(feature_path) if os.path.isabs(temp_path) is False: @@ -79,21 +82,14 @@ def check_workspace_args(feature_path): if os.path.isfile(temp_path) is False and os.path.isdir( temp_path) is False: raise Exception(f"cannot find path:{temp_path}") - - path_array = temp_path.split(os.sep) - if path_array is not None and path_array.index("features") >= 1: - index = path_array.index("features") - config_path = path_array[0] - if path_array[0].find(":") >= 0: - config_path = os.path.join(config_path, os.sep) - for p in path_array[1:index]: - config_path = os.path.join(config_path, p) - else: - raise Exception( - f"cannot find features dir under path: {feature_path}") - - if os.path.isdir(config_dir) is False: - raise Exception(f"no config directory {config_dir}") + if os.path.isdir(temp_path): + features_dir = os.listdir(temp_path) + for k in range(len(features_dir)): + features_dir[k] = os.path.splitext(features_dir[k])[1] + Str = '.feature' + if Str not in features_dir: + raise Exception(f"not have any features under directory" + f" {temp_path}") def parse_args( From a6a2fc9aa7ff34ee99787c7377fe4f902e7b4ae4 Mon Sep 17 00:00:00 2001 From: xingwenyang Date: Tue, 25 Jan 2022 17:25:51 +0800 Subject: [PATCH 3/6] fix: remove feature check --- flybirds/cli/parse_args.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/flybirds/cli/parse_args.py b/flybirds/cli/parse_args.py index 8d93eba4..c5c87b80 100644 --- a/flybirds/cli/parse_args.py +++ b/flybirds/cli/parse_args.py @@ -74,23 +74,6 @@ def check_workspace_args(feature_path): if os.path.isdir(config_dir) is False: raise Exception(f"no config directory {config_dir}") - if feature_path is not None: - temp_path = os.path.normpath(feature_path) - if os.path.isabs(temp_path) is False: - temp_path = os.path.abspath(temp_path) - - if os.path.isfile(temp_path) is False and os.path.isdir( - temp_path) is False: - raise Exception(f"cannot find path:{temp_path}") - if os.path.isdir(temp_path): - features_dir = os.listdir(temp_path) - for k in range(len(features_dir)): - features_dir[k] = os.path.splitext(features_dir[k])[1] - Str = '.feature' - if Str not in features_dir: - raise Exception(f"not have any features under directory" - f" {temp_path}") - def parse_args( feature_path, tag, report_format, report_path, define, rerun, es, From 4aef920baaa82058737373bddd244530c10f407d Mon Sep 17 00:00:00 2001 From: xingwenyang Date: Tue, 25 Jan 2022 17:36:06 +0800 Subject: [PATCH 4/6] fix: change config error info --- flybirds/cli/parse_args.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flybirds/cli/parse_args.py b/flybirds/cli/parse_args.py index c5c87b80..467d6264 100644 --- a/flybirds/cli/parse_args.py +++ b/flybirds/cli/parse_args.py @@ -72,7 +72,7 @@ def check_workspace_args(feature_path): config_dir = os.path.join(base_dir, "config") if os.path.isdir(config_dir) is False: - raise Exception(f"no config directory {config_dir}") + raise Exception(f"not find config directory in {base_dir}") def parse_args( From 806a1c782dd872c555c1ea3ac74c555c3110dabc Mon Sep 17 00:00:00 2001 From: xingwenyang Date: Tue, 25 Jan 2022 17:44:25 +0800 Subject: [PATCH 5/6] fix: remove unused code --- flybirds/cli/parse_args.py | 45 -------------------------------------- 1 file changed, 45 deletions(-) diff --git a/flybirds/cli/parse_args.py b/flybirds/cli/parse_args.py index 467d6264..f6700360 100644 --- a/flybirds/cli/parse_args.py +++ b/flybirds/cli/parse_args.py @@ -22,51 +22,6 @@ def default_report_path(): return report_path -def check_workspace_args_bk(feature_path): - change_base_dir = None - base_dir = os.getcwd() - config_dir = os.path.join(base_dir, "config") - - if feature_path is not None and feature_path != 'features': - temp_path = os.path.normpath(feature_path) - if os.path.isabs(temp_path) is False: - temp_path = os.path.abspath(temp_path) - - if os.path.isfile(temp_path) is False and os.path.isdir( - temp_path) is False: - raise Exception(f"cannot find path:{temp_path}") - - path_array = temp_path.split(os.sep) - if path_array is not None and path_array.index("features") >= 1: - index = path_array.index("features") - config_path = path_array[0] - if path_array[0].find(":") >= 0: - config_path = os.path.join(config_path, os.sep) - for p in path_array[1:index]: - config_path = os.path.join(config_path, p) - - change_base_dir = config_path - else: - raise Exception( - f"cannot find features dir under path: {feature_path}") - - if os.path.isdir(config_dir) is False: - if change_base_dir is not None: - config_path = os.path.join(change_base_dir, "config") - if os.path.isdir(config_path) is False: - raise Exception(f"no config directory {config_path}") - else: - if change_base_dir != base_dir: - raise Exception(f"no config directory {config_path}") - # os.environ['base_dir'] = change_base_dir - else: - raise Exception(f"cannot find config path in {base_dir}") - else: - if change_base_dir is not None and change_base_dir != \ - base_dir: - os.environ['base_feature_dir'] = change_base_dir - - def check_workspace_args(feature_path): base_dir = os.getcwd() config_dir = os.path.join(base_dir, "config") From 3d0a96f5f95a15a8748e204f1358337e0fc5df9a Mon Sep 17 00:00:00 2001 From: xingwenyang Date: Tue, 25 Jan 2022 17:49:47 +0800 Subject: [PATCH 6/6] fix: remove unused code --- flybirds/report/fail_feature_create.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/flybirds/report/fail_feature_create.py b/flybirds/report/fail_feature_create.py index 0f0dc2a5..7cd3a920 100644 --- a/flybirds/report/fail_feature_create.py +++ b/flybirds/report/fail_feature_create.py @@ -388,7 +388,7 @@ def copy_behave_need_file(rerun_root_dir): copy step.py and environment.py and other behave files to feature path """ - cwd_pth = os.getcwd() + # cwd_pth = os.getcwd() # if os.environ.get('base_dir') is not None: # cwd_pth = os.environ.get('base_dir') # elif os.environ.get('base_feature_dir') is not None: @@ -396,15 +396,15 @@ def copy_behave_need_file(rerun_root_dir): file_helper.create_dirs(os.path.join(rerun_root_dir, "steps")) file_helper.clear_dirs(os.path.join(rerun_root_dir, "steps")) shutil.copy( - os.path.join(cwd_pth, "features", "steps", "steps.py"), + os.path.join(os.getcwd(), "features", "steps", "steps.py"), os.path.join(rerun_root_dir, "steps", "steps.py"), ) shutil.copy( - os.path.join(cwd_pth, "features", "environment.py"), + os.path.join(os.getcwd(), "features", "environment.py"), os.path.join(rerun_root_dir, "environment.py"), ) shutil.copy( - os.path.join(cwd_pth, "features", "__init__.py"), + os.path.join(os.getcwd(), "features", "__init__.py"), os.path.join(rerun_root_dir, "__init__.py"), )