Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions apps/polarion/polarion_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
import shlex
import subprocess
from pylero.exceptions import PyleroLibException
from typing import Any
from typing import Dict, List

LOGGER = get_logger(name=__name__)


def git_diff() -> Any:
def git_diff() -> str:
data = subprocess.check_output(shlex.split("git diff HEAD^-1"))
return data.decode("utf-8")
return data.decode()


def git_diff_lines() -> dict:
diff: dict = {}
def git_diff_lines() -> Dict[str, List[str]]:
diff: Dict[str, List[str]] = {}
for line in git_diff().splitlines():
LOGGER.debug(line)
if line.startswith("+"):
Expand All @@ -22,12 +22,12 @@ def git_diff_lines() -> dict:


def validate_polarion_requirements(
polarion_test_ids: list,
polarion_test_ids: List[str],
polarion_project_id: str,
) -> list:
) -> List[str]:
from pylero.work_item import TestCase, Requirement

tests_with_missing_requirements = []
tests_with_missing_requirements: List[str] = []

for _id in polarion_test_ids:
has_req = False
Expand Down
3 changes: 1 addition & 2 deletions apps/polarion/polarion_verify_tc_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
validate_polarion_requirements,
)
from apps.utils import get_util_config
from typing import Any

LOGGER = get_logger(name="polarion-verify-tc-requirements")

Expand All @@ -22,7 +21,7 @@
)
@click.option("--project-id", "-p", help="Provide the polarion project id")
@click.option("--verbosity", default=False, is_flag=True)
def has_verify(config_file_path: Any, project_id: str, verbosity: bool) -> Any:
def has_verify(config_file_path: str, project_id: str, verbosity: bool) -> None:
if verbosity:
LOGGER.setLevel(logging.DEBUG)

Expand Down
42 changes: 20 additions & 22 deletions apps/unused_code/unused_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,47 @@
from simple_logger.logger import get_logger

from apps.utils import all_python_files, ListParamType, get_util_config
from typing import Any
from typing import Any, Iterable, List

LOGGER = get_logger(name=__name__)


def is_fixture_autouse(func: Any) -> Any:
if func.decorator_list:
for deco in func.decorator_list:
if not hasattr(deco, "func"):
continue
def is_fixture_autouse(func: ast.FunctionDef) -> bool:
deco_list: List[Any] = func.decorator_list
for deco in deco_list or []:
if not hasattr(deco, "func"):
continue

if getattr(deco.func, "attr", None) and getattr(deco.func, "value", None):
if deco.func.attr == "fixture" and deco.func.value.id == "pytest":
for _key in deco.keywords:
if _key.arg == "autouse":
return _key.value.s
if getattr(deco.func, "attr", None) and getattr(deco.func, "value", None):
if deco.func.attr == "fixture" and deco.func.value.id == "pytest":
for _key in deco.keywords:
if _key.arg == "autouse":
return True
return False


def _iter_functions(tree: Any) -> Any:
def _iter_functions(tree: ast.Module) -> Iterable[ast.FunctionDef]:
"""
Get all function from python file
"""

def is_func(_elm: Any) -> Any:
return isinstance(_elm, ast.FunctionDef)

def is_test(_elm: Any) -> Any:
return _elm.name.startswith("test_")

for elm in tree.body:
if is_func(_elm=elm):
if is_test(_elm=elm):
if isinstance(elm, ast.FunctionDef):
if elm.name.startswith("test_"):
continue

yield elm


def is_ignore_function_list(ignore_prefix_list: list, function: Any) -> Any:
def is_ignore_function_list(ignore_prefix_list: List[str], function: ast.FunctionDef) -> bool:
ignore_function_lists = [
function.name for ignore_prefix in ignore_prefix_list if function.name.startswith(ignore_prefix)
]
if ignore_function_lists:
LOGGER.debug(f"Following functions are getting skipped: {ignore_function_lists}")
return True

return False


@click.command()
@click.option(
Expand All @@ -77,10 +73,12 @@ def get_unused_functions(
LOGGER.setLevel(logging.DEBUG)
else:
logging.disable(logging.CRITICAL)

_unused_functions = []
unused_code_config = get_util_config(util_name="pyutils-unusedcode", config_file_path=config_file_path)
func_ignore_prefix = exclude_function_prefixes or unused_code_config.get("exclude_function_prefix", [])
file_ignore_list = exclude_files or unused_code_config.get("exclude_files", [])

for py_file in all_python_files():
if os.path.basename(py_file) in file_ignore_list:
continue
Expand Down
6 changes: 3 additions & 3 deletions apps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from simple_logger.logger import get_logger
import json
import click
from typing import Any
from typing import Any, Dict, Iterable

LOGGER = get_logger(name=__name__)


def get_util_config(util_name: str, config_file_path: Any) -> dict:
def get_util_config(util_name: str, config_file_path: str) -> Dict[str, Any]:
if os.path.exists(config_file_path):
with open(config_file_path) as _file:
return yaml.safe_load(_file).get(util_name, {})
Expand Down Expand Up @@ -72,7 +72,7 @@ def convert(self, cli_value: Any, param: click.Parameter | None, ctx: click.Cont
)


def all_python_files() -> Any:
def all_python_files() -> Iterable[str]:
"""
Get all python files from current directory and subdirectories
"""
Expand Down
5 changes: 3 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
omit = ["tests/*"]

[tool.coverage.report]
fail_under = 60
fail_under = 75
skip_empty = true

[tool.coverage.html]
directory = ".tests_coverage"
show_contexts = true

[tool.mypy]
check_untyped_defs = true
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
no_implicit_optional = true

[tool.ruff]
preview = true
line-length = 120
Expand Down Expand Up @@ -39,14 +46,13 @@ packages = [{ include = "apps" }]
pyutils-unusedcode = "apps.unused_code.unused_code:get_unused_functions"
pyutils-polarion-verify-tc-requirements = "apps.polarion.polarion_verify_tc_requirements:has_verify"


[tool.poetry.dependencies]
python = "^3.8"
python-simple-logger = "^1.0.8"
pylero = "^0.0.8"
pyyaml = "*"
pyhelper-utils = "^0.0.3"
pytest-mock = "^3.14.0"
pyyaml = "^6.0.1"

[tool.poetry.group.dev.dependencies]
ipdb = "^0.13.13"
Expand All @@ -57,8 +63,6 @@ ipython = "*"
enable = true
pattern = "((?P<epoch>\\d+)!)?(?P<base>\\d+(\\.\\d+)*)"



[tool.poetry.group.test.dependencies]
pytest = "^8.0.0"
pytest-cov = "^4.1.0"
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[pytest]
addopts =
--cov-config=pyproject.toml --cov-report=html --cov-report=term --cov=.
--cov-config=pyproject.toml --cov-report=html --cov-report=term --cov=apps
6 changes: 2 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
[tox]
envlist = {py38,py39,py310,py311,py312}-{unittest},
skipsdist = True


[testenv:unittests]
basepython = python3
[testenv]
setenv =
PYTHONPATH = {toxinidir}
deps =
poetry
commands =
poetry install
poetry run pytest tests
allowlist_externals =
poetry