diff --git a/apps/polarion/exceptions.py b/apps/polarion/exceptions.py deleted file mode 100644 index bb6fff9..0000000 --- a/apps/polarion/exceptions.py +++ /dev/null @@ -1,6 +0,0 @@ -class PolarionTestCaseApprovalError(Exception): - pass - - -class PolarionTestCaseWithoutRequirementError(Exception): - pass diff --git a/apps/polarion/polarion_set_automated.py b/apps/polarion/polarion_set_automated.py index e478681..2f89a33 100644 --- a/apps/polarion/polarion_set_automated.py +++ b/apps/polarion/polarion_set_automated.py @@ -2,10 +2,9 @@ import logging import os from simple_logger.logger import get_logger - +import sys import click -from apps.polarion.exceptions import PolarionTestCaseApprovalError from apps.polarion.polarion_utils import get_polarion_project_id, find_polarion_ids, update_polarion_ids from typing import List, Dict, Optional @@ -48,16 +47,18 @@ def remove_approved_tests( @click.option("--verbose", default=False, is_flag=True) def polarion_approve_automate(config_file_path: str, project_id: str, branch: str, verbose: bool) -> None: if verbose: - LOGGER.setLevel(logging.INFO) - else: - logging.disable(logging.ERROR) + LOGGER.setLevel(logging.DEBUG) + # since the utilities are in apps.polarion.polarion_utils, we need to change log level + # for apps.polarion.polarion_utils as well + logging.getLogger("apps.polarion.polarion_utils").setLevel(logging.DEBUG) + polarion_project_id = project_id or get_polarion_project_id( config_file_path=config_file_path, util_name="pyutils-polarion-set-automated" ) added_polarions = {} if added_ids := find_polarion_ids(polarion_project_id=polarion_project_id, string_to_match="added", branch=branch): added_polarions = approve_tests(polarion_project_id=polarion_project_id, added_ids=added_ids) - LOGGER.info(f"Following polarion ids were marked automated and approved: {added_polarions.get('updated')}") + LOGGER.debug(f"Following polarion ids were marked automated and approved: {added_polarions.get('updated')}") removed_polarions = remove_approved_tests( polarion_project_id=polarion_project_id, added_ids=added_ids, branch=branch @@ -69,7 +70,7 @@ def polarion_approve_automate(config_file_path: str, project_id: str, branch: st if added_polarions.get("failed"): error += f" Added ids:: {added_polarions.get('failed')}." LOGGER.error(error) - raise PolarionTestCaseApprovalError(error) + sys.exit(1) if __name__ == "__main__": diff --git a/apps/polarion/polarion_utils.py b/apps/polarion/polarion_utils.py index 3a5e55c..fd5434a 100644 --- a/apps/polarion/polarion_utils.py +++ b/apps/polarion/polarion_utils.py @@ -1,7 +1,6 @@ from __future__ import annotations import re - -import click +import sys from simple_logger.logger import get_logger import shlex import subprocess @@ -23,7 +22,7 @@ def git_diff(branch: str) -> str: def git_diff_lines(branch: str) -> Dict[str, List[str]]: diff: Dict[str, List[str]] = {} for line in git_diff(branch=branch).splitlines(): - LOGGER.info(line) + LOGGER.debug(line) if line.startswith("+"): diff.setdefault("added", []).append(line) if line.startswith("-"): @@ -42,7 +41,7 @@ def validate_polarion_requirements( for _id in polarion_test_ids: has_req = False - LOGGER.info(f"Checking if {_id} verifies any requirement") + LOGGER.debug(f"Checking if {_id} verifies any requirement") tc = TestCase(project_id=polarion_project_id, work_item_id=_id) for link in tc.linked_work_items: try: @@ -70,7 +69,7 @@ def get_polarion_project_id(util_name: str, config_file_path: str) -> str: polarion_project_id = get_util_config(util_name=util_name, config_file_path=config_file_path).get("project_id") if not polarion_project_id: LOGGER.error("Polarion project id must be passed via config file or command line") - raise click.Abort() + sys.exit(1) return polarion_project_id @@ -91,7 +90,7 @@ def update_polarion_ids( if is_approved: tc.status = APPROVED tc.update() - LOGGER.info(f"Polarion {id}: marked as: {automation_status}, approved status set: {is_approved}") + LOGGER.debug(f"Polarion {id}: marked as: {automation_status}, approved status set: {is_approved}") updated_ids.setdefault("updated", []).append(id) except PyleroLibException as polarion_exception: error = f"{id}: {polarion_exception}" diff --git a/apps/polarion/polarion_verify_tc_requirements.py b/apps/polarion/polarion_verify_tc_requirements.py index a9a5486..beb4435 100644 --- a/apps/polarion/polarion_verify_tc_requirements.py +++ b/apps/polarion/polarion_verify_tc_requirements.py @@ -2,8 +2,8 @@ from simple_logger.logger import get_logger import os import click +import sys -from apps.polarion.exceptions import PolarionTestCaseWithoutRequirementError from apps.polarion.polarion_utils import validate_polarion_requirements, find_polarion_ids, get_polarion_project_id LOGGER = get_logger(name="polarion-verify-tc-requirements") @@ -21,21 +21,22 @@ @click.option("--verbose", default=False, is_flag=True) def has_verify(config_file_path: str, project_id: str, branch: str, verbose: bool) -> None: if verbose: - LOGGER.setLevel(logging.INFO) - else: - logging.disable(logging.ERROR) + LOGGER.setLevel(logging.DEBUG) + # since the utilities are in apps.polarion.polarion_utils, we need to change log level + # for apps.polarion.polarion_utils as well + logging.getLogger("apps.polarion.polarion_utils").setLevel(logging.DEBUG) + polarion_project_id = project_id or get_polarion_project_id( config_file_path=config_file_path, util_name="pyutils-polarion-verify-tc-requirements" ) if added_ids := find_polarion_ids(polarion_project_id=polarion_project_id, string_to_match="added", branch=branch): - LOGGER.info(f"Checking following ids: {added_ids}") + LOGGER.debug(f"Checking following ids: {added_ids}") if tests_with_missing_requirements := validate_polarion_requirements( polarion_test_ids=added_ids, polarion_project_id=polarion_project_id, ): - raise PolarionTestCaseWithoutRequirementError( - f"TestCases with missing requirement: {tests_with_missing_requirements}" - ) + LOGGER.error(f"TestCases with missing requirement: {tests_with_missing_requirements}") + sys.exit(1) if __name__ == "__main__": diff --git a/apps/unused_code/unused_code.py b/apps/unused_code/unused_code.py index 06073b3..e9d8e6d 100644 --- a/apps/unused_code/unused_code.py +++ b/apps/unused_code/unused_code.py @@ -2,6 +2,8 @@ import logging import os import subprocess +import sys + import click from simple_logger.logger import get_logger @@ -69,10 +71,7 @@ def is_ignore_function_list(ignore_prefix_list: List[str], function: ast.Functio def get_unused_functions( config_file_path: Any, exclude_files: Any, exclude_function_prefixes: Any, verbose: bool ) -> Any: - if verbose: - LOGGER.setLevel(logging.DEBUG) - else: - logging.disable(logging.CRITICAL) + LOGGER.setLevel(logging.DEBUG if verbose else logging.INFO) _unused_functions = [] unused_code_config = get_util_config(util_name="pyutils-unusedcode", config_file_path=config_file_path) @@ -104,7 +103,7 @@ def get_unused_functions( ) if _unused_functions: click.echo("\n".join(_unused_functions)) - raise click.Abort() + sys.exit(1) if __name__ == "__main__":