Skip to content

Commit

Permalink
Linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wwakabobik committed Aug 30, 2024
1 parent 965c8b9 commit 6c247c2
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 90 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
pip install types-requests
pip install pytest
pip install faker
pip install pillow
- name: Add 'testrail_api_reporter' to PYTHONPATH
run: echo "PYTHONPATH=$PYTHONPATH:$(pwd)/testrail_api_reporter:." >> $GITHUB_ENV
- name: Analysing the code with pylint
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/master_linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
pip install types-requests
pip install pytest
pip install faker
pip install pillow
- name: Add 'testrail_api_reporter' to PYTHONPATH
run: echo "PYTHONPATH=$PYTHONPATH:$(pwd)/testrail_api_reporter:." >> $GITHUB_ENV
- name: Analysing the code with pylint
Expand Down
4 changes: 3 additions & 1 deletion testrail_api_reporter/engines/plotly_reporter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
""" Confluence sender module """

from typing import Optional

import plotly

from ..utils.csv_parser import CSVParser
Expand Down Expand Up @@ -231,7 +233,7 @@ def draw_test_case_by_area(self, filename=None, cases=None, ar_colors=None, line

def draw_history_state_chart(
self,
chart_name: str | None = None,
chart_name: Optional[str] = None,
history_data=None,
filename=None,
trace1_decor=None,
Expand Down
12 changes: 6 additions & 6 deletions testrail_api_reporter/utils/reporter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
""" This module contains service functions for reporter """
from logging import Logger
from os import popen
from typing import Optional, Any
from typing import Optional, Any, Union

import requests


def format_error(error: list | str | Exception) -> str:
def format_error(error: Union[list, str, Exception]) -> str:
"""
Service function for parse errors to human-readable format
Expand Down Expand Up @@ -58,7 +58,7 @@ def delete_file(filename: str, debug: bool = True, logger: Optional[Logger] = No
logger.debug(f"Removed {filename}")


def zip_file(filename: str, suffix: str | None = None, debug: bool = True, logger: Optional[Logger] = None) -> str:
def zip_file(filename: str, suffix: Optional[str] = None, debug: bool = True, logger: Optional[Logger] = None) -> str:
"""
Service function to ZIP file
Expand All @@ -79,8 +79,8 @@ def zip_file(filename: str, suffix: str | None = None, debug: bool = True, logge


def check_captions_and_files(
captions: list | None | Any, files: list, debug: bool = True, logger: Optional[Logger] = None
) -> list | None:
captions: Union[list, None, Any], files: list, debug: bool = True, logger: Optional[Logger] = None
) -> Optional[list]:
"""
Service function to check captions and file lists
Expand Down Expand Up @@ -114,7 +114,7 @@ def init_get_cases_process() -> tuple[list, bool, None, None, int]:
:return: cases_list, first_run, criteria, response, retry
"""
cases_list = []
cases_list: list = []
first_run = True
criteria = None
response = None
Expand Down
17 changes: 9 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from os import path, remove
from random import randint
from typing import Generator

import pytest
from faker import Faker
Expand All @@ -14,17 +15,16 @@
from testrail_api_reporter.utils.case_stat import CaseStat # pylint: disable=import-error,no-name-in-module



fake = Faker()


@pytest.fixture
def create_test_file() -> str:
def create_test_file() -> Generator:
"""
Fixture to create random test file
:return: filename
:rtype: str
:rtype: Generator
"""
test_file = f"not_existing_{fake.file_name()}"
with open(test_file, "w", encoding="utf-8") as file:
Expand Down Expand Up @@ -65,7 +65,7 @@ def case_stat() -> CaseStat:


@pytest.fixture
def case_stat_random(case_stat, random_stat):
def case_stat_random(case_stat, random_stat): # pylint: disable=redefined-outer-name
"""
Fixture to return object of CaseStat
Expand All @@ -81,12 +81,12 @@ def case_stat_random(case_stat, random_stat):


@pytest.fixture
def csv_file() -> str:
def csv_file() -> Generator:
"""
Fixture to create random test file
:return: filename
:rtype: str
:rtype: Generator
"""
test_file = f"not_existing_{fake.file_name(extension='csv')}"
with open(test_file, "w", encoding="utf-8") as file:
Expand Down Expand Up @@ -155,7 +155,7 @@ def random_type_platforms() -> list[dict]:


@pytest.fixture
def random_plotly_reporter(random_type_platforms) -> PlotlyReporter:
def random_plotly_reporter(random_type_platforms) -> PlotlyReporter: # pylint: disable=redefined-outer-name
"""
Returns PlotlyReporter object with random type platforms
Expand All @@ -167,7 +167,8 @@ def random_plotly_reporter(random_type_platforms) -> PlotlyReporter:

@pytest.fixture()
def random_rgb():
"""Returns fixture to get rgb in string format """
"""Returns fixture to get rgb in string format"""

def get_rgb() -> str:
"""
Returns rgb in string format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ def random_expected_image(case_stat):
case_stat.not_automated = 27205
case_stat.not_applicable = 10092
return {"filename": f"{getcwd()}/tests/assets/expected_automation_state.png", "data": [case_stat]}
else:
case_stat.set_name("Automation State")
return {"filename": f"{getcwd()}/tests/assets/expected_automation_state_empty.png", "data": [case_stat]}
case_stat.set_name("Automation State")
return {"filename": f"{getcwd()}/tests/assets/expected_automation_state_empty.png", "data": [case_stat]}


def test_draw_automation_state_report_no_reports(caplog, random_plotly_reporter):
def test_draw_automation_state_report_no_reports(random_plotly_reporter):
"""
Init PlotlyReporter and call draw_automation_state_report without reports should raise ValueError
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
"""
with pytest.raises(ValueError, match="No TestRail reports are provided, report aborted!"):
Expand All @@ -47,11 +45,10 @@ def test_draw_automation_state_report_no_reports(caplog, random_plotly_reporter)
)


def test_draw_automation_state_report_no_filename(caplog, random_plotly_reporter):
def test_draw_automation_state_report_no_filename(random_plotly_reporter):
"""
Init PlotlyReporter and call draw_automation_state_report without filename should raise ValueError
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
"""
with pytest.raises(ValueError, match="No output filename is provided, report aborted!"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@
fake = Faker()


def test_draw_history_state_chart_no_chart_name(caplog, random_plotly_reporter):
def test_draw_history_state_chart_no_chart_name(random_plotly_reporter):
"""
Init PlotlyReporter and call draw_history_state_chart without chart_name should raise ValueError
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
"""
with pytest.raises(ValueError, match="No chart name is provided, report aborted!"):
random_plotly_reporter.draw_history_state_chart() # type: ignore


def test_draw_history_state_chart_no_filename(caplog, random_plotly_reporter):
def test_draw_history_state_chart_no_filename(random_plotly_reporter):
"""
Init PlotlyReporter and call draw_test_case_by_priority without filename should raise ValueError
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
"""
fake_name = fake.name()
Expand All @@ -32,87 +30,79 @@ def test_draw_history_state_chart_no_filename(caplog, random_plotly_reporter):
random_plotly_reporter.draw_history_state_chart(chart_name=fake_name)


def test_draw_history_state_chart_creates_file(caplog, random_plotly_reporter):
def test_draw_history_state_chart_creates_file(random_plotly_reporter):
"""
Init PlotlyReporter and call draw_history_state_chart with valid parameters should create file
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
"""
raise NotImplementedError


def test_draw_history_state_chart_creates_correct_image(caplog, random_plotly_reporter, compare_image):
def test_draw_history_state_chart_creates_correct_image(random_plotly_reporter, compare_image):
"""
Init PlotlyReporter and call draw_history_state_chart with valid parameters should create valid image
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
:param compare_image: fixture, returns function to compare images
"""
raise NotImplementedError


def test_draw_history_state_chart_default_history_data(caplog, random_plotly_reporter, compare_image):
def test_draw_history_state_chart_default_history_data(random_plotly_reporter, compare_image):
"""
Init PlotlyReporter and call draw_history_state_chart with default history data
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
:param compare_image: fixture, returns function to compare images
"""
raise NotImplementedError


def test_draw_history_state_chart_custom_history_data(caplog, random_plotly_reporter, compare_image):
def test_draw_history_state_chart_custom_history_data(random_plotly_reporter, compare_image):
"""
Init PlotlyReporter and call draw_history_state_chart with custom history data
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
:param compare_image: fixture, returns function to compare images
"""
raise NotImplementedError


def test_draw_history_state_chart_trace1_decor(caplog, random_plotly_reporter, compare_image):
def test_draw_history_state_chart_trace1_decor(random_plotly_reporter, compare_image):
"""
Init PlotlyReporter and call draw_history_state_chart with custom trace1 decor
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
:param compare_image: fixture, returns function to compare images
"""
raise NotImplementedError


def test_draw_history_state_chart_trace2_decor(caplog, random_plotly_reporter, compare_image):
def test_draw_history_state_chart_trace2_decor(random_plotly_reporter, compare_image):
"""
Init PlotlyReporter and call draw_history_state_chart with custom trace2 decor
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
:param compare_image: fixture, returns function to compare images
"""
raise NotImplementedError


def test_draw_history_state_chart_reverse_traces(caplog, random_plotly_reporter, compare_image):
def test_draw_history_state_chart_reverse_traces(random_plotly_reporter, compare_image):
"""
Init PlotlyReporter and call draw_history_state_chart with reverced traces
Init PlotlyReporter and call draw_history_state_chart with reversed traces
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
:param compare_image: fixture, returns function to compare images
"""
raise NotImplementedError


def test_draw_history_state_chart_filename_pattern(caplog, random_plotly_reporter, compare_image):
def test_draw_history_state_chart_filename_pattern(random_plotly_reporter, compare_image):
"""
Init PlotlyReporter and call draw_history_state_chart with reverced traces
Init PlotlyReporter and call draw_history_state_chart with filename pattern
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
:param compare_image: fixture, returns function to compare images
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ def random_expected_image(case_stat):
}


def test_draw_test_case_by_area_no_cases(caplog, random_plotly_reporter):
def test_draw_test_case_by_area_no_cases(random_plotly_reporter):
"""
Init PlotlyReporter and call draw_test_case_by_area without cases should raise ValueError
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
"""
with pytest.raises(ValueError, match="No TestRail cases are provided, report aborted!"):
Expand All @@ -54,22 +53,20 @@ def test_draw_test_case_by_area_no_cases(caplog, random_plotly_reporter):
)


