From 2bcb1f2b4ec99701ca82c0c6ee81a98e50e65a27 Mon Sep 17 00:00:00 2001 From: Ariel Serafim Date: Thu, 19 Oct 2023 20:24:34 -0300 Subject: [PATCH 01/36] testig basic structure --- src/cli/commands/cmd_print_config.py | 31 ++++++++++++++++++++++++++++ src/cli/parsers.py | 21 ++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/cli/commands/cmd_print_config.py diff --git a/src/cli/commands/cmd_print_config.py b/src/cli/commands/cmd_print_config.py new file mode 100644 index 00000000..1421e9e8 --- /dev/null +++ b/src/cli/commands/cmd_print_config.py @@ -0,0 +1,31 @@ +import json +import logging +import sys +from pathlib import Path + +from rich.console import Console +from rich.prompt import Confirm +from staticfiles import DEFAULT_PRE_CONFIG + +from src.cli.utils import print_error, print_info, print_panel, print_rule +from src.config.settings import FILE_CONFIG + +logger = logging.getLogger("msgram") + + +def command_print_config(args): + # try: + # config_path: Path = args["config_path"] + + # except Exception as e: + # logger.error(f"KeyError: args[{e}] - non-existent parameters") + # print_error(f"KeyError: args[{e}] - non-existent parameters") + # sys.exit(1) + + console = Console() + console.clear() + print_rule("MSGram", "[#708090] TESTING [/]:") + + print_info( + f"Command was called!" + ) diff --git a/src/cli/parsers.py b/src/cli/parsers.py index 987b1671..ac45b847 100644 --- a/src/cli/parsers.py +++ b/src/cli/parsers.py @@ -2,7 +2,11 @@ from pathlib import Path -from src.cli.commands import command_init, command_extract, command_calculate +from src.cli.commands.cmd_init import command_init +from src.cli.commands.cmd_extract import command_extract +from src.cli.commands.cmd_calculate import command_calculate +from src.cli.commands.cmd_print_config import command_print_config + from src.config.settings import ( AVAILABLE_IMPORTS, SUPPORTED_FORMATS, @@ -39,6 +43,21 @@ def create_parser(): ) parser_init.set_defaults(func=command_init) # function command init + # =====================================< COMMAND print_config >===================================== + parser_print_config = subparsers.add_parser( + "print_config", + help="THIS MESSAGE IS FROM PARSER", + ) + + parser_print_config.add_argument( + "-hw", + "--hello_world", + type=lambda p: Path(p).absolute(), + default=DEFAULT_CONFIG_PATH, + help="HELP PARSER", + ) + parser_print_config.set_defaults(func=command_print_config) # function command print config + # =====================================< COMMAND extract >===================================== parser_extract = subparsers.add_parser("extract", help="Extract supported metrics") From 8ba1f7f89a9a18a5a53c3109b926f4867689367e Mon Sep 17 00:00:00 2001 From: Ana Carolina Rodrigues Date: Thu, 19 Oct 2023 20:44:32 -0300 Subject: [PATCH 02/36] testando --- src/cli/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cli/utils.py b/src/cli/utils.py index 44053418..4bde5f45 100644 --- a/src/cli/utils.py +++ b/src/cli/utils.py @@ -93,3 +93,5 @@ def print_panel(menssage: str, title: str = "Next steps"): width=140, ), ) + +# testegit \ No newline at end of file From 1c2ae77fa76e2d86e1b6a7c7917feb1271f821e6 Mon Sep 17 00:00:00 2001 From: Ana Carolina Rodrigues Date: Sun, 22 Oct 2023 11:47:05 -0300 Subject: [PATCH 03/36] Feat: Partial configuration tree listing --- src/cli/commands/cmd_print_config.py | 166 +++++++++++++++++++++++++-- src/cli/parsers.py | 28 +++-- 2 files changed, 172 insertions(+), 22 deletions(-) diff --git a/src/cli/commands/cmd_print_config.py b/src/cli/commands/cmd_print_config.py index 1421e9e8..75d8a5a2 100644 --- a/src/cli/commands/cmd_print_config.py +++ b/src/cli/commands/cmd_print_config.py @@ -5,27 +5,169 @@ from rich.console import Console from rich.prompt import Confirm -from staticfiles import DEFAULT_PRE_CONFIG +from rich.tree import Tree +from rich import print +from rich.prompt import Prompt +from staticfiles import DEFAULT_PRE_CONFIG as pre_config from src.cli.utils import print_error, print_info, print_panel, print_rule from src.config.settings import FILE_CONFIG logger = logging.getLogger("msgram") +def print_json_tree(data, indent=""): + output = [] + output.append("------------------------------ Listing Configuration Parameters ------------------------------") + key = data.get("key") + weight = data.get("weight", 0) + output.append(f"{indent}{key}\n") + output.append(f"{indent}Peso: {weight}%") -def command_print_config(args): - # try: - # config_path: Path = args["config_path"] + if "subcharacteristics" in data: + for subchar in data["subcharacteristics"]: + output.append(f"{indent}Subcaracteristica (s):") + output.extend(print_json_tree(subchar, indent + "| ")) + output.append(f"{indent}Fim-Subcaracteristica(s)") - # except Exception as e: - # logger.error(f"KeyError: args[{e}] - non-existent parameters") - # print_error(f"KeyError: args[{e}] - non-existent parameters") - # sys.exit(1) + if "measures" in data: + for measure in data["measures"]: + output.append(f"{indent}Medida (s):") + output.extend(print_json_tree(measure, indent + "| | ")) + output.append(f"{indent}Fim-Medida(s)") + + if "min_threshold" in data and "max_threshold" in data: + min_threshold = data.get("min_threshold") + max_threshold = data.get("max_threshold") + output.append(f"{indent}Metrica (s):") + output.append(f"{indent}| coverage") + output.append(f"{indent}| Peso: {weight}%") + output.append(f"{indent}| Valores de referência: Min: {min_threshold} e Max: {max_threshold}") + output.append(f"{indent}Fim-Metrica(s)") + + output.append(f"{indent}Fim-Caracteristica") + return output + +def command_list_config(): + try: + #config_path = args[none] + print("teste") + except Exception as e: + logger.error(f"KeyError: args[{e}] - non-existent parameters") + print_error(f"Parâmetro inválido. Para exibir a configuração do modelo, informe o parâmetro -config!") + sys.exit(1) + + logger.debug(config_path) + file_path = config_path / FILE_CONFIG console = Console() console.clear() - print_rule("MSGram", "[#708090] TESTING [/]:") + print_rule("MSGram", "[#708090] Reading of config file[/]:") + + data_print = [] + output = [] + + if not config_path.exists(): + output.append("\n [#A9A9A9] O arquivo de configuração não foi encontrado. Execute o comando msgram init para criá-lo.") + else: + output.append(f"MSGram config file [bold red]'{FILE_CONFIG}'[/] exists already!") + data_print = open_json_file(file_path) + for characteristic in data_print.get("characteristics", []): + output.extend(print_json_tree(characteristic)) + + output = "\n".join(output) + print_info(output) + + print_info("\n[#A9A9A9]Para editar o arquivo de configuração utilize em seu terminal o seguinte comando: vim ") + + + +# def command_list_config(args): +# try: +# config_path: Path = args["config"] + +# except Exception as e: +# logger.error(f"KeyError: args[{e}] - non-existent parameters") +# print_error(f"Parâmetro inválido. Para exibir a configuração do modelo, informe o parâmetro -config!") +# sys.exit(1) + +# logger.debug(config_path) +# file_path = config_path / FILE_CONFIG + +# console = Console() +# console.clear() +# print_rule("MSGram", "[#708090] Reading of config file[/]:") + +# data_print = {} +# if not config_path.exists(): +# print_info(f"O arquivo de configuração não foi encontrado. Execute o comando msgram init para criá-lo.") +# else: +# print_info(f"MSGram config file [bold red]'{FILE_CONFIG}'[/] exists already!") +# data_print = open_json_file(file_path) + +# import json + +# def print_json_tree(data, indent=""): +# print("---------------------------- Listing Configuration Parameters ---------------------------\n\n") +# key = data.get("key") +# weight = data.get("weight", 0) +# print(f"{indent}{key} \n\n") +# print(f"{indent}Peso: {weight}%") + +# if "subcharacteristics" in data: +# for subchar in data["subcharacteristics"]: +# print(f"{indent}Subcaracteristica (s):") +# print_json_tree(subchar, indent + "| ") + +# if "measures" in data: +# for measure in data["measures"]: +# print(f"{indent}Medida (s):") +# print_json_tree(measure, indent + "| | ") + +# if "min_threshold" in data and "max_threshold" in data: +# min_threshold = data.get("min_threshold") +# max_threshold = data.get("max_threshold") +# print(f"{indent}Metrica (s):") +# print(f"{indent}| coverage [Verde]") +# print(f"{indent}| Peso: {weight}%") +# print(f"{indent}| Valores de referência: Min: {min_threshold} e Max: {max_threshold}") + +# # # Carregue o JSON externo +# # with open('seuarquivo.json', 'r') as json_file: +# # json_data = json.load(json_file) + +# # Comece a partir das características +# for characteristic in json_data.get("characteristics", []): +# print_json_tree(characteristic) + +# print_info("\n[#A9A9A9]Para editar o arquivo de configuração utilize em seu terminal o seguinte comando: vim ") + + +# def get_obj_by_element(object_list: list, element_key: str, element_to_find): +# return next((obj for obj in object_list if obj[element_key] == element_to_find), {}) + +# def show_tree(data_calculated): +# tsqmi = data_calculated["tsqmi"][0] +# characteristics = data_calculated["characteristics"] +# subcharacteristics = data_calculated["subcharacteristics"] +# measures = data_calculated["measures"] +# metrics = data_calculated["metrics"] + +# print("---------------------------- Listing Configuration Parameters ---------------------------\n\n") +# tsqmi_tree = Tree("") + +# for char_c, char in zip(pre_config["characteristics"], characteristics): +# char_tree = tsqmi_tree.add(f"{char['Peso']}: [green]{char['weight']}") + +# for subchar_c in char_c["subcharacteristics"]: +# subchar = get_obj_by_element(subcharacteristics, "key", subchar_c["key"]) +# sub_char_tree = char_tree.add(f"{subchar['Peso']}: [green]{subchar['weight']}") + +# for measure_c in subchar_c["measures"]: +# measure = get_obj_by_element(measures, "key", measure_c["key"]) +# sub_char_tree.add(f"{measure['Peso']}: [green]{measure['weight']}") + +# for metric_c in measure_c["metrics"]: +# metric = get_obj_by_element(metrics, "metric", metric_c["metric"]) +# sub_char_tree.add(f"{metric['metric']} {metric['value']}") - print_info( - f"Command was called!" - ) +# print(tsqmi_tree) \ No newline at end of file diff --git a/src/cli/parsers.py b/src/cli/parsers.py index ac45b847..76f8a2da 100644 --- a/src/cli/parsers.py +++ b/src/cli/parsers.py @@ -5,7 +5,7 @@ from src.cli.commands.cmd_init import command_init from src.cli.commands.cmd_extract import command_extract from src.cli.commands.cmd_calculate import command_calculate -from src.cli.commands.cmd_print_config import command_print_config +from src.cli.commands.cmd_print_config import command_list_config from src.config.settings import ( AVAILABLE_IMPORTS, @@ -43,20 +43,28 @@ def create_parser(): ) parser_init.set_defaults(func=command_init) # function command init - # =====================================< COMMAND print_config >===================================== - parser_print_config = subparsers.add_parser( - "print_config", - help="THIS MESSAGE IS FROM PARSER", + # =====================================< COMMAND list_config >===================================== + parser_list_config = subparsers.add_parser( + "list", + help="Listing configurations parameters.", ) - parser_print_config.add_argument( - "-hw", - "--hello_world", + parser_list_config.add_argument( + "-cp", + "--config_path", type=lambda p: Path(p).absolute(), default=DEFAULT_CONFIG_PATH, - help="HELP PARSER", + help="Path to default config directory.", ) - parser_print_config.set_defaults(func=command_print_config) # function command print config + + parser_list_config.add_argument( + "all", + #type=str, + nargs="?", + help="Show configuration file.", + ) + + parser_list_config.set_defaults(func=command_list_config) # function command list config # =====================================< COMMAND extract >===================================== parser_extract = subparsers.add_parser("extract", help="Extract supported metrics") From f7a735230564b328f7c6653cf3a9ef38e9ff294a Mon Sep 17 00:00:00 2001 From: ArielSixwings Date: Sun, 22 Oct 2023 12:52:26 -0300 Subject: [PATCH 04/36] fix: list initial usage --- src/cli/commands/cmd_print_config.py | 169 +++++---------------------- src/cli/parsers.py | 2 + 2 files changed, 34 insertions(+), 137 deletions(-) diff --git a/src/cli/commands/cmd_print_config.py b/src/cli/commands/cmd_print_config.py index 75d8a5a2..8a9f3dfb 100644 --- a/src/cli/commands/cmd_print_config.py +++ b/src/cli/commands/cmd_print_config.py @@ -1,173 +1,68 @@ import json import logging +import os import sys from pathlib import Path from rich.console import Console from rich.prompt import Confirm -from rich.tree import Tree -from rich import print -from rich.prompt import Prompt -from staticfiles import DEFAULT_PRE_CONFIG as pre_config +from staticfiles import DEFAULT_PRE_CONFIG from src.cli.utils import print_error, print_info, print_panel, print_rule from src.config.settings import FILE_CONFIG +from src.config.settings import DEFAULT_CONFIG_FILE_PATH +from src.config.settings import DEFAULT_CONFIG_PATH logger = logging.getLogger("msgram") -def print_json_tree(data, indent=""): - output = [] - output.append("------------------------------ Listing Configuration Parameters ------------------------------") +def print_json_tree(data, indent="",isTop = True): + if isTop: + print_info("---------------------------- Listing Configuration Parameters ---------------------------\n\n") + key = data.get("key") + print_info(f"{indent}{key}") + weight = data.get("weight", 0) - output.append(f"{indent}{key}\n") - output.append(f"{indent}Peso: {weight}%") + print_info(f"{indent}Peso: {weight}%") if "subcharacteristics" in data: for subchar in data["subcharacteristics"]: - output.append(f"{indent}Subcaracteristica (s):") - output.extend(print_json_tree(subchar, indent + "| ")) - output.append(f"{indent}Fim-Subcaracteristica(s)") + print_info(f"{indent}Subcaracteristica (s):") + print_json_tree(subchar, indent + "| ",False) if "measures" in data: for measure in data["measures"]: - output.append(f"{indent}Medida (s):") - output.extend(print_json_tree(measure, indent + "| | ")) - output.append(f"{indent}Fim-Medida(s)") + print_info(f"{indent}Medida (s):") + print_json_tree(measure, indent + "| | ",False) if "min_threshold" in data and "max_threshold" in data: min_threshold = data.get("min_threshold") max_threshold = data.get("max_threshold") - output.append(f"{indent}Metrica (s):") - output.append(f"{indent}| coverage") - output.append(f"{indent}| Peso: {weight}%") - output.append(f"{indent}| Valores de referência: Min: {min_threshold} e Max: {max_threshold}") - output.append(f"{indent}Fim-Metrica(s)") - - output.append(f"{indent}Fim-Caracteristica") - return output - -def command_list_config(): - try: - #config_path = args[none] - print("teste") - except Exception as e: - logger.error(f"KeyError: args[{e}] - non-existent parameters") - print_error(f"Parâmetro inválido. Para exibir a configuração do modelo, informe o parâmetro -config!") - sys.exit(1) - - logger.debug(config_path) - file_path = config_path / FILE_CONFIG + print_info(f"{indent}Metrica (s):") + print_info(f"{indent}| [#458B00]coverage") + print_info(f"{indent}| Peso: {weight}%") + print_info(f"{indent}| Valores de referência: Min: {min_threshold} e Max: {max_threshold}") +def command_list_config(args): + console = Console() console.clear() - print_rule("MSGram", "[#708090] Reading of config file[/]:") - - data_print = [] - output = [] - - if not config_path.exists(): - output.append("\n [#A9A9A9] O arquivo de configuração não foi encontrado. Execute o comando msgram init para criá-lo.") - else: - output.append(f"MSGram config file [bold red]'{FILE_CONFIG}'[/] exists already!") - data_print = open_json_file(file_path) - for characteristic in data_print.get("characteristics", []): - output.extend(print_json_tree(characteristic)) - - output = "\n".join(output) - print_info(output) - - print_info("\n[#A9A9A9]Para editar o arquivo de configuração utilize em seu terminal o seguinte comando: vim ") - - - -# def command_list_config(args): -# try: -# config_path: Path = args["config"] - -# except Exception as e: -# logger.error(f"KeyError: args[{e}] - non-existent parameters") -# print_error(f"Parâmetro inválido. Para exibir a configuração do modelo, informe o parâmetro -config!") -# sys.exit(1) - -# logger.debug(config_path) -# file_path = config_path / FILE_CONFIG - -# console = Console() -# console.clear() -# print_rule("MSGram", "[#708090] Reading of config file[/]:") -# data_print = {} -# if not config_path.exists(): -# print_info(f"O arquivo de configuração não foi encontrado. Execute o comando msgram init para criá-lo.") -# else: -# print_info(f"MSGram config file [bold red]'{FILE_CONFIG}'[/] exists already!") -# data_print = open_json_file(file_path) - -# import json - -# def print_json_tree(data, indent=""): -# print("---------------------------- Listing Configuration Parameters ---------------------------\n\n") -# key = data.get("key") -# weight = data.get("weight", 0) -# print(f"{indent}{key} \n\n") -# print(f"{indent}Peso: {weight}%") - -# if "subcharacteristics" in data: -# for subchar in data["subcharacteristics"]: -# print(f"{indent}Subcaracteristica (s):") -# print_json_tree(subchar, indent + "| ") - -# if "measures" in data: -# for measure in data["measures"]: -# print(f"{indent}Medida (s):") -# print_json_tree(measure, indent + "| | ") - -# if "min_threshold" in data and "max_threshold" in data: -# min_threshold = data.get("min_threshold") -# max_threshold = data.get("max_threshold") -# print(f"{indent}Metrica (s):") -# print(f"{indent}| coverage [Verde]") -# print(f"{indent}| Peso: {weight}%") -# print(f"{indent}| Valores de referência: Min: {min_threshold} e Max: {max_threshold}") - -# # # Carregue o JSON externo -# # with open('seuarquivo.json', 'r') as json_file: -# # json_data = json.load(json_file) - -# # Comece a partir das características -# for characteristic in json_data.get("characteristics", []): -# print_json_tree(characteristic) - -# print_info("\n[#A9A9A9]Para editar o arquivo de configuração utilize em seu terminal o seguinte comando: vim ") - - -# def get_obj_by_element(object_list: list, element_key: str, element_to_find): -# return next((obj for obj in object_list if obj[element_key] == element_to_find), {}) + print_rule("MSGram", "[#708090] Reading of config file[/]:") -# def show_tree(data_calculated): -# tsqmi = data_calculated["tsqmi"][0] -# characteristics = data_calculated["characteristics"] -# subcharacteristics = data_calculated["subcharacteristics"] -# measures = data_calculated["measures"] -# metrics = data_calculated["metrics"] + if not (os.path.exists(DEFAULT_CONFIG_FILE_PATH)): + print_info( f"[#A9A9A9] O arquivo de configuração não foi encontrado. Execute o comando msgram init para criá-lo." ) + exit() + + print_info(f"MSGram config file [bold red]'{FILE_CONFIG}'[/] exists already!") -# print("---------------------------- Listing Configuration Parameters ---------------------------\n\n") -# tsqmi_tree = Tree("") + f = open(DEFAULT_CONFIG_FILE_PATH) + data = json.load(f) -# for char_c, char in zip(pre_config["characteristics"], characteristics): -# char_tree = tsqmi_tree.add(f"{char['Peso']}: [green]{char['weight']}") -# for subchar_c in char_c["subcharacteristics"]: -# subchar = get_obj_by_element(subcharacteristics, "key", subchar_c["key"]) -# sub_char_tree = char_tree.add(f"{subchar['Peso']}: [green]{subchar['weight']}") + for characteristic in data.get("characteristics", []): + print_json_tree(characteristic) -# for measure_c in subchar_c["measures"]: -# measure = get_obj_by_element(measures, "key", measure_c["key"]) -# sub_char_tree.add(f"{measure['Peso']}: [green]{measure['weight']}") -# for metric_c in measure_c["metrics"]: -# metric = get_obj_by_element(metrics, "metric", metric_c["metric"]) -# sub_char_tree.add(f"{metric['metric']} {metric['value']}") -# print(tsqmi_tree) \ No newline at end of file + print_info("\n[#A9A9A9]Para editar o arquivo de configuração utilize em seu terminal o seguinte comando: vim ") \ No newline at end of file diff --git a/src/cli/parsers.py b/src/cli/parsers.py index 76f8a2da..8d20733b 100644 --- a/src/cli/parsers.py +++ b/src/cli/parsers.py @@ -66,6 +66,8 @@ def create_parser(): parser_list_config.set_defaults(func=command_list_config) # function command list config + + # =====================================< COMMAND extract >===================================== parser_extract = subparsers.add_parser("extract", help="Extract supported metrics") From c7c1de90b08bc99d174033a92c0692afbc1ea210 Mon Sep 17 00:00:00 2001 From: ArielSixwings Date: Sun, 22 Oct 2023 12:59:28 -0300 Subject: [PATCH 05/36] fix: list initial usage --- src/config/msgram.json | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/config/msgram.json diff --git a/src/config/msgram.json b/src/config/msgram.json new file mode 100644 index 00000000..7b179b35 --- /dev/null +++ b/src/config/msgram.json @@ -0,0 +1,64 @@ +{ + "characteristics": [ + { + "key": "reliability", + "weight": 50, + "subcharacteristics": [ + { + "key": "testing_status", + "weight": 100, + "measures": [ + { + "key": "passed_tests", + "weight": 33, + "min_passed_tests": 0, + "max_passed_tests": 1 + }, + { + "key": "test_builds", + "weight": 33, + "min_fast_test_time": 0, + "max_fast_test_time": 300000 + }, + { + "key": "test_coverage", + "weight": 34, + "min_coverage": 60, + "max_coverage": 100 + } + ] + } + ] + }, + { + "key": "maintainability", + "weight": 50, + "subcharacteristics": [ + { + "key": "modifiability", + "weight": 100, + "measures": [ + { + "key": "non_complex_file_density", + "weight": 33, + "min_complex_files_density": 0, + "max_complex_files_density": 10 + }, + { + "key": "commented_file_density", + "weight": 33, + "min_comment_density": 10, + "max_comment_density": 30 + }, + { + "key": "duplication_absense", + "weight": 34, + "min_duplicated_lines": 0, + "max_duplicated_lines": 5 + } + ] + } + ] + } + ] +} \ No newline at end of file From 514bf0d816d65b2c903457bff30185b670687806 Mon Sep 17 00:00:00 2001 From: ArielSixwings Date: Sun, 22 Oct 2023 15:17:53 -0300 Subject: [PATCH 06/36] feat: Improved config presentation Co-Authored-by: Ana Carolina Rodrigues --- src/cli/commands/cmd_print_config.py | 36 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/cli/commands/cmd_print_config.py b/src/cli/commands/cmd_print_config.py index 8a9f3dfb..06fbfb30 100644 --- a/src/cli/commands/cmd_print_config.py +++ b/src/cli/commands/cmd_print_config.py @@ -16,32 +16,37 @@ logger = logging.getLogger("msgram") def print_json_tree(data, indent="",isTop = True): - if isTop: - print_info("---------------------------- Listing Configuration Parameters ---------------------------\n\n") - key = data.get("key") - print_info(f"{indent}{key}") + + if isTop: + print_info("\n\n") + print_info("---------------------------- Listing Configuration Parameters ---------------------------\n") + print_info(f"[#FFFFFF]{indent}[#458B00]{key}") + else: + print_info(f"[#FFFFFF]{indent}[#458B00]{key}") weight = data.get("weight", 0) - print_info(f"{indent}Peso: {weight}%") + print_info(f"[#FFFFFF]{indent}Peso: [#458B00]{weight}%") if "subcharacteristics" in data: for subchar in data["subcharacteristics"]: - print_info(f"{indent}Subcaracteristica (s):") - print_json_tree(subchar, indent + "| ",False) + print_info(f"[#FFFFFF]{indent}Subcaracteristica (s):") + print_json_tree(subchar, indent + "| ",False) + print_info(f"[#FFFFFF]{indent}Fim-Subcaracteristica(s)\n") if "measures" in data: for measure in data["measures"]: - print_info(f"{indent}Medida (s):") - print_json_tree(measure, indent + "| | ",False) + print_info(f"[#FFFFFF]{indent}{indent}Medida (s):") + print_json_tree(measure, indent + "| | ",False) + print_info(f"[#FFFFFF]{indent}{indent}Fim-Medida(s)\n") if "min_threshold" in data and "max_threshold" in data: min_threshold = data.get("min_threshold") max_threshold = data.get("max_threshold") - print_info(f"{indent}Metrica (s):") - print_info(f"{indent}| [#458B00]coverage") - print_info(f"{indent}| Peso: {weight}%") - print_info(f"{indent}| Valores de referência: Min: {min_threshold} e Max: {max_threshold}") + print_info(f"[#FFFFFF]{indent}Metrica (s):") + print_info(f"[#FFFFFF]{indent}| [#458B00]coverage") + print_info(f"[#FFFFFF]{indent}| Peso: [#458B00]{weight}%") + print_info(f"[#FFFFFF]{indent}| Valores de referência: Min: [#458B00]{min_threshold} [#FFFFFF]e Max: [#458B00]{max_threshold}") def command_list_config(args): @@ -60,8 +65,11 @@ def command_list_config(args): data = json.load(f) + isTop = True for characteristic in data.get("characteristics", []): - print_json_tree(characteristic) + print_json_tree(characteristic,"",isTop) + print_info(f"[#FFFFFF]Fim-Caracteristica(s)\n") + isTop = False From 7f013447bec31a264e279399dbdb5adf55bcad1d Mon Sep 17 00:00:00 2001 From: Ana Carolina Rodrigues Date: Sun, 22 Oct 2023 15:26:28 -0300 Subject: [PATCH 07/36] Fix: Add indent --- src/cli/commands/cmd_print_config.py | 59 +++++++++++++--------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/src/cli/commands/cmd_print_config.py b/src/cli/commands/cmd_print_config.py index 06fbfb30..9ea93d67 100644 --- a/src/cli/commands/cmd_print_config.py +++ b/src/cli/commands/cmd_print_config.py @@ -13,64 +13,59 @@ from src.config.settings import DEFAULT_CONFIG_FILE_PATH from src.config.settings import DEFAULT_CONFIG_PATH -logger = logging.getLogger("msgram") - -def print_json_tree(data, indent="",isTop = True): +def print_json_tree(data, indent="", isTop = True): key = data.get("key") + value = data.get("metric") if isTop: - print_info("\n\n") - print_info("---------------------------- Listing Configuration Parameters ---------------------------\n") - print_info(f"[#FFFFFF]{indent}[#458B00]{key}") + print_info(f"[#FFFFFF]\nCaracterística:") + print_info(f"[#FFFFFF]{indent}{indent}[#458B00]{key}") else: - print_info(f"[#FFFFFF]{indent}[#458B00]{key}") + print_info(f"[#FFFFFF]{indent}{indent}[#458B00]{key}") weight = data.get("weight", 0) - print_info(f"[#FFFFFF]{indent}Peso: [#458B00]{weight}%") + print_info(f"[#FFFFFF]{indent}{indent}Peso: [#458B00]{weight}%") if "subcharacteristics" in data: for subchar in data["subcharacteristics"]: print_info(f"[#FFFFFF]{indent}Subcaracteristica (s):") - print_json_tree(subchar, indent + "| ",False) - print_info(f"[#FFFFFF]{indent}Fim-Subcaracteristica(s)\n") + print_json_tree(subchar, indent + "| ",False) + print_info(f"[#FFFFFF]{indent}{indent}Fim-Subcaracterística\n") if "measures" in data: for measure in data["measures"]: print_info(f"[#FFFFFF]{indent}{indent}Medida (s):") - print_json_tree(measure, indent + "| | ",False) + print_json_tree(measure, indent + "| ",False) print_info(f"[#FFFFFF]{indent}{indent}Fim-Medida(s)\n") if "min_threshold" in data and "max_threshold" in data: - min_threshold = data.get("min_threshold") - max_threshold = data.get("max_threshold") - print_info(f"[#FFFFFF]{indent}Metrica (s):") - print_info(f"[#FFFFFF]{indent}| [#458B00]coverage") - print_info(f"[#FFFFFF]{indent}| Peso: [#458B00]{weight}%") - print_info(f"[#FFFFFF]{indent}| Valores de referência: Min: [#458B00]{min_threshold} [#FFFFFF]e Max: [#458B00]{max_threshold}") + print_info(f"[#FFFFFF]{indent}{indent}Métrica (s):") + value = data.get("metric") + #print_info("{indent} | | | {value}") + min_threshold = data.get("min_threshold") + max_threshold = data.get("max_threshold") + print_info(f"[#FFFFFF]{indent}| Valores de referência: Min: [#458B00]{min_threshold} [#FFFFFF]e Max: [#458B00]{max_threshold}") + print_info(f"[#FFFFFF]{indent}{indent}Fim-Metrica(s)\n") def command_list_config(args): - console = Console() console.clear() - print_rule("MSGram", "[#708090] Reading of config file[/]:") + print_rule("[#FFFFFF] Listing Configuration Parameters[/]:") if not (os.path.exists(DEFAULT_CONFIG_FILE_PATH)): print_info( f"[#A9A9A9] O arquivo de configuração não foi encontrado. Execute o comando msgram init para criá-lo." ) exit() - - print_info(f"MSGram config file [bold red]'{FILE_CONFIG}'[/] exists already!") - - f = open(DEFAULT_CONFIG_FILE_PATH) - data = json.load(f) - - - isTop = True - for characteristic in data.get("characteristics", []): - print_json_tree(characteristic,"",isTop) - print_info(f"[#FFFFFF]Fim-Caracteristica(s)\n") - isTop = False + else: + print_info(f"MSGram config file [bold red]'{FILE_CONFIG}'[/] exists already!") + f = open(DEFAULT_CONFIG_FILE_PATH) + data = json.load(f) + isTop = True + for data in data.get("characteristics", []): + print_json_tree(data, "", isTop) + print_info(f"[#FFFFFF]Fim-Característica\n") + isTop = False - print_info("\n[#A9A9A9]Para editar o arquivo de configuração utilize em seu terminal o seguinte comando: vim ") \ No newline at end of file + print_info("\n[#A9A9A9]Para editar o arquivo de configuração utilize em seu terminal o seguinte comando: vim ") \ No newline at end of file From 12f59e321b6a201b9cd4ab8050dd2fc5d9c68a93 Mon Sep 17 00:00:00 2001 From: ArielSixwings Date: Sun, 22 Oct 2023 15:28:14 -0300 Subject: [PATCH 08/36] fix: fix identation --- src/cli/commands/cmd_print_config.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/cli/commands/cmd_print_config.py b/src/cli/commands/cmd_print_config.py index 9ea93d67..15eb75bb 100644 --- a/src/cli/commands/cmd_print_config.py +++ b/src/cli/commands/cmd_print_config.py @@ -56,16 +56,17 @@ def command_list_config(args): if not (os.path.exists(DEFAULT_CONFIG_FILE_PATH)): print_info( f"[#A9A9A9] O arquivo de configuração não foi encontrado. Execute o comando msgram init para criá-lo." ) exit() - else: - print_info(f"MSGram config file [bold red]'{FILE_CONFIG}'[/] exists already!") + + print_info(f"MSGram config file [bold red]'{FILE_CONFIG}'[/] exists already!") - f = open(DEFAULT_CONFIG_FILE_PATH) - data = json.load(f) + f = open(DEFAULT_CONFIG_FILE_PATH) + + data = json.load(f) - isTop = True - for data in data.get("characteristics", []): - print_json_tree(data, "", isTop) - print_info(f"[#FFFFFF]Fim-Característica\n") - isTop = False + isTop = True + for data in data.get("characteristics", []): + print_json_tree(data, "", isTop) + print_info(f"[#FFFFFF]Fim-Característica\n") + isTop = False - print_info("\n[#A9A9A9]Para editar o arquivo de configuração utilize em seu terminal o seguinte comando: vim ") \ No newline at end of file + print_info("\n[#A9A9A9]Para editar o arquivo de configuração utilize em seu terminal o seguinte comando: vim ") \ No newline at end of file From efb5df063cd78a76cafd408e0ec006d25d94acea Mon Sep 17 00:00:00 2001 From: Ana Carolina Rodrigues Date: Sun, 22 Oct 2023 15:44:09 -0300 Subject: [PATCH 09/36] Fix: fixing indentation --- src/cli/commands/cmd_print_config.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cli/commands/cmd_print_config.py b/src/cli/commands/cmd_print_config.py index 15eb75bb..7ce71a04 100644 --- a/src/cli/commands/cmd_print_config.py +++ b/src/cli/commands/cmd_print_config.py @@ -28,24 +28,24 @@ def print_json_tree(data, indent="", isTop = True): if "subcharacteristics" in data: for subchar in data["subcharacteristics"]: - print_info(f"[#FFFFFF]{indent}Subcaracteristica (s):") + print_info(f"[#FFFFFF]{indent}Subcaracteristica(s):") print_json_tree(subchar, indent + "| ",False) - print_info(f"[#FFFFFF]{indent}{indent}Fim-Subcaracterística\n") + print_info(f"[#FFFFFF]{indent}{indent}Fim-Subcaracterística") if "measures" in data: for measure in data["measures"]: - print_info(f"[#FFFFFF]{indent}{indent}Medida (s):") + print_info(f"[#FFFFFF]{indent}{indent}Medida(s):") print_json_tree(measure, indent + "| ",False) - print_info(f"[#FFFFFF]{indent}{indent}Fim-Medida(s)\n") + print_info(f"[#FFFFFF]{indent}{indent}Fim-Medida(s)") if "min_threshold" in data and "max_threshold" in data: - print_info(f"[#FFFFFF]{indent}{indent}Métrica (s):") + print_info(f"[#FFFFFF]{indent}{indent}Métrica(s):") value = data.get("metric") #print_info("{indent} | | | {value}") min_threshold = data.get("min_threshold") max_threshold = data.get("max_threshold") print_info(f"[#FFFFFF]{indent}| Valores de referência: Min: [#458B00]{min_threshold} [#FFFFFF]e Max: [#458B00]{max_threshold}") - print_info(f"[#FFFFFF]{indent}{indent}Fim-Metrica(s)\n") + print_info(f"[#FFFFFF]{indent}{indent}Fim-Metrica(s)") def command_list_config(args): console = Console() From 64c33029a9adc31d2b3f850efa0f77d3a08db1c8 Mon Sep 17 00:00:00 2001 From: ArielSixwings Date: Sun, 22 Oct 2023 16:08:24 -0300 Subject: [PATCH 10/36] refactor: Removed unused Co-Authored-by: Ana Carolina Rodrigues --- src/cli/commands/cmd_print_config.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/cli/commands/cmd_print_config.py b/src/cli/commands/cmd_print_config.py index 7ce71a04..46043bbd 100644 --- a/src/cli/commands/cmd_print_config.py +++ b/src/cli/commands/cmd_print_config.py @@ -1,21 +1,15 @@ -import json -import logging -import os -import sys -from pathlib import Path - from rich.console import Console -from rich.prompt import Confirm -from staticfiles import DEFAULT_PRE_CONFIG -from src.cli.utils import print_error, print_info, print_panel, print_rule +from src.cli.utils import print_info, print_rule + from src.config.settings import FILE_CONFIG from src.config.settings import DEFAULT_CONFIG_FILE_PATH -from src.config.settings import DEFAULT_CONFIG_PATH + +import json +import os def print_json_tree(data, indent="", isTop = True): key = data.get("key") - value = data.get("metric") if isTop: print_info(f"[#FFFFFF]\nCaracterística:") @@ -40,8 +34,6 @@ def print_json_tree(data, indent="", isTop = True): if "min_threshold" in data and "max_threshold" in data: print_info(f"[#FFFFFF]{indent}{indent}Métrica(s):") - value = data.get("metric") - #print_info("{indent} | | | {value}") min_threshold = data.get("min_threshold") max_threshold = data.get("max_threshold") print_info(f"[#FFFFFF]{indent}| Valores de referência: Min: [#458B00]{min_threshold} [#FFFFFF]e Max: [#458B00]{max_threshold}") @@ -69,4 +61,7 @@ def command_list_config(args): print_info(f"[#FFFFFF]Fim-Característica\n") isTop = False - print_info("\n[#A9A9A9]Para editar o arquivo de configuração utilize em seu terminal o seguinte comando: vim ") \ No newline at end of file + print_info( + "\n[#A9A9A9]Para editar o arquivo de configuração utilize em seu terminal o seguinte comando: vim " + ) + From 5510ec60abfa38002a330bccbd2adf891af21a87 Mon Sep 17 00:00:00 2001 From: ArielSixwings Date: Sun, 22 Oct 2023 19:32:16 -0300 Subject: [PATCH 11/36] refactor: modify print of configuration to be testable --- src/cli/commands/cmd_print_config.py | 85 +++++++++++++++------------- tests/unit/data/expected_list.txt | 29 ++++++++++ tests/unit/test_print_config.py | 27 +++++++++ 3 files changed, 101 insertions(+), 40 deletions(-) create mode 100644 tests/unit/data/expected_list.txt create mode 100644 tests/unit/test_print_config.py diff --git a/src/cli/commands/cmd_print_config.py b/src/cli/commands/cmd_print_config.py index 46043bbd..b6faff89 100644 --- a/src/cli/commands/cmd_print_config.py +++ b/src/cli/commands/cmd_print_config.py @@ -8,36 +8,43 @@ import json import os -def print_json_tree(data, indent="", isTop = True): - key = data.get("key") - - if isTop: - print_info(f"[#FFFFFF]\nCaracterística:") - print_info(f"[#FFFFFF]{indent}{indent}[#458B00]{key}") - else: - print_info(f"[#FFFFFF]{indent}{indent}[#458B00]{key}") - - weight = data.get("weight", 0) - print_info(f"[#FFFFFF]{indent}{indent}Peso: [#458B00]{weight}%") - - if "subcharacteristics" in data: - for subchar in data["subcharacteristics"]: - print_info(f"[#FFFFFF]{indent}Subcaracteristica(s):") - print_json_tree(subchar, indent + "| ",False) - print_info(f"[#FFFFFF]{indent}{indent}Fim-Subcaracterística") - - if "measures" in data: - for measure in data["measures"]: - print_info(f"[#FFFFFF]{indent}{indent}Medida(s):") - print_json_tree(measure, indent + "| ",False) - print_info(f"[#FFFFFF]{indent}{indent}Fim-Medida(s)") - - if "min_threshold" in data and "max_threshold" in data: - print_info(f"[#FFFFFF]{indent}{indent}Métrica(s):") - min_threshold = data.get("min_threshold") - max_threshold = data.get("max_threshold") - print_info(f"[#FFFFFF]{indent}| Valores de referência: Min: [#458B00]{min_threshold} [#FFFFFF]e Max: [#458B00]{max_threshold}") - print_info(f"[#FFFFFF]{indent}{indent}Fim-Metrica(s)") +def print_json_tree(data): + result = [] # Initialize an empty list to store the output as strings + stack = [(data, "")] + + while stack: + data, indent = stack.pop() + + key = data.get("key") + result.append(f"[#FFFFFF]\nCaracterística:") + result.append(f"[#FFFFFF]{indent}[#458B00]{key}") + + weight = data.get("weight", 0) + result.append(f"[#FFFFFF]{indent}Peso: [#458B00]{weight}%") + + if "subcharacteristics" in data: + for subchar in data["subcharacteristics"]: + result.append(f"[#FFFFFF]{indent}Subcaracteristica(s):") + stack.append((subchar, f"{indent}| ")) + + if "measures" in data: + result.append(f"[#FFFFFF]{indent}Medida(s):") + for measure in data["measures"]: + result.append(f"[#FFFFFF]{indent}| [#458B00]{measure['key']}") + result.append(f"[#FFFFFF]{indent}| Peso: [#458B00]{measure['weight']}%") + if "min_threshold" in measure and "max_threshold" in measure: + min_threshold = measure.get("min_threshold") + max_threshold = measure.get("max_threshold") + result.append(f"[#FFFFFF]{indent}| Métrica(s):") + result.append(f"[#FFFFFF]{indent}| | Valores de referência: Min: [#458B00]{min_threshold} [#FFFFFF]e Max: [#458B00]{max_threshold}") + result.append(f"[#FFFFFF]{indent}| Fim-Metrica(s)") + result.append(f"[#FFFFFF]{indent}Fim-Medida(s)") + result.append("[#FFFFFF]Fim-SubCaracterística") + + result.append("[#FFFFFF]Fim-Característica") + + # Join the result list into a single string with newlines + return '\n'.join(result) def command_list_config(args): console = Console() @@ -46,22 +53,20 @@ def command_list_config(args): print_rule("[#FFFFFF] Listing Configuration Parameters[/]:") if not (os.path.exists(DEFAULT_CONFIG_FILE_PATH)): - print_info( f"[#A9A9A9] O arquivo de configuração não foi encontrado. Execute o comando msgram init para criá-lo." ) + print_info(f"[#A9A9A9] O arquivo de configuração não foi encontrado. Execute o comando msgram init para criá-lo.") exit() - + print_info(f"MSGram config file [bold red]'{FILE_CONFIG}'[/] exists already!") f = open(DEFAULT_CONFIG_FILE_PATH) - + data = json.load(f) - isTop = True - for data in data.get("characteristics", []): - print_json_tree(data, "", isTop) - print_info(f"[#FFFFFF]Fim-Característica\n") - isTop = False + for characteristic in data.get("characteristics", []): + output_string = print_json_tree(characteristic) + print_info(output_string) print_info( "\n[#A9A9A9]Para editar o arquivo de configuração utilize em seu terminal o seguinte comando: vim " - ) - + ) + diff --git a/tests/unit/data/expected_list.txt b/tests/unit/data/expected_list.txt new file mode 100644 index 00000000..8149f4c9 --- /dev/null +++ b/tests/unit/data/expected_list.txt @@ -0,0 +1,29 @@ + +[#FFFFFF]Característica: +reliability +[#FFFFFF]Peso: 50% +[#FFFFFF]Subcaracteristica(s): +[#FFFFFF]Fim-Subcaracterística +| | testing_status +| | [#FFFFFF]Peso: 100% +| | [#FFFFFF]Medida(s): +| | [#FFFFFF]Fim-Medida(s) +| | [#FFFFFF]Medida(s): +| | [#FFFFFF]Fim-Medida(s) +| | Medida(s): +| | Fim-Medida(s) +| | | | test_coverage +| | | | Peso: 34% +| | | | Métrica(s): +| | | Valores de referência: Min: 60 e Max: 100 +| | | | Fim-Metrica(s) +| | | | test_builds +| | | | Peso: 33% +| | | | Métrica(s): +| | | Valores de referência: Min: 0 e Max: 300000 +| | | | Fim-Metrica(s) +| | | | passed_tests +| | | | Peso: 33% +| | | | Métrica(s): +| | | Valores de referência: Min: 0 e Max: 1 +| | | | Fim-Metrica(s) diff --git a/tests/unit/test_print_config.py b/tests/unit/test_print_config.py new file mode 100644 index 00000000..ccb6bfc4 --- /dev/null +++ b/tests/unit/test_print_config.py @@ -0,0 +1,27 @@ +import unittest +from unittest.mock import patch +from io import StringIO +import sys +import json + +from src.cli.commands.cmd_print_config import print_json_tree +from src.cli.utils import print_info, print_rule + + +def test_print_json_tree(): + + file = open("tests/unit/data/msgram.json") + data = json.load(file) + + captured_output = StringIO() + sys.stdout = captured_output + + characteristics = data.get("characteristics", []) + + result = print_json_tree(characteristics[0]) + + fileExpected = open("tests/unit/data/expected_list.txt") + + compare = fileExpected.read() + + assert result == compare \ No newline at end of file From dfd0602da0694f47b22e8a1a7129165a4a81ea9c Mon Sep 17 00:00:00 2001 From: ArielSixwings Date: Sun, 22 Oct 2023 19:51:21 -0300 Subject: [PATCH 12/36] test: Add test_print_config Co-Authored-by: Ana Carolina Rodrigues --- tests/unit/data/expected_list.txt | 56 +++++++++++++-------------- tests/unit/data/newmsgram.json | 64 +++++++++++++++++++++++++++++++ tests/unit/test_print_config.py | 11 +++++- 3 files changed, 102 insertions(+), 29 deletions(-) create mode 100644 tests/unit/data/newmsgram.json diff --git a/tests/unit/data/expected_list.txt b/tests/unit/data/expected_list.txt index 8149f4c9..060a240d 100644 --- a/tests/unit/data/expected_list.txt +++ b/tests/unit/data/expected_list.txt @@ -1,29 +1,29 @@ - -[#FFFFFF]Característica: +Característica: reliability -[#FFFFFF]Peso: 50% -[#FFFFFF]Subcaracteristica(s): -[#FFFFFF]Fim-Subcaracterística -| | testing_status -| | [#FFFFFF]Peso: 100% -| | [#FFFFFF]Medida(s): -| | [#FFFFFF]Fim-Medida(s) -| | [#FFFFFF]Medida(s): -| | [#FFFFFF]Fim-Medida(s) -| | Medida(s): -| | Fim-Medida(s) -| | | | test_coverage -| | | | Peso: 34% -| | | | Métrica(s): -| | | Valores de referência: Min: 60 e Max: 100 -| | | | Fim-Metrica(s) -| | | | test_builds -| | | | Peso: 33% -| | | | Métrica(s): -| | | Valores de referência: Min: 0 e Max: 300000 -| | | | Fim-Metrica(s) -| | | | passed_tests -| | | | Peso: 33% -| | | | Métrica(s): -| | | Valores de referência: Min: 0 e Max: 1 -| | | | Fim-Metrica(s) +Peso: 50% +Subcaracteristica(s): + +Característica: +| testing_status +| Peso: 100% +| Medida(s): +| | passed_tests +| | Peso: 33% +| | Métrica(s): +| | | Valores de referência: Min: 0 e Max: 1 +| | Fim-Metrica(s) +| Fim-Medida(s) +| | test_builds +| | Peso: 33% +| | Métrica(s): +| | | Valores de referência: Min: 0 e Max: 300000 +| | Fim-Metrica(s) +| Fim-Medida(s) +| | test_coverage +| | Peso: 34% +| | Métrica(s): +| | | Valores de referência: Min: 60 e Max: 100 +| | Fim-Metrica(s) +| Fim-Medida(s) +Fim-SubCaracterística +Fim-Característica \ No newline at end of file diff --git a/tests/unit/data/newmsgram.json b/tests/unit/data/newmsgram.json new file mode 100644 index 00000000..4ded7c63 --- /dev/null +++ b/tests/unit/data/newmsgram.json @@ -0,0 +1,64 @@ +{ + "characteristics": [ + { + "key": "reliability", + "weight": 50, + "subcharacteristics": [ + { + "key": "testing_status", + "weight": 100, + "measures": [ + { + "key": "passed_tests", + "weight": 33, + "min_threshold": 0, + "max_threshold": 1 + }, + { + "key": "test_builds", + "weight": 33, + "min_threshold": 0, + "max_threshold": 300000 + }, + { + "key": "test_coverage", + "weight": 34, + "min_threshold": 60, + "max_threshold": 100 + } + ] + } + ] + }, + { + "key": "maintainability", + "weight": 50, + "subcharacteristics": [ + { + "key": "modifiability", + "weight": 100, + "measures": [ + { + "key": "non_complex_file_density", + "weight": 33, + "min_threshold": 0, + "max_threshold": 10 + }, + { + "key": "commented_file_density", + "weight": 33, + "min_threshold": 10, + "max_threshold": 30 + }, + { + "key": "duplication_absense", + "weight": 34, + "min_threshold": 0, + "max_threshold": 5 + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/unit/test_print_config.py b/tests/unit/test_print_config.py index ccb6bfc4..3417d294 100644 --- a/tests/unit/test_print_config.py +++ b/tests/unit/test_print_config.py @@ -7,10 +7,11 @@ from src.cli.commands.cmd_print_config import print_json_tree from src.cli.utils import print_info, print_rule +import re def test_print_json_tree(): - file = open("tests/unit/data/msgram.json") + file = open("tests/unit/data/newmsgram.json") data = json.load(file) captured_output = StringIO() @@ -24,4 +25,12 @@ def test_print_json_tree(): compare = fileExpected.read() + # O padrão de regex para cores no formato [#FFFFFF] e [#458B00] + color_pattern = r'\[#\w+\]' + + # Substituir todas as ocorrências do padrão pelo texto vazio + result = re.sub(color_pattern, '', result) + result = re.sub('\n', '', result) + compare = re.sub('\n', '', compare) + assert result == compare \ No newline at end of file From f6e9e79ad5548c3cfdc388e2c8ea20d453b9ebde Mon Sep 17 00:00:00 2001 From: Ana Carolina Rodrigues Date: Sun, 22 Oct 2023 20:07:25 -0300 Subject: [PATCH 13/36] Fix: Lopping Caracteriscts --- src/cli/commands/cmd_print_config.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/cli/commands/cmd_print_config.py b/src/cli/commands/cmd_print_config.py index b6faff89..858ced83 100644 --- a/src/cli/commands/cmd_print_config.py +++ b/src/cli/commands/cmd_print_config.py @@ -1,22 +1,21 @@ from rich.console import Console - from src.cli.utils import print_info, print_rule - from src.config.settings import FILE_CONFIG from src.config.settings import DEFAULT_CONFIG_FILE_PATH - import json import os def print_json_tree(data): - result = [] # Initialize an empty list to store the output as strings + result = [] stack = [(data, "")] - + is_top = True while stack: data, indent = stack.pop() - key = data.get("key") - result.append(f"[#FFFFFF]\nCaracterística:") + + if is_top: + result.append(f"[#FFFFFF]\nCaracterística:") + is_top = False result.append(f"[#FFFFFF]{indent}[#458B00]{key}") weight = data.get("weight", 0) @@ -43,7 +42,6 @@ def print_json_tree(data): result.append("[#FFFFFF]Fim-Característica") - # Join the result list into a single string with newlines return '\n'.join(result) def command_list_config(args): From e502ee75b768d6c90067dececedbbeb69ef8c4b0 Mon Sep 17 00:00:00 2001 From: ArielSixwings Date: Sun, 22 Oct 2023 20:09:58 -0300 Subject: [PATCH 14/36] Fix: modified expected output --- tests/unit/data/expected_list.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/unit/data/expected_list.txt b/tests/unit/data/expected_list.txt index 060a240d..fa0dcc94 100644 --- a/tests/unit/data/expected_list.txt +++ b/tests/unit/data/expected_list.txt @@ -2,8 +2,6 @@ Característica: reliability Peso: 50% Subcaracteristica(s): - -Característica: | testing_status | Peso: 100% | Medida(s): From e92913e964f1af50120d9cb5e0506e68e14f9f49 Mon Sep 17 00:00:00 2001 From: Ian Rocha Date: Sun, 22 Oct 2023 21:33:12 -0300 Subject: [PATCH 15/36] delete src/config/msgram.json --- src/config/msgram.json | 64 ------------------------------------------ 1 file changed, 64 deletions(-) delete mode 100644 src/config/msgram.json diff --git a/src/config/msgram.json b/src/config/msgram.json deleted file mode 100644 index 7b179b35..00000000 --- a/src/config/msgram.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "characteristics": [ - { - "key": "reliability", - "weight": 50, - "subcharacteristics": [ - { - "key": "testing_status", - "weight": 100, - "measures": [ - { - "key": "passed_tests", - "weight": 33, - "min_passed_tests": 0, - "max_passed_tests": 1 - }, - { - "key": "test_builds", - "weight": 33, - "min_fast_test_time": 0, - "max_fast_test_time": 300000 - }, - { - "key": "test_coverage", - "weight": 34, - "min_coverage": 60, - "max_coverage": 100 - } - ] - } - ] - }, - { - "key": "maintainability", - "weight": 50, - "subcharacteristics": [ - { - "key": "modifiability", - "weight": 100, - "measures": [ - { - "key": "non_complex_file_density", - "weight": 33, - "min_complex_files_density": 0, - "max_complex_files_density": 10 - }, - { - "key": "commented_file_density", - "weight": 33, - "min_comment_density": 10, - "max_comment_density": 30 - }, - { - "key": "duplication_absense", - "weight": 34, - "min_duplicated_lines": 0, - "max_duplicated_lines": 5 - } - ] - } - ] - } - ] -} \ No newline at end of file From e1b4e5f70231aace931a549474eba35e085a5f1e Mon Sep 17 00:00:00 2001 From: Ana Carolina <49570180+AnaCarolinaRodriguesLeite@users.noreply.github.com> Date: Sun, 22 Oct 2023 22:10:23 -0300 Subject: [PATCH 16/36] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 51e38ecb..f128d3ff 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 2023-1-MeasureSoftGram-CLI +# 2023-2 MeasureSoftGram-CLI ## Badges From 4a6328bb9448af2a490c36ea7da033e2e782238b Mon Sep 17 00:00:00 2001 From: Ian Rocha Date: Mon, 23 Oct 2023 11:49:51 -0300 Subject: [PATCH 17/36] Update sonar-project.properties --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index f8a012c0..742e1f96 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,4 +1,4 @@ -sonar.projectKey=fga-eps-mds_2023-1-MeasureSoftGram-CLI +sonar.projectKey=fga-eps-mds_2023-2-MeasureSoftGram-CLI sonar.organization=fga-eps-mds-1 sonar.python.version=3 From 8add29a864c75b51d4120465303823deece82f70 Mon Sep 17 00:00:00 2001 From: Ian Rocha Date: Mon, 23 Oct 2023 11:58:57 -0300 Subject: [PATCH 18/36] Update metrics.yml --- .github/workflows/metrics.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/metrics.yml b/.github/workflows/metrics.yml index e970b4a8..0825542c 100644 --- a/.github/workflows/metrics.yml +++ b/.github/workflows/metrics.yml @@ -24,7 +24,7 @@ jobs: run: | git config --global user.email "${{secrets.USER_EMAIL}}" git config --global user.name "${{secrets.USER_NAME}}" - git clone --single-branch --branch main "https://x-access-token:${{secrets.API_TOKEN_DOC}}@github.com/fga-eps-mds/2023-1-MeasureSoftGram-Doc" doc + git clone --single-branch --branch main "https://x-access-token:${{secrets.API_TOKEN_DOC}}@github.com/fga-eps-mds/2023.2-MeasureSoftGram-DOC" doc mkdir -p doc/analytics-raw-data cp -R analytics-raw-data/*.json doc/analytics-raw-data cd doc/ From f3d31d541ed17cb9ff65565dbc968e9a8812497c Mon Sep 17 00:00:00 2001 From: Ian Rocha Date: Mon, 23 Oct 2023 12:00:59 -0300 Subject: [PATCH 19/36] Update test.yml --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d74f0fff..cd48269f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,5 +45,5 @@ jobs: fail_ci_if_error: true files: ./coverage.xml flags: unittests - name: 2023-1-MeasureSoftGram-CLI - verbose: true \ No newline at end of file + name: 2023-2-MeasureSoftGram-CLI + verbose: true From f5980e544aca5c5ede6ae95e603d9d2f7c5df08d Mon Sep 17 00:00:00 2001 From: Ian Rocha Date: Mon, 23 Oct 2023 12:31:47 -0300 Subject: [PATCH 20/36] Update metrics.yml --- .github/workflows/metrics.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/metrics.yml b/.github/workflows/metrics.yml index 0825542c..5107a671 100644 --- a/.github/workflows/metrics.yml +++ b/.github/workflows/metrics.yml @@ -5,6 +5,7 @@ on: branches: [main, develop] tags: - "v*" + workflow_dispatch: jobs: release: From f6a8bf274b08c886bf684b560ac490e90e20be73 Mon Sep 17 00:00:00 2001 From: Ian Rocha Date: Mon, 23 Oct 2023 14:08:06 -0300 Subject: [PATCH 21/36] Create build.yml --- .github/workflows/build.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..7501f9f9 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,20 @@ +name: Build +on: + push: + branches: + - develop + pull_request: + types: [opened, synchronize, reopened] +jobs: + sonarcloud: + name: SonarCloud + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From bfafe86bc76d49e88c3d28ffb4f9c56de3b74221 Mon Sep 17 00:00:00 2001 From: Ian Rocha Date: Tue, 24 Oct 2023 16:19:22 -0300 Subject: [PATCH 22/36] Update build.yml --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7501f9f9..20e58945 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,6 +5,7 @@ on: - develop pull_request: types: [opened, synchronize, reopened] + workflow_dispatch: jobs: sonarcloud: name: SonarCloud From 543de25814d41b0824cd2aacea42e5e019fb3c02 Mon Sep 17 00:00:00 2001 From: Ian Rocha Date: Thu, 26 Oct 2023 19:10:30 -0300 Subject: [PATCH 23/36] Update python-publish.yml --- .github/workflows/python-publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 45f5e270..bed0676f 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -5,6 +5,7 @@ on: branches: [ develop ] tags: - "v*" + workflow_dispatch: jobs: deploy: From e7d8f4c47766c045c0b575da00fdbc4f3dd10bf2 Mon Sep 17 00:00:00 2001 From: Ian Rocha Date: Thu, 26 Oct 2023 19:13:31 -0300 Subject: [PATCH 24/36] Update pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5511dd62..4b4ee35f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "msgram" -version = "3.0.0" +version = "3.0.1" description = "The msgram CLI is a command-line interface to use MeasureSoftGram software" readme = "README.md" authors = [ From daedc68a51d619c88bc1b5a27d34118ba02a67fd Mon Sep 17 00:00:00 2001 From: Ian Rocha Date: Thu, 26 Oct 2023 19:16:43 -0300 Subject: [PATCH 25/36] Update python-publish.yml --- .github/workflows/python-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index bed0676f..7feede77 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -33,5 +33,5 @@ jobs: run: python -m twine upload -u __token__ -p ${{ secrets.TEST_PYPI_API_TOKEN }} --repository testpypi dist/* - name: Publish package on pypi - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + #if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') run: python -m twine upload -u __token__ -p ${{ secrets.PYPI_API_TOKEN }} dist/* From 8601f8ac155d1a684a6c4e6c19f54f426503e2c2 Mon Sep 17 00:00:00 2001 From: Ian Rocha Date: Thu, 26 Oct 2023 19:18:28 -0300 Subject: [PATCH 26/36] Update pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4b4ee35f..f3955c5f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "msgram" -version = "3.0.1" +version = "3.0.2" description = "The msgram CLI is a command-line interface to use MeasureSoftGram software" readme = "README.md" authors = [ From f6b558c7029ebac7a9b714edee3081b556d62670 Mon Sep 17 00:00:00 2001 From: Ian Rocha Date: Thu, 26 Oct 2023 20:20:29 -0300 Subject: [PATCH 27/36] Update sonar-project.properties --- sonar-project.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/sonar-project.properties b/sonar-project.properties index 742e1f96..14152614 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -9,6 +9,7 @@ sonar.sources.exclusions= \ **/parsers.py \ **/cli.py sonar.tests=./tests +sonar.test.inclusions=**/tests/** sonar.dynamicAnalysis=reuseReports sonar.core.codeCoveragePlugin=cobertura From 7a1c058331675f8920c14f8d125dce824e5f3908 Mon Sep 17 00:00:00 2001 From: Ian Rocha Date: Thu, 26 Oct 2023 20:24:36 -0300 Subject: [PATCH 28/36] Update sonar-project.properties --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 14152614..f313c8cf 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -9,7 +9,7 @@ sonar.sources.exclusions= \ **/parsers.py \ **/cli.py sonar.tests=./tests -sonar.test.inclusions=**/tests/** +sonar.test.inclusions=**/tests/ sonar.dynamicAnalysis=reuseReports sonar.core.codeCoveragePlugin=cobertura From 37c5d5f35f950696c9ca5168129a5fe953cd18ff Mon Sep 17 00:00:00 2001 From: ArielSixwings Date: Thu, 2 Nov 2023 15:52:56 -0300 Subject: [PATCH 29/36] fix: Changed pipe character for asc2 179 character. Co-Authored-by: Ana Carolina Rodrigues --- src/cli/commands/cmd_print_config.py | 15 +++++----- tests/unit/data/expected_list.txt | 42 ++++++++++++++-------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/cli/commands/cmd_print_config.py b/src/cli/commands/cmd_print_config.py index 858ced83..2b90d761 100644 --- a/src/cli/commands/cmd_print_config.py +++ b/src/cli/commands/cmd_print_config.py @@ -24,26 +24,27 @@ def print_json_tree(data): if "subcharacteristics" in data: for subchar in data["subcharacteristics"]: result.append(f"[#FFFFFF]{indent}Subcaracteristica(s):") - stack.append((subchar, f"{indent}| ")) + stack.append((subchar, f"{indent}│ ")) # Use the ASCII character │ (code 179) if "measures" in data: result.append(f"[#FFFFFF]{indent}Medida(s):") for measure in data["measures"]: - result.append(f"[#FFFFFF]{indent}| [#458B00]{measure['key']}") - result.append(f"[#FFFFFF]{indent}| Peso: [#458B00]{measure['weight']}%") + result.append(f"[#FFFFFF]{indent}│ [#458B00]{measure['key']}") # Use the ASCII character │ (code 179) + result.append(f"[#FFFFFF]{indent}│ Peso: [#458B00]{measure['weight']}%") if "min_threshold" in measure and "max_threshold" in measure: min_threshold = measure.get("min_threshold") max_threshold = measure.get("max_threshold") - result.append(f"[#FFFFFF]{indent}| Métrica(s):") - result.append(f"[#FFFFFF]{indent}| | Valores de referência: Min: [#458B00]{min_threshold} [#FFFFFF]e Max: [#458B00]{max_threshold}") - result.append(f"[#FFFFFF]{indent}| Fim-Metrica(s)") - result.append(f"[#FFFFFF]{indent}Fim-Medida(s)") + result.append(f"[#FFFFFF]{indent}│ Métrica(s):") # Use the ASCII character │ (code 179) + result.append(f"[#FFFFFF]{indent}│ │ Valores de referência: Min: [#458B00]{min_threshold} [#FFFFFF]e Max: [#458B00]{max_threshold}") + result.append(f"[#FFFFFF]{indent}│ Fim-Metrica(s)") + result.append(f"[#FFFFFF]{indent}│ Fim-Medida(s)") result.append("[#FFFFFF]Fim-SubCaracterística") result.append("[#FFFFFF]Fim-Característica") return '\n'.join(result) + def command_list_config(args): console = Console() console.clear() diff --git a/tests/unit/data/expected_list.txt b/tests/unit/data/expected_list.txt index fa0dcc94..c8123df1 100644 --- a/tests/unit/data/expected_list.txt +++ b/tests/unit/data/expected_list.txt @@ -2,26 +2,26 @@ Característica: reliability Peso: 50% Subcaracteristica(s): -| testing_status -| Peso: 100% -| Medida(s): -| | passed_tests -| | Peso: 33% -| | Métrica(s): -| | | Valores de referência: Min: 0 e Max: 1 -| | Fim-Metrica(s) -| Fim-Medida(s) -| | test_builds -| | Peso: 33% -| | Métrica(s): -| | | Valores de referência: Min: 0 e Max: 300000 -| | Fim-Metrica(s) -| Fim-Medida(s) -| | test_coverage -| | Peso: 34% -| | Métrica(s): -| | | Valores de referência: Min: 60 e Max: 100 -| | Fim-Metrica(s) -| Fim-Medida(s) +│ testing_status +│ Peso: 100% +│ Medida(s): +│ │ passed_tests +│ │ Peso: 33% +│ │ Métrica(s): +│ │ │ Valores de referência: Min: 0 e Max: 1 +│ │ Fim-Metrica(s) +│ │ Fim-Medida(s) +│ │ test_builds +│ │ Peso: 33% +│ │ Métrica(s): +│ │ │ Valores de referência: Min: 0 e Max: 300000 +│ │ Fim-Metrica(s) +│ │ Fim-Medida(s) +│ │ test_coverage +│ │ Peso: 34% +│ │ Métrica(s): +│ │ │ Valores de referência: Min: 60 e Max: 100 +│ │ Fim-Metrica(s) +│ │ Fim-Medida(s) Fim-SubCaracterística Fim-Característica \ No newline at end of file From 5165c81defdcf0f831b19b1fcd66cd6a3e95edb1 Mon Sep 17 00:00:00 2001 From: ArielSixwings Date: Thu, 2 Nov 2023 17:31:52 -0300 Subject: [PATCH 30/36] fix: add metrics to list Co-Authored-by: Ana Carolina Rodrigues --- src/cli/commands/cmd_print_config.py | 31 ++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/cli/commands/cmd_print_config.py b/src/cli/commands/cmd_print_config.py index 2b90d761..4c8de566 100644 --- a/src/cli/commands/cmd_print_config.py +++ b/src/cli/commands/cmd_print_config.py @@ -9,6 +9,15 @@ def print_json_tree(data): result = [] stack = [(data, "")] is_top = True + + measure_to_metric = {} + measure_to_metric["passed_tests"] = ['test_success_density'] + measure_to_metric["test_builds"] = ['tests', 'tests_execution_time'] + measure_to_metric["test_coverage"] = ['coverage'] + measure_to_metric["non_complex_file_density"] = ['complexity_functions', 'total_number_of_files'] + measure_to_metric["commented_file_density"] = ['commented_lines_density'] + measure_to_metric["duplication_absense"] = ['duplication_lines_density'] + while stack: data, indent = stack.pop() key = data.get("key") @@ -16,10 +25,10 @@ def print_json_tree(data): if is_top: result.append(f"[#FFFFFF]\nCaracterística:") is_top = False - result.append(f"[#FFFFFF]{indent}[#458B00]{key}") + result.append(f"[#FFFFFF]{indent}[#00FF00]{key}") weight = data.get("weight", 0) - result.append(f"[#FFFFFF]{indent}Peso: [#458B00]{weight}%") + result.append(f"[#FFFFFF]{indent}Peso: [#00FF00]{weight}%") if "subcharacteristics" in data: for subchar in data["subcharacteristics"]: @@ -27,17 +36,22 @@ def print_json_tree(data): stack.append((subchar, f"{indent}│ ")) # Use the ASCII character │ (code 179) if "measures" in data: - result.append(f"[#FFFFFF]{indent}Medida(s):") for measure in data["measures"]: - result.append(f"[#FFFFFF]{indent}│ [#458B00]{measure['key']}") # Use the ASCII character │ (code 179) - result.append(f"[#FFFFFF]{indent}│ Peso: [#458B00]{measure['weight']}%") + measure_key = measure.get("key") + result.append(f"[#FFFFFF]{indent}│ [#00FF00]{measure_key}") # Use the ASCII character │ (code 179) + result.append(f"[#FFFFFF]{indent}│ Peso: [#00FF00]{measure['weight']}%") if "min_threshold" in measure and "max_threshold" in measure: min_threshold = measure.get("min_threshold") max_threshold = measure.get("max_threshold") result.append(f"[#FFFFFF]{indent}│ Métrica(s):") # Use the ASCII character │ (code 179) - result.append(f"[#FFFFFF]{indent}│ │ Valores de referência: Min: [#458B00]{min_threshold} [#FFFFFF]e Max: [#458B00]{max_threshold}") + result.append(f"[#FFFFFF]{indent}│ │ Valores de referência: Min: [#00FF00]{min_threshold} [#FFFFFF]e Max: [#00FF00]{max_threshold}") + metrics = measure_to_metric.get(measure_key, []) # Get associated metrics + for metric in metrics: + result.append(f"[#FFFFFF]{indent}│ │ [#00FF00]{metric}") # Print metrics in green color result.append(f"[#FFFFFF]{indent}│ Fim-Metrica(s)") + result.append(f"[#FFFFFF]{indent}│ Fim-Medida(s)") + result.append("[#FFFFFF]Fim-SubCaracterística") result.append("[#FFFFFF]Fim-Característica") @@ -45,6 +59,8 @@ def print_json_tree(data): return '\n'.join(result) + + def command_list_config(args): console = Console() console.clear() @@ -57,10 +73,13 @@ def command_list_config(args): print_info(f"MSGram config file [bold red]'{FILE_CONFIG}'[/] exists already!") + #get data f = open(DEFAULT_CONFIG_FILE_PATH) data = json.load(f) + #dictionary of metrics and measures + for characteristic in data.get("characteristics", []): output_string = print_json_tree(characteristic) print_info(output_string) From 7288f7d158b930fc6d2c8c340f31aee101eb0e8b Mon Sep 17 00:00:00 2001 From: Ana Carolina Rodrigues Date: Fri, 3 Nov 2023 00:14:07 -0300 Subject: [PATCH 31/36] Fix: Ajustes de indentacao e detalhes --- src/cli/commands/cmd_print_config.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/cli/commands/cmd_print_config.py b/src/cli/commands/cmd_print_config.py index 4c8de566..d8d366f2 100644 --- a/src/cli/commands/cmd_print_config.py +++ b/src/cli/commands/cmd_print_config.py @@ -32,40 +32,35 @@ def print_json_tree(data): if "subcharacteristics" in data: for subchar in data["subcharacteristics"]: - result.append(f"[#FFFFFF]{indent}Subcaracteristica(s):") + result.append(f"[#FFFFFF]{indent}Sub-característica(s):") stack.append((subchar, f"{indent}│ ")) # Use the ASCII character │ (code 179) if "measures" in data: for measure in data["measures"]: + result.append(f"[#FFFFFF]{indent}│ Medida(s):") measure_key = measure.get("key") - result.append(f"[#FFFFFF]{indent}│ [#00FF00]{measure_key}") # Use the ASCII character │ (code 179) - result.append(f"[#FFFFFF]{indent}│ Peso: [#00FF00]{measure['weight']}%") + result.append(f"[#FFFFFF]{indent}{indent}│ [#00FF00]{measure_key}") # Use the ASCII character │ (code 179) + result.append(f"[#FFFFFF]{indent}{indent}│ Peso: [#00FF00]{measure['weight']}%") if "min_threshold" in measure and "max_threshold" in measure: min_threshold = measure.get("min_threshold") max_threshold = measure.get("max_threshold") - result.append(f"[#FFFFFF]{indent}│ Métrica(s):") # Use the ASCII character │ (code 179) - result.append(f"[#FFFFFF]{indent}│ │ Valores de referência: Min: [#00FF00]{min_threshold} [#FFFFFF]e Max: [#00FF00]{max_threshold}") + result.append(f"[#FFFFFF]{indent}{indent}│ Métrica(s):") # Use the ASCII character │ (code 179) metrics = measure_to_metric.get(measure_key, []) # Get associated metrics for metric in metrics: - result.append(f"[#FFFFFF]{indent}│ │ [#00FF00]{metric}") # Print metrics in green color - result.append(f"[#FFFFFF]{indent}│ Fim-Metrica(s)") - + result.append(f"[#FFFFFF]{indent}{indent}│ │ [#00FF00]{metric}") # Print metrics in green color + result.append(f"[#FFFFFF]{indent}{indent}│ │ Valores de referência: Min = [#00FF00]{min_threshold} [#FFFFFF]e Max = [#00FF00]{max_threshold}") + result.append(f"[#FFFFFF]{indent}{indent}│ Fim-Métrica(s)") result.append(f"[#FFFFFF]{indent}│ Fim-Medida(s)") - result.append("[#FFFFFF]Fim-SubCaracterística") - result.append("[#FFFFFF]Fim-Característica") return '\n'.join(result) - - - def command_list_config(args): console = Console() console.clear() - print_rule("[#FFFFFF] Listing Configuration Parameters[/]:") + print_rule("[#FFFFFF] Listing Configuration Parameters") if not (os.path.exists(DEFAULT_CONFIG_FILE_PATH)): print_info(f"[#A9A9A9] O arquivo de configuração não foi encontrado. Execute o comando msgram init para criá-lo.") @@ -78,13 +73,10 @@ def command_list_config(args): data = json.load(f) - #dictionary of metrics and measures - for characteristic in data.get("characteristics", []): output_string = print_json_tree(characteristic) print_info(output_string) print_info( - "\n[#A9A9A9]Para editar o arquivo de configuração utilize em seu terminal o seguinte comando: vim " + "\n[#A9A9A9]Para editar o arquivo de configuração utilize em seu terminal o seguinte comando: vim <.msgram/msgram.json>" ) - From cd1160b0baed97f6e44655f802a3cbc33e325094 Mon Sep 17 00:00:00 2001 From: ArielSixwings Date: Sat, 4 Nov 2023 14:12:52 -0300 Subject: [PATCH 32/36] test: Updated test based on metrics fix. Co-Authored-by: Ana Carolina Rodrigues --- tests/unit/data/expected_list.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/unit/data/expected_list.txt b/tests/unit/data/expected_list.txt index c8123df1..23085471 100644 --- a/tests/unit/data/expected_list.txt +++ b/tests/unit/data/expected_list.txt @@ -4,23 +4,26 @@ Peso: 50% Subcaracteristica(s): │ testing_status │ Peso: 100% -│ Medida(s): │ │ passed_tests │ │ Peso: 33% │ │ Métrica(s): │ │ │ Valores de referência: Min: 0 e Max: 1 +│ │ │ test_success_density │ │ Fim-Metrica(s) │ │ Fim-Medida(s) │ │ test_builds │ │ Peso: 33% │ │ Métrica(s): │ │ │ Valores de referência: Min: 0 e Max: 300000 +│ │ │ tests +│ │ │ tests_execution_time │ │ Fim-Metrica(s) │ │ Fim-Medida(s) │ │ test_coverage │ │ Peso: 34% │ │ Métrica(s): │ │ │ Valores de referência: Min: 60 e Max: 100 +│ │ │ coverage │ │ Fim-Metrica(s) │ │ Fim-Medida(s) Fim-SubCaracterística From ff0f351ae0f09c3fa2f8e968ebb377d85b55874b Mon Sep 17 00:00:00 2001 From: ArielSixwings Date: Sat, 4 Nov 2023 14:18:15 -0300 Subject: [PATCH 33/36] Test: updated test --- outhelp.txt | 32 +++++++++++++++++++++++ tests/unit/data/expected_list.txt | 43 +++++++++++++++++-------------- 2 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 outhelp.txt diff --git a/outhelp.txt b/outhelp.txt new file mode 100644 index 00000000..2d8f7f1a --- /dev/null +++ b/outhelp.txt @@ -0,0 +1,32 @@ +──────────────────────────────────────────────────── Listing Configuration Parameters: ──────────────────────────────────────────────────── + + +Característica: +reliability +Peso: 50% +Subcaracteristica(s): + +Característica: +| testing_status +| Peso: 100% +| Medida(s): +| | passed_tests +| | Peso: 33% +| | Métrica(s): +| | | Valores de referência: Min: 0 e Max: 1 +| | Fim-Metrica(s) +| Fim-Medida(s) +| | test_builds +| | Peso: 33% +| | Métrica(s): +| | | Valores de referência: Min: 0 e Max: 300000 +| | Fim-Metrica(s) +| Fim-Medida(s) +| | test_coverage +| | Peso: 34% +| | Métrica(s): +| | | Valores de referência: Min: 60 e Max: 100 +| | Fim-Metrica(s) +| Fim-Medida(s) +Fim-SubCaracterística +Fim-Característica diff --git a/tests/unit/data/expected_list.txt b/tests/unit/data/expected_list.txt index 23085471..944bf044 100644 --- a/tests/unit/data/expected_list.txt +++ b/tests/unit/data/expected_list.txt @@ -1,30 +1,33 @@ Característica: reliability Peso: 50% -Subcaracteristica(s): +Sub-característica(s): │ testing_status │ Peso: 100% -│ │ passed_tests -│ │ Peso: 33% -│ │ Métrica(s): -│ │ │ Valores de referência: Min: 0 e Max: 1 -│ │ │ test_success_density -│ │ Fim-Metrica(s) +│ │ Medida(s): +│ │ │ passed_tests +│ │ │ Peso: 33% +│ │ │ Métrica(s): +│ │ │ │ test_success_density +│ │ │ │ Valores de referência: Min = 0 e Max = 1 +│ │ │ Fim-Métrica(s) │ │ Fim-Medida(s) -│ │ test_builds -│ │ Peso: 33% -│ │ Métrica(s): -│ │ │ Valores de referência: Min: 0 e Max: 300000 -│ │ │ tests -│ │ │ tests_execution_time -│ │ Fim-Metrica(s) +│ │ Medida(s): +│ │ │ test_builds +│ │ │ Peso: 33% +│ │ │ Métrica(s): +│ │ │ │ tests +│ │ │ │ tests_execution_time +│ │ │ │ Valores de referência: Min = 0 e Max = 300000 +│ │ │ Fim-Métrica(s) │ │ Fim-Medida(s) -│ │ test_coverage -│ │ Peso: 34% -│ │ Métrica(s): -│ │ │ Valores de referência: Min: 60 e Max: 100 -│ │ │ coverage -│ │ Fim-Metrica(s) +│ │ Medida(s): +│ │ │ test_coverage +│ │ │ Peso: 34% +│ │ │ Métrica(s): +│ │ │ │ coverage +│ │ │ │ Valores de referência: Min = 60 e Max = 100 +│ │ │ Fim-Métrica(s) │ │ Fim-Medida(s) Fim-SubCaracterística Fim-Característica \ No newline at end of file From ce8933f48b76ad608a46cb1492c8bbaa5b022e7d Mon Sep 17 00:00:00 2001 From: ArielSixwings Date: Sat, 4 Nov 2023 14:59:39 -0300 Subject: [PATCH 34/36] feat: Add config path option to msgram list. Co-Authored-by: Ana Carolina Rodrigues --- src/cli/commands/cmd_print_config.py | 31 ++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/cli/commands/cmd_print_config.py b/src/cli/commands/cmd_print_config.py index d8d366f2..f1456d0b 100644 --- a/src/cli/commands/cmd_print_config.py +++ b/src/cli/commands/cmd_print_config.py @@ -1,7 +1,10 @@ from rich.console import Console -from src.cli.utils import print_info, print_rule -from src.config.settings import FILE_CONFIG -from src.config.settings import DEFAULT_CONFIG_FILE_PATH +from src.cli.utils import print_info, print_rule, print_error + +from src.config.settings import FILE_CONFIG, DEFAULT_CONFIG_PATH, DEFAULT_CONFIG_FILE_PATH + +from pathlib import Path + import json import os @@ -60,16 +63,32 @@ def command_list_config(args): console = Console() console.clear() + file_path = DEFAULT_CONFIG_FILE_PATH + try: + config_path: Path = args["config_path"] + + if config_path != DEFAULT_CONFIG_PATH: + print_info(f"[#A9A9A9] Será usado arquivo informado pelo usuário: ") + file_path = str(config_path) + "/msgram.json" + else: + print_info(f"[#A9A9A9] Não foi informado caminho do arquivo de configuração, será usado caminho padrão.") + + + except Exception as e: + print_error(f"KeyError: args[{e}] - non-existent parameters") + exit(1) + + print_rule("[#FFFFFF] Listing Configuration Parameters") - if not (os.path.exists(DEFAULT_CONFIG_FILE_PATH)): - print_info(f"[#A9A9A9] O arquivo de configuração não foi encontrado. Execute o comando msgram init para criá-lo.") + if not (os.path.exists(file_path)): + print_info(f"[#A9A9A9] O arquivo de configuração não foi encontrado. \n Execute o comando msgram init no projeto desejado para criá-lo.") exit() print_info(f"MSGram config file [bold red]'{FILE_CONFIG}'[/] exists already!") #get data - f = open(DEFAULT_CONFIG_FILE_PATH) + f = open(file_path) data = json.load(f) From 20ae9bc7faa60532ca7b7ec1afba029e48f18e41 Mon Sep 17 00:00:00 2001 From: ArielSixwings Date: Sat, 4 Nov 2023 15:39:43 -0300 Subject: [PATCH 35/36] feat: changed character at metrics. Co-Authored-by: Ana Carolina Rodrigues --- src/cli/commands/cmd_print_config.py | 2 +- tests/unit/data/expected_list.txt | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cli/commands/cmd_print_config.py b/src/cli/commands/cmd_print_config.py index f1456d0b..94a2c6c3 100644 --- a/src/cli/commands/cmd_print_config.py +++ b/src/cli/commands/cmd_print_config.py @@ -50,7 +50,7 @@ def print_json_tree(data): result.append(f"[#FFFFFF]{indent}{indent}│ Métrica(s):") # Use the ASCII character │ (code 179) metrics = measure_to_metric.get(measure_key, []) # Get associated metrics for metric in metrics: - result.append(f"[#FFFFFF]{indent}{indent}│ │ [#00FF00]{metric}") # Print metrics in green color + result.append(f"[#FFFFFF]{indent}{indent}│ └─[#00FF00]{metric}") # Print metrics in green color result.append(f"[#FFFFFF]{indent}{indent}│ │ Valores de referência: Min = [#00FF00]{min_threshold} [#FFFFFF]e Max = [#00FF00]{max_threshold}") result.append(f"[#FFFFFF]{indent}{indent}│ Fim-Métrica(s)") result.append(f"[#FFFFFF]{indent}│ Fim-Medida(s)") diff --git a/tests/unit/data/expected_list.txt b/tests/unit/data/expected_list.txt index 944bf044..51acc197 100644 --- a/tests/unit/data/expected_list.txt +++ b/tests/unit/data/expected_list.txt @@ -8,7 +8,7 @@ Sub-característica(s): │ │ │ passed_tests │ │ │ Peso: 33% │ │ │ Métrica(s): -│ │ │ │ test_success_density +│ │ │ └─test_success_density │ │ │ │ Valores de referência: Min = 0 e Max = 1 │ │ │ Fim-Métrica(s) │ │ Fim-Medida(s) @@ -16,8 +16,8 @@ Sub-característica(s): │ │ │ test_builds │ │ │ Peso: 33% │ │ │ Métrica(s): -│ │ │ │ tests -│ │ │ │ tests_execution_time +│ │ │ └─tests +│ │ │ └─tests_execution_time │ │ │ │ Valores de referência: Min = 0 e Max = 300000 │ │ │ Fim-Métrica(s) │ │ Fim-Medida(s) @@ -25,7 +25,7 @@ Sub-característica(s): │ │ │ test_coverage │ │ │ Peso: 34% │ │ │ Métrica(s): -│ │ │ │ coverage +│ │ │ └─coverage │ │ │ │ Valores de referência: Min = 60 e Max = 100 │ │ │ Fim-Métrica(s) │ │ Fim-Medida(s) From 8c0681e92f9fa3827a84404563d41b6fb9261b7a Mon Sep 17 00:00:00 2001 From: ArielSixwings Date: Sat, 4 Nov 2023 15:44:58 -0300 Subject: [PATCH 36/36] fix: version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f3955c5f..5925a41e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "msgram" -version = "3.0.2" +version = "3.0.3" description = "The msgram CLI is a command-line interface to use MeasureSoftGram software" readme = "README.md" authors = [