From 6998a12d62c68c1baa624b0eb059cbd99036d5f9 Mon Sep 17 00:00:00 2001 From: "jiyeong.seok" Date: Thu, 10 Oct 2024 15:19:08 +0900 Subject: [PATCH] Update compare yaml test case Signed-off-by: jiyeong.seok --- src/fosslight_util/compare_yaml.py | 4 +- src/fosslight_util/convert_excel_to_yaml.py | 69 --------------------- tests/legacy/test_compare_yaml.py | 6 +- tests/legacy/test_convert_to_yaml.py | 20 ------ 4 files changed, 8 insertions(+), 91 deletions(-) delete mode 100644 src/fosslight_util/convert_excel_to_yaml.py delete mode 100755 tests/legacy/test_convert_to_yaml.py diff --git a/src/fosslight_util/compare_yaml.py b/src/fosslight_util/compare_yaml.py index 67e0db3..0a80a41 100644 --- a/src/fosslight_util/compare_yaml.py +++ b/src/fosslight_util/compare_yaml.py @@ -4,7 +4,9 @@ # SPDX-License-Identifier: Apache-2.0 import logging +from typing import List, Dict from fosslight_util.constant import LOGGER_NAME +from fosslight_util.oss_item import FileItem logger = logging.getLogger(LOGGER_NAME) VERSION = 'version' @@ -12,7 +14,7 @@ NAME = 'name' -def compare_yaml(before_fileitems, after_fileitems): +def compare_yaml(before_fileitems: List[FileItem], after_fileitems: List[FileItem]) -> Dict[str, List]: bf_raw = [] af_raw = [] for bf in before_fileitems: diff --git a/src/fosslight_util/convert_excel_to_yaml.py b/src/fosslight_util/convert_excel_to_yaml.py deleted file mode 100644 index b99ebc8..0000000 --- a/src/fosslight_util/convert_excel_to_yaml.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (c) 2022 LG Electronics Inc. -# SPDX-License-Identifier: Apache-2.0 -import os -import sys -import logging -import yaml -import re -from fosslight_util.constant import LOGGER_NAME -from fosslight_util.write_yaml import create_yaml_with_ossitem -from fosslight_util.read_excel import read_oss_report - -logger = logging.getLogger(LOGGER_NAME) - - -def find_report_file(path_to_find): - file_to_find = ["FOSSLight-Report.xlsx", "OSS-Report.xlsx"] - - try: - for file in file_to_find: - file_with_path = os.path.join(path_to_find, file) - if os.path.isfile(file_with_path): - return file - for root, dirs, files in os.walk(path_to_find): - for file in files: - file_name = file.lower() - p = re.compile(r"[\s\S]*OSS[\s\S]*-Report[\s\S]*.xlsx", re.I) - if p.search(file_name): - return os.path.join(root, file) - except Exception as error: - logger.debug("Find report:"+str(error)) - return "" - - -def convert_excel_to_yaml(oss_report_to_read: str, output_file: str, sheet_names: str = "") -> None: - _file_extension = ".yaml" - yaml_dict = {} - - if os.path.isfile(oss_report_to_read): - try: - items = read_oss_report(oss_report_to_read, sheet_names) - for item in items: - create_yaml_with_ossitem(item, yaml_dict) - if yaml_dict: - output_file = output_file if output_file.endswith(_file_extension) else output_file + _file_extension - success = write_yaml_file(output_file, yaml_dict) - if success: - logger.warning(f"Output: {output_file}") - else: - logger.error(f"Can't write yaml file : {output_file}") - sys.exit(1) - except Exception as error: - logger.error(f"Convert yaml: {error}") - else: - logger.error(f"Can't find a file: {oss_report_to_read}") - - -def write_yaml_file(output_file, json_output): - success = True - error_msg = "" - - try: - with open(output_file, 'w') as f: - yaml.dump(json_output, f, sort_keys=False) - except Exception as ex: - error_msg = str(ex) - success = False - return success, error_msg diff --git a/tests/legacy/test_compare_yaml.py b/tests/legacy/test_compare_yaml.py index 02f4f8f..f839203 100644 --- a/tests/legacy/test_compare_yaml.py +++ b/tests/legacy/test_compare_yaml.py @@ -5,11 +5,15 @@ import os import json from fosslight_util.compare_yaml import compare_yaml +from fosslight_util.parsing_yaml import parsing_yml def main(): cur = os.getcwd() - result = compare_yaml(os.path.join(cur, 'before.yaml'), os.path.join(cur, 'after.yaml')) + resources = os.path.join(cur, 'resources') + before_fileitems, _, _ = parsing_yml(os.path.join(resources, 'before.yaml'), resources) + after_fileitems, _, _ = parsing_yml(os.path.join(resources, 'after.yaml'), resources) + result = compare_yaml(before_fileitems, after_fileitems) print(json.dumps(result, indent=4, sort_keys=True)) diff --git a/tests/legacy/test_convert_to_yaml.py b/tests/legacy/test_convert_to_yaml.py deleted file mode 100755 index 574023d..0000000 --- a/tests/legacy/test_convert_to_yaml.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (c) 2022 LG Electronics Inc. -# SPDX-License-Identifier: Apache-2.0 -import os -from fosslight_util.set_log import init_log -from fosslight_util.convert_excel_to_yaml import convert_excel_to_yaml - - -def main(): - output_dir = "test_result/convert" - logger, _result_log = init_log(os.path.join(output_dir, "convert_result.txt")) - logger.warning("TESTING - converting excel to yaml") - output_yaml = os.path.join(os.path.abspath(output_dir), "fosslight-sbom-info") - logger.warning(f"output_yaml - {output_yaml}") - convert_excel_to_yaml("tests/FOSSLight-Report_sample.xlsx", output_yaml) - - -if __name__ == '__main__': - main()