Skip to content

Commit

Permalink
Merge pull request #109 from qlrd/main
Browse files Browse the repository at this point in the history
v0.0.20
  • Loading branch information
qlrd authored Dec 20, 2024
2 parents 13570ec + b6a489c commit 471d45a
Show file tree
Hide file tree
Showing 61 changed files with 2,695 additions and 434 deletions.
4 changes: 2 additions & 2 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ coverage:
status:
project:
default:
target: 100%
threshold: 15%
target: 95%
threshold: 5%
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ without typing any command in terminal for [flash the firmware onto the device](

## Installing

There are pre-built
[releases](https://github.com/selfcustody/krux-installer/releases) for:
[<img src="img/badge_github.png" alt="github releases page" width="186">](https://github.com/selfcustody/krux-installer/releases)

Available for:

* Linux:
* Debian-like;
Expand All @@ -23,7 +24,7 @@ There are pre-built
* intel processors;
* arm64 processors (M1/M2/M3).

To build it from the source, please follow the steps below:
## Build from source

* [System setup](/#system-setup)
* [Linux](/#linux)
Expand Down
71 changes: 70 additions & 1 deletion e2e/test_000_base_screen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
from pathlib import Path
from unittest.mock import patch, call, MagicMock
from kivy.base import EventLoop, EventLoopBase
Expand Down Expand Up @@ -93,12 +94,21 @@ def test_static_open_settings(self, mock_get_ruunning_app):
BaseScreen.open_settings()
mock_get_ruunning_app.return_value.open_settings.assert_called_once()

@patch.object(EventLoopBase, "ensure_window", lambda x: None)
@patch("src.app.screens.base_screen.App.get_running_app")
def test_static_quit_app(self, mock_get_ruunning_app):
mock_get_ruunning_app.return_value = MagicMock()
mock_get_ruunning_app.return_value.stop = MagicMock()

BaseScreen.quit_app()
mock_get_ruunning_app.return_value.stop.assert_called_once()

@patch.object(EventLoopBase, "ensure_window", lambda x: None)
@patch("sys.platform", "linux")
@patch(
"src.app.screens.base_screen.BaseScreen.get_locale", return_value="en_US.UTF-8"
)
def test_init_linux(self, mock_get_locale):
def test_init_linux_no_frozen(self, mock_get_locale):
screen = BaseScreen(wid="mock", name="Mock")
self.render(screen)

Expand All @@ -112,6 +122,31 @@ def test_init_linux(self, mock_get_locale):

mock_get_locale.assert_called_once()

@patch.object(EventLoopBase, "ensure_window", lambda x: None)
@patch("sys.platform", "linux")
@patch(
"src.app.screens.base_screen.BaseScreen.get_locale", return_value="en_US.UTF-8"
)
def test_init_linux_frozen(self, mock_get_locale):
with patch.dict(
sys.__dict__, {"_MEIPASS": os.path.join("mock", "path"), "frozen": True}
):
screen = BaseScreen(wid="mock", name="Mock")
self.render(screen)

# get your Window instance safely
EventLoop.ensure_window()
window = EventLoop.window

# your asserts
self.assertEqual(
screen.logo_img, os.path.join("mock", "path", "assets", "logo.png")
)
self.assertEqual(window.children[0], screen)
self.assertEqual(window.children[0].height, window.height)

mock_get_locale.assert_called_once()

@patch.object(EventLoopBase, "ensure_window", lambda x: None)
@patch("src.app.screens.base_screen.BaseScreen.get_locale")
def test_init_win32(self, mock_get_locale):
Expand Down Expand Up @@ -401,6 +436,40 @@ def test_update_screen_locale(self, mock_get_locale):
self.assertEqual(screen.locale, "mocked")
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.base_screen.BaseScreen.redirect_exception")
def test_fail_update_screen_locale(self, mock_redirect_exception, mock_get_locale):
screen = BaseScreen(wid="mock", name="Mock")
screen.make_grid(wid="mock_grid", rows=1)
screen.make_button(
row=0,
wid="mock_button",
root_widget="mock_grid",
text="Mocked button",
font_factor=32,
halign=None,
on_press=MagicMock(),
on_release=MagicMock(),
on_ref_press=MagicMock(),
)
setattr(screen, "update", MagicMock())
self.render(screen)
self.assertEqual(screen.locale, "en_US.UTF-8")

screen.update_screen(
name="MockedScreen",
key="locale",
value=None,
allowed_screens=("MockedScreen",),
on_update=MagicMock(),
)

mock_get_locale.assert_called_once()
mock_redirect_exception.assert_called_once()

@patch.object(EventLoopBase, "ensure_window", lambda x: None)
@patch("src.app.screens.base_screen.BaseScreen.get_locale")
@patch("src.app.screens.base_screen.Color")
Expand Down
48 changes: 34 additions & 14 deletions e2e/test_001_greetings_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from kivy.tests.common import GraphicUnitTest
from src.app.screens.greetings_screen import GreetingsScreen

# to be used in mocking grp
import src.app.screens.greetings_screen


class TestAboutScreen(GraphicUnitTest):

Expand Down Expand Up @@ -317,40 +320,50 @@ def test_fail_get_os_dialout_group_file_not_found(
mock_redirect_exception.assert_called()

@mark.skipif(
sys.platform in ("win32", "darwin"),
reason="does not run on windows or macos",
sys.platform in ("win32"),
reason="does not run on windows",
)
@patch("sys.platform", "linux") # Patch platform to Linux
@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.greetings_screen.grp")
def test_is_user_not_in_dialout(self, mock_grp, mock_get_locale):
def test_is_user_not_in_dialout(self, mock_get_locale):
# Create a mock grp module
mock_grp = MagicMock()
mock_grp.getgrall.return_value = [
MagicMock(gr_name="dialout", gr_passwd="x", gr_gid=1234, gr_mem=["brltty"])
]
# mock_grp.getgrall.return_value[0].__getitem__ = MagicMock(
# return_value=['dialout', 'x', 1234, ['brltty']]
# )

# Temporarily add the mock grp to greetings_screen's global namespace
setattr(src.app.screens.greetings_screen, "grp", mock_grp)

# Initialize the screen and call the method to test
screen = GreetingsScreen()
is_in_dialout = screen.is_user_in_dialout_group(
user="mockuser", group="dialout"
)
self.assertEqual(is_in_dialout, False)

# Assertions
self.assertEqual(is_in_dialout, False)
mock_get_locale.assert_called()
mock_grp.getgrall.assert_called()

# Clean up by removing the mock from the module's namespace
delattr(src.app.screens.greetings_screen, "grp")

@mark.skipif(
sys.platform in ("win32", "darwin"),
reason="does not run on windows or macos",
sys.platform in ("win32"),
reason="does not run on windows",
)
@patch("sys.platform", "linux") # Patch platform to Linux
@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.greetings_screen.grp")
def test_is_user_in_dialout(self, mock_grp, mock_get_locale):
def test_is_user_in_dialout(self, mock_get_locale):
# Create a mock grp module
mock_grp = MagicMock()
mock_grp.getgrall.return_value = [
MagicMock(
gr_name="dialout",
Expand All @@ -359,6 +372,11 @@ def test_is_user_in_dialout(self, mock_grp, mock_get_locale):
gr_mem=["brltty", "mockuser"],
)
]

# Temporarily add the mock grp to greetings_screen's global namespace
setattr(src.app.screens.greetings_screen, "grp", mock_grp)

# Initialize the screen and call the method to test
screen = GreetingsScreen()
is_in_dialout = screen.is_user_in_dialout_group(
user="mockuser", group="dialout"
Expand Down Expand Up @@ -459,9 +477,10 @@ def test_pass_check_dialout_permission_not_linux(
mock_schedule_once.assert_called()

@mark.skipif(
sys.platform in ("win32", "darwin"),
sys.platform in ("win32"),
reason="does not run on windows or darwin",
)
@patch("sys.platform", "linux")
@patch.object(EventLoopBase, "ensure_window", lambda x: None)
@patch("src.app.screens.greetings_screen.os.environ.get", return_value="mockuser")
@patch(
Expand Down Expand Up @@ -501,9 +520,10 @@ def test_check_dialout_permission_not_in_dialout(
mock_in_dialout.assert_called()

@mark.skipif(
sys.platform in ("win32", "darwin"),
sys.platform in ("win32"),
reason="does not run on windows or darwin",
)
@patch("sys.platform", "linux")
@patch.object(EventLoopBase, "ensure_window", lambda x: None)
@patch("src.app.screens.greetings_screen.os.environ.get", return_value="mockuser")
@patch(
Expand Down
Loading

0 comments on commit 471d45a

Please sign in to comment.