From 8f5eb981f219e5f55014a10c610e6b10c7d5ba2e Mon Sep 17 00:00:00 2001 From: Qi Pan <43341456+Pan-Qi@users.noreply.github.com> Date: Fri, 21 Jun 2024 17:42:54 +1000 Subject: [PATCH] {CI} Fix cmdcov issue: remove `tested_command.txt` reference (#455) * Remove tested_command.txt * Remove extra blank line * add release --- HISTORY.rst | 4 +++ azdev/__init__.py | 2 +- azdev/operations/cmdcov/cmdcov.py | 57 ------------------------------- 3 files changed, 5 insertions(+), 58 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 5c039871..484b7f50 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,10 @@ Release History =============== +0.1.70 +++++++ +* Fix cmdcov issue(#455): remove tested_command.txt reference. + 0.1.69 ++++++ * `azdev command-change tree-export`: Add command help message. diff --git a/azdev/__init__.py b/azdev/__init__.py index 6e2b9bff..db461ad3 100644 --- a/azdev/__init__.py +++ b/azdev/__init__.py @@ -4,4 +4,4 @@ # license information. # ----------------------------------------------------------------------------- -__VERSION__ = '0.1.69' +__VERSION__ = '0.1.70' diff --git a/azdev/operations/cmdcov/cmdcov.py b/azdev/operations/cmdcov/cmdcov.py index 317ac53e..c4f1920e 100644 --- a/azdev/operations/cmdcov/cmdcov.py +++ b/azdev/operations/cmdcov/cmdcov.py @@ -58,7 +58,6 @@ def __init__(self, selected_mod_names=None, selected_mod_paths=None, loaded_help self.enable_cli_own = enable_cli_own self.all_commands = {m: [] for m in self.selected_mod_names} self.all_tested_commands = {m: [] for m in self.selected_mod_names} - self.all_live_commands = [] self.all_untested_commands = {} self.command_test_coverage = {'Total': [0, 0, 0]} self.date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) @@ -73,8 +72,6 @@ def run(self): self._get_all_tested_commands_from_regex() self._get_all_tested_commands_from_record() self._run_command_test_coverage() - self._get_all_tested_commands_from_live() - self._run_command_test_coverage_enhance() html_file = self._render_html() if self.enable_cli_own: command_test_coverage = {k: v for k, v in self.command_test_coverage.items() if k in CLI_OWN_MODULES} @@ -191,10 +188,6 @@ def _get_all_tested_commands_from_record(self): cmd = command + ' ' + argument self.all_tested_commands[self.selected_mod_names[idx]].append(cmd) - def _get_all_tested_commands_from_live(self): - with open(os.path.join(self.cmdcov_path, 'tested_command.txt'), 'r') as f: - self.all_live_commands = f.readlines() - def _run_command_test_coverage(self): """ all_commands: All commands that need to be test @@ -247,56 +240,6 @@ def _run_command_test_coverage(self): logger.warning(self.command_test_coverage) return self.command_test_coverage - def _run_command_test_coverage_enhance(self): - """ - all_untest_commands: {[module]:[],} - all_tested_commands_from_file: [] - command_test_coverage: {[module: [test, untested, pct] - module: vm - percentage: xx.xxx% - """ - import ast - total_tested = 0 - total_untested = 0 - # pylint: disable=too-many-nested-blocks - for module, untested_commands in self.all_untested_commands.items(): - for cmd_idx, command in enumerate(untested_commands): - exist_flag = False - prefix = command.rsplit('[', maxsplit=1)[0] - opt_list = ast.literal_eval('[' + command.rsplit('[', maxsplit=1)[1]) if self.level == 'argument' \ - else [] - for cmd in self.all_live_commands: - if prefix in cmd: - if self.level == 'argument': - for opt in opt_list: - if opt in cmd: - self.command_test_coverage[module][0] += 1 - untested_commands.pop(cmd_idx) - exist_flag = True - if exist_flag: - break - else: - self.command_test_coverage[module][0] += 1 - untested_commands.pop(cmd_idx) - exist_flag = True - if exist_flag: - break - if exist_flag: - break - try: - self.command_test_coverage[module][1] = len(untested_commands) - self.command_test_coverage[module][2] = f'''{self.command_test_coverage[module][0] / - (self.command_test_coverage[module][0] + - self.command_test_coverage[module][1]):.3%}''' - except ZeroDivisionError: - self.command_test_coverage[module] = [0, 0, 'N/A'] - total_tested += self.command_test_coverage[module][0] if self.command_test_coverage[module] else 0 - total_untested += self.command_test_coverage[module][1] if self.command_test_coverage[module] else 0 - self.command_test_coverage['Total'][0] = total_tested - self.command_test_coverage['Total'][1] = total_untested - self.command_test_coverage['Total'][2] = f'{total_tested / (total_tested + total_untested):.3%}' - logger.warning(self.command_test_coverage) - def _render_html(self): """ :return: Return a HTML string