Skip to content

Commit

Permalink
Merge branch 'main' of github.com:qlrd/krux-installer
Browse files Browse the repository at this point in the history
coverage of exception hooks on flash_screen
  • Loading branch information
qlrddev committed Nov 21, 2024
2 parents 50904c2 + 5dfdde4 commit c7482b0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 54 deletions.
4 changes: 2 additions & 2 deletions e2e/test_008_about_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_render_main_screen(self, mock_get_locale):

text = "".join(
[
"[ref=SourceCode][b]v0.0.20-beta[/b][/ref]",
"[ref=SourceCode][b]v0.0.20[/b][/ref]",
"\n",
"\n",
"follow us on X: ",
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_update_locale(self, mock_get_locale):

text = "".join(
[
"[ref=SourceCode][b]v0.0.20-beta[/b][/ref]",
"[ref=SourceCode][b]v0.0.20[/b][/ref]",
"\n",
"\n",
"siga-nos no X: ",
Expand Down
9 changes: 1 addition & 8 deletions e2e/test_024_warning_wipe_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ def test_on_ref_press_proceed(
[call(mock_partial(), 0), call(mock_partial(), 0)], any_order=True
)

@patch.object(EventLoopBase, "ensure_window", lambda x: None)
@patch(
"src.app.screens.base_screen.BaseScreen.get_locale", return_value="en_US.UTF-8"
)
Expand All @@ -186,16 +185,10 @@ def test_on_ref_press_deny(self, mock_set_screen, mock_get_locale):
screen.manager = MagicMock()
screen.manager.get_screen = MagicMock()

self.render(screen)

# get your Window instance safely
EventLoop.ensure_window()
window = EventLoop.window
grid = window.children[0].children[0]
label = grid.children[0]
button = screen.ids[f"{screen.id}_label"]
action = getattr(screen.__class__, f"on_ref_press_{button.id}")
action(label, "MainScreen")
action(button, "MainScreen")

mock_get_locale.assert_any_call()
mock_set_screen.assert_called_once_with(name="MainScreen", direction="right")
49 changes: 6 additions & 43 deletions e2e/test_025_error_screen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from unittest.mock import patch, MagicMock
from kivy.base import EventLoop, EventLoopBase
from kivy.base import EventLoop
from kivy.tests.common import GraphicUnitTest
from kivy.core.text import LabelBase, DEFAULT_FONT
from src.app.screens.error_screen import ErrorScreen
Expand All @@ -21,40 +21,28 @@ def setUpClass(cls):
def teardown_class(cls):
EventLoop.exit()

@patch.object(EventLoopBase, "ensure_window", lambda x: None)
@patch(
"src.app.screens.base_screen.BaseScreen.get_locale", return_value="en_US.UTF-8"
)
def test_init(self, mock_get_locale):
screen = ErrorScreen()
self.render(screen)

# get your Window instance safely
EventLoop.ensure_window()
window = EventLoop.window
grid = window.children[0].children[0]
label = grid.children[0]

# default assertions
self.assertEqual(grid.id, "error_screen_grid")
self.assertEqual(len(grid.children), 1)
self.assertEqual(label.id, "error_screen_label")
self.assertTrue("error_screen_grid" in screen.ids)
self.assertTrue("error_screen_label" in screen.ids)

# patch assertions
mock_get_locale.assert_called_once()

@patch.object(EventLoopBase, "ensure_window", lambda x: None)
@patch(
"src.app.screens.base_screen.BaseScreen.get_locale", return_value="en_US.UTF-8"
)
def test_make_label_text(self, mock_get_locale):
screen = ErrorScreen()
screen.manager = MagicMock()
screen.manager.screen_names = ["KruxInstallerApp", screen.name]
self.render(screen)

# get your Window instance safely
EventLoop.ensure_window()
label = screen.ids[f"{screen.id}_label"]

error = RuntimeError("Error: mocked error: at test")
Expand Down Expand Up @@ -93,32 +81,22 @@ def test_make_label_text(self, mock_get_locale):
# patch assertions
mock_get_locale.assert_called_once()

@patch.object(EventLoopBase, "ensure_window", lambda x: None)
@patch(
"src.app.screens.base_screen.BaseScreen.get_locale", return_value="en_US.UTF-8"
)
@patch("src.app.screens.error_screen.ErrorScreen.set_screen")
def test_on_ref_press_back(self, mock_set_screen, mock_get_locale):
screen = ErrorScreen()

self.render(screen)

# get your Window instance safely
EventLoop.ensure_window()
window = EventLoop.window
grid = window.children[0].children[0]
label = grid.children[0]
button = screen.ids[f"{screen.id}_label"]

action = getattr(ErrorScreen, f"on_ref_press_{button.id}")
action(label, "Back")
action(button, "Back")

mock_get_locale.assert_any_call()
mock_set_screen.assert_called_once_with(
name="GreetingsScreen", direction="right"
)

@patch.object(EventLoopBase, "ensure_window", lambda x: None)
@patch(
"src.app.screens.base_screen.BaseScreen.get_locale", return_value="en_US.UTF-8"
)
Expand All @@ -128,22 +106,14 @@ def test_on_ref_press_quit(self, mock_quit_app, mock_get_locale):
screen.manager = MagicMock()
screen.manager.get_screen = MagicMock()

self.render(screen)

# get your Window instance safely
EventLoop.ensure_window()
window = EventLoop.window
grid = window.children[0].children[0]
label = grid.children[0]
button = screen.ids[f"{screen.id}_label"]

action = getattr(ErrorScreen, f"on_ref_press_{button.id}")
action(label, "Quit")
action(button, "Quit")

mock_get_locale.assert_any_call()
mock_quit_app.assert_called_once()

@patch.object(EventLoopBase, "ensure_window", lambda x: None)
@patch(
"src.app.screens.base_screen.BaseScreen.get_locale", return_value="en_US.UTF-8"
)
Expand All @@ -153,17 +123,10 @@ def test_on_ref_press_report(self, mock_web_open, mock_get_locale):
screen.manager = MagicMock()
screen.manager.get_screen = MagicMock()

self.render(screen)

# get your Window instance safely
EventLoop.ensure_window()
window = EventLoop.window
grid = window.children[0].children[0]
label = grid.children[0]
button = screen.ids[f"{screen.id}_label"]

action = getattr(ErrorScreen, f"on_ref_press_{button.id}")
action(label, "ReportIssue")
action(button, "ReportIssue")

mock_get_locale.assert_any_call()
mock_web_open.assert_called_once_with(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ prefer-active-python = true

[tool.poetry]
name = "krux-installer"
version = "0.0.20-beta"
version = "0.0.20"
description = "A GUI based application to flash Krux firmware on K210 based devices"
authors = [
"qlrd <[email protected]>"
Expand Down

0 comments on commit c7482b0

Please sign in to comment.