def test_draw_test_case_by_area_no_filename(caplog, random_plotly_reporter):
def test_draw_test_case_by_area_no_filename(random_plotly_reporter):
"""
Init PlotlyReporter and call draw_test_case_by_area without filename should raise ValueError
:param caplog: caplog fixture
:param random_plotly_reporter: fixture returns PlotlyReporter
"""
with pytest.raises(ValueError, match="No output filename is provided, report aborted!"):
random_plotly_reporter.draw_test_case_by_area(cases=[fake.pydict()])


def test_draw_test_case_by_area_creates_file(caplog, case_stat, case_stat_random, random_plotly_reporter):
def test_draw_test_case_by_area_creates_file(case_stat, case_stat_random, random_plotly_reporter):
"""
Init PlotlyReporter and call draw_test_case_by_area with valid parameters should create file
:param caplog: caplog fixture
:param case_stat: fixture returns empty CaseStat object
:param case_stat_random: fixture returns filled with random data CaseStat object
:param random_plotly_reporter: fixture returns PlotlyReporter
Expand All @@ -86,11 +83,10 @@ def test_draw_test_case_by_area_creates_file(caplog, case_stat, case_stat_random
remove(filename)


def test_draw_test_case_by_area_creates_correct_image(caplog, random_expected_image, compare_image):
def test_draw_test_case_by_area_creates_correct_image(random_expected_image, compare_image):
"""
Init PlotlyReporter and call draw_test_case_by_area with valid parameters should create correct image
:param caplog: caplog fixture
:param random_expected_image: fixture, returns any of possible expected cases
:param compare_image: fixture, returns function to compare images
"""
Expand All @@ -105,11 +101,10 @@ def test_draw_test_case_by_area_creates_correct_image(caplog, random_expected_im
remove(filename)


def test_draw_test_case_by_area_changes_ar_colors(caplog, random_expected_image, compare_image, random_rgb):
def test_draw_test_case_by_area_changes_ar_colors(random_expected_image, compare_image, random_rgb):
"""
Init PlotlyReporter and call draw_test_case_by_area with valid parameters and ar_colors should create correct image
:param caplog: caplog fixture
:param random_expected_image: fixture, returns any of possible expected cases
:param compare_image: fixture, returns function to compare images
:param random_rgb: fixture, returns random rgb in string format
Expand All @@ -128,11 +123,10 @@ def test_draw_test_case_by_area_changes_ar_colors(caplog, random_expected_image,
remove(filename)


def test_draw_test_case_by_area_changes_lines(caplog, random_expected_image, compare_image, random_rgb):
def test_draw_test_case_by_area_changes_lines(random_expected_image, compare_image, random_rgb):
"""
Init PlotlyReporter and call draw_test_case_by_area with valid parameters and ar_colors should create correct image
:param caplog: caplog fixture
:param random_expected_image: fixture, returns any of possible expected cases
:param compare_image: fixture, returns function to compare images
:param random_rgb: fixture, returns random rgb in string format
Expand Down
Loading

0 comments on commit 6c247c2

Please sign in to comment.