Skip to content

Commit

Permalink
style: format code with Black, isort and Ruff Formatter (#226)
Browse files Browse the repository at this point in the history
* style: format code with Black, isort and Ruff Formatter

This commit fixes the style issues introduced in b9cf8cf according to the output
from Black, isort and Ruff Formatter.

Details: None

* style: format code with Black, isort and Ruff Formatter

This commit fixes the style issues introduced in 35504e0 according to the output
from Black, isort and Ruff Formatter.

Details: #226

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Co-authored-by: bartholomew-smith[bot] <156136305+bartholomew-smith[bot]@users.noreply.github.com>
Co-authored-by: Heitor Polidoro <[email protected]>
  • Loading branch information
3 people authored Jul 22, 2024
1 parent 7832a57 commit b67fe68
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 46 deletions.
78 changes: 44 additions & 34 deletions githubapp/event_check_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ class SubRun:
"""

def __init__(
self,
parent_check_run: "EventCheckRun",
name: str,
status: CheckRunStatus = None,
summary: str = None,
self,
parent_check_run: "EventCheckRun",
name: str,
status: CheckRunStatus = None,
summary: str = None,
) -> None:
self.parent_check_run = parent_check_run
self.name = name
Expand All @@ -91,12 +91,12 @@ def __repr__(self) -> str: # pragma: no cover
return f"SubRun({_dict})"

def update(
self,
title: str = None,
status: CheckRunStatus = None,
summary: str = None,
conclusion: CheckRunConclusion = None,
update_check_run: bool = True,
self,
title: str = None,
status: CheckRunStatus = None,
summary: str = None,
conclusion: CheckRunConclusion = None,
update_check_run: bool = True,
) -> None:
"""Update a sub run"""
self.title = title or self.title
Expand Down Expand Up @@ -154,14 +154,16 @@ def set_icons(cls) -> None:
elif isinstance(icons_set, dict):
cls.icons = icons_set
else:
raise AttributeError(f"Icons set must be a string or a dictionary. {type(icons_set)}")
raise AttributeError(
f"Icons set must be a string or a dictionary. {type(icons_set)}"
)

def start(
self,
status: CheckRunStatus = CheckRunStatus.WAITING,
summary: str = None,
title: str = None,
text: str = None,
self,
status: CheckRunStatus = CheckRunStatus.WAITING,
summary: str = None,
title: str = None,
text: str = None,
) -> None:
"""Start a check run"""
output = {"title": title or self.name, "summary": summary or ""}
Expand Down Expand Up @@ -194,13 +196,13 @@ def build_summary(cls, sub_runs: list[SubRun]) -> str:
return summary

def update(
self,
title: str = None,
status: CheckRunStatus = None,
summary: str = None,
conclusion: CheckRunConclusion = None,
text: str = None,
**output,
self,
title: str = None,
status: CheckRunStatus = None,
summary: str = None,
conclusion: CheckRunConclusion = None,
text: str = None,
**output,
) -> None:
"""Updates the check run"""

Expand All @@ -221,29 +223,37 @@ def clean_dict(d: dict[str, Any]) -> dict[str, Any]:
output = clean_dict(output) or None
args = {
"status": status.value if isinstance(status, Enum) else status,
"conclusion": conclusion.value if isinstance(conclusion, Enum) else conclusion,
"conclusion": conclusion.value
if isinstance(conclusion, Enum)
else conclusion,
"output": output,
}
if args := clean_dict(args):
self._check_run.edit(**args)

def finish(
self,
title: str = None,
status: CheckRunStatus = None,
summary: str = None,
conclusion: CheckRunConclusion = None,
text: str = None,
**output,
self,
title: str = None,
status: CheckRunStatus = None,
summary: str = None,
conclusion: CheckRunConclusion = None,
text: str = None,
**output,
) -> None:
"""Finish the Check Run"""
conclusions_list_order = {c: i for i, c in enumerate(CheckRunConclusion)}
sub_run_name = None
sub_run_title = None
for sub_run in self.sub_runs:
if not sub_run.conclusion:
sub_run.update(conclusion=CheckRunConclusion.CANCELLED, update_check_run=False)
if conclusion is None or conclusions_list_order[sub_run.conclusion] < conclusions_list_order[conclusion]:
sub_run.update(
conclusion=CheckRunConclusion.CANCELLED, update_check_run=False
)
if (
conclusion is None
or conclusions_list_order[sub_run.conclusion]
< conclusions_list_order[conclusion]
):
conclusion = sub_run.conclusion
sub_run_name = None
sub_run_title = None
Expand Down
52 changes: 40 additions & 12 deletions tests/test_event_check_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
@pytest.fixture(autouse=True)
def mock_check_run(event):
repository = event.repository
repository.create_check_run.return_value = Mock(output=Mock(title=None, summary=None))
repository.create_check_run.return_value = Mock(
output=Mock(title=None, summary=None)
)


@pytest.mark.parametrize(
Expand All @@ -31,7 +33,9 @@ def mock_check_run(event):
],
)
def test_set_icons(sub_runs_icons, expected_icons):
with patch.object(Config, "SUB_RUNS_ICONS", sub_runs_icons), patch.object(EventCheckRun, "icons", {}):
with patch.object(Config, "SUB_RUNS_ICONS", sub_runs_icons), patch.object(
EventCheckRun, "icons", {}
):
if expected_icons == AttributeError:
with pytest.raises(expected_icons):
EventCheckRun.set_icons()
Expand Down Expand Up @@ -71,14 +75,18 @@ def test_update_check_run_with_only_conclusion(event):
check_run = EventCheckRun(event.repository, "name", "sha")
check_run.start(title="title")
check_run.update(conclusion=CheckRunConclusion.SUCCESS)
check_run._check_run.edit.assert_called_with(status="completed", conclusion="success")
check_run._check_run.edit.assert_called_with(
status="completed", conclusion="success"
)


def test_update_check_run_with_output(event):
check_run = EventCheckRun(event.repository, "name", "sha")
check_run.start(title="title", summary="summary")
check_run.update(title="new_title", summary="new_summary")
check_run._check_run.edit.assert_called_with(output={"title": "new_title", "summary": "new_summary"})
check_run._check_run.edit.assert_called_with(
output={"title": "new_title", "summary": "new_summary"}
)


def test_update_check_run_with_only_output_text(event):
Expand All @@ -87,7 +95,9 @@ def test_update_check_run_with_only_output_text(event):
check_run._check_run.output.title = "title"
check_run._check_run.output.summary = "summary"
check_run.update(text="text")
check_run._check_run.edit.assert_called_with(output={"title": "title", "summary": "summary", "text": "text"})
check_run._check_run.edit.assert_called_with(
output={"title": "title", "summary": "summary", "text": "text"}
)


def test_update_check_run_with_nothing(event):
Expand Down Expand Up @@ -119,7 +129,9 @@ def test_sub_check_run(event):
}
)
check_run_edit.reset_mock()
sub_run1.update(title="sub 1 title", summary="sub 1 other summary", update_check_run=False)
sub_run1.update(
title="sub 1 title", summary="sub 1 other summary", update_check_run=False
)
check_run_edit.assert_not_called()
sub_run2.update(title="sub 2 title", summary="sub 2 other summary")
check_run_edit.assert_called_once_with(
Expand All @@ -138,10 +150,14 @@ def test_sub_check_run_icons(event):
with patch.object(EventCheckRun, "icons", icons):
for status in CheckRunStatus:
sub_run1.update(status=status)
check_run._check_run.edit.assert_called_with(output={"summary": f":{status.value}: sub 1: "})
check_run._check_run.edit.assert_called_with(
output={"summary": f":{status.value}: sub 1: "}
)
for conclusion in CheckRunConclusion:
sub_run1.update(conclusion=conclusion)
check_run._check_run.edit.assert_called_with(output={"summary": f":{conclusion.value}: sub 1: "})
check_run._check_run.edit.assert_called_with(
output={"summary": f":{conclusion.value}: sub 1: "}
)


def test_check_run_getattr(event):
Expand All @@ -155,7 +171,9 @@ def test_check_run_getattr(event):
},
completed=True,
)
with patch.object(event.repository, "create_check_run", return_value=mocked_check_run):
with patch.object(
event.repository, "create_check_run", return_value=mocked_check_run
):
check_run = EventCheckRun(event.repository, "name", "sha")
assert check_run.anny_attr is None
check_run.start()
Expand Down Expand Up @@ -249,13 +267,23 @@ def test_finish_check_run_with_sub_runs(
sub_run2 = check_run.create_sub_run("sub 2")

sub_run1.update(conclusion=sub_run1_initial_conclusion, update_check_run=False)
sub_run2.update(title=f"Sub 2 title", conclusion=sub_run2_initial_conclusion, update_check_run=False)
sub_run2.update(
title=f"Sub 2 title",
conclusion=sub_run2_initial_conclusion,
update_check_run=False,
)
check_run.finish(conclusion=conclusion)

check_run._check_run.edit.assert_called_once_with(
status="completed",
conclusion=expected_conclusion.value,
output={"summary": "sub 1: \nsub 2: Sub 2 title", "title": expected_title},
)
assert sub_run1.conclusion == sub_run1_initial_conclusion or CheckRunConclusion.CANCELLED
assert sub_run2.conclusion == sub_run2_initial_conclusion or CheckRunConclusion.CANCELLED
assert (
sub_run1.conclusion == sub_run1_initial_conclusion
or CheckRunConclusion.CANCELLED
)
assert (
sub_run2.conclusion == sub_run2_initial_conclusion
or CheckRunConclusion.CANCELLED
)

0 comments on commit b67fe68

Please sign in to comment.