diff --git a/safeeyes/__main__.py b/safeeyes/__main__.py
index 2d8ac43d..d922fc8c 100755
--- a/safeeyes/__main__.py
+++ b/safeeyes/__main__.py
@@ -28,7 +28,7 @@
from safeeyes.safeeyes import SafeEyes
-def main():
+def main() -> None:
"""Start the Safe Eyes."""
signal.signal(signal.SIGINT, signal.SIG_DFL) # Handle Ctrl + C
diff --git a/safeeyes/context.py b/safeeyes/context.py
index e92d5128..4244b548 100644
--- a/safeeyes/context.py
+++ b/safeeyes/context.py
@@ -18,6 +18,7 @@
from collections.abc import MutableMapping
import datetime
+import gettext
import typing
from safeeyes import utility
@@ -78,7 +79,7 @@ class Context(MutableMapping):
api: API
desktop: str
is_wayland: bool
- locale: str
+ locale: gettext.NullTranslations
session: dict[str, typing.Any]
state: State
@@ -92,7 +93,7 @@ class Context(MutableMapping):
def __init__(
self,
api: API,
- locale: str,
+ locale: gettext.NullTranslations,
version: str,
session: dict[str, typing.Any],
) -> None:
diff --git a/safeeyes/safeeyes.py b/safeeyes/safeeyes.py
index d2ddcba7..8ef27bb2 100644
--- a/safeeyes/safeeyes.py
+++ b/safeeyes/safeeyes.py
@@ -21,6 +21,7 @@
"""
import atexit
+import gettext
import logging
from importlib import metadata
import typing
@@ -51,11 +52,11 @@ class SafeEyes(Gtk.Application):
break_screen: BreakScreen
safe_eyes_core: SafeEyesCore
plugins_manager: PluginManager
- system_locale: str
+ system_locale: gettext.NullTranslations
_settings_dialog: typing.Optional[SettingsDialog] = None
- def __init__(self, system_locale: str, config) -> None:
+ def __init__(self, system_locale: gettext.NullTranslations, config) -> None:
super().__init__(
application_id="io.github.slgobinath.SafeEyes",
flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
diff --git a/safeeyes/tests/test_core.py b/safeeyes/tests/test_core.py
index 669c2032..f8be1bab 100644
--- a/safeeyes/tests/test_core.py
+++ b/safeeyes/tests/test_core.py
@@ -17,6 +17,7 @@
# along with this program. If not, see .
import datetime
+import gettext
import pytest
import typing
@@ -130,6 +131,14 @@ def create_handle(safe_eyes_core: core.SafeEyesCore) -> SafeEyesCoreHandle:
yield create_handle
+ def get_context(self) -> context.Context:
+ return context.Context(
+ api=mock.Mock(spec=context.API),
+ locale=gettext.NullTranslations(),
+ version="0.0.0",
+ session={},
+ )
+
def run_next_break(
self,
sequential_threading_handle: SafeEyesCoreHandle,
@@ -252,9 +261,7 @@ def assert_datetime(self, string: str):
) == datetime.datetime.fromisoformat(string)
def test_start_empty(self, sequential_threading: SequentialThreadingFixture):
- ctx = context.Context(
- api=mock.Mock(spec=context.API), locale="en_US", version="0.0.0", session={}
- )
+ ctx = self.get_context()
config = model.Config(
user_config={
"short_breaks": [],
@@ -280,9 +287,7 @@ def test_start_empty(self, sequential_threading: SequentialThreadingFixture):
on_update_next_break.assert_not_called()
def test_start(self, sequential_threading: SequentialThreadingFixture):
- ctx = context.Context(
- api=mock.Mock(spec=context.API), locale="en_US", version="0.0.0", session={}
- )
+ ctx = self.get_context()
config = model.Config(
user_config={
"short_breaks": [
@@ -335,9 +340,7 @@ def test_full_run_with_defaults(
sequential_threading: SequentialThreadingFixture,
time_machine: TimeMachineFixture,
):
- ctx = context.Context(
- api=mock.Mock(spec=context.API), locale="en_US", version="0.0.0", session={}
- )
+ ctx = self.get_context()
short_break_duration = 15 # seconds
short_break_interval = 15 # minutes
pre_break_warning_time = 10 # seconds
@@ -462,9 +465,7 @@ def test_long_duration_is_bigger_than_short_interval(
time_machine: TimeMachineFixture,
):
"""Example taken from https://github.com/slgobinath/safeeyes/issues/640."""
- ctx = context.Context(
- api=mock.Mock(spec=context.API), locale="en_US", version="0.0.0", session={}
- )
+ ctx = self.get_context()
short_break_duration = 300 # seconds = 5min
short_break_interval = 25 # minutes
pre_break_warning_time = 10 # seconds
@@ -578,9 +579,7 @@ def test_idle(
time_machine: TimeMachineFixture,
):
"""Test idling for short amount of time."""
- ctx = context.Context(
- api=mock.Mock(spec=context.API), locale="en_US", version="0.0.0", session={}
- )
+ ctx = self.get_context()
short_break_duration = 15 # seconds
short_break_interval = 15 # minutes
pre_break_warning_time = 10 # seconds
@@ -721,9 +720,7 @@ def test_idle_skip_long(
time_machine: TimeMachineFixture,
):
"""Test idling for longer than long break time."""
- ctx = context.Context(
- api=mock.Mock(spec=context.API), locale="en_US", version="0.0.0", session={}
- )
+ ctx = self.get_context()
short_break_duration = 15 # seconds
short_break_interval = 15 # minutes
pre_break_warning_time = 10 # seconds
@@ -879,9 +876,7 @@ def test_idle_skip_long_before_long(
This used to skip all the short breaks too.
"""
- ctx = context.Context(
- api=mock.Mock(spec=context.API), locale="en_US", version="0.0.0", session={}
- )
+ ctx = self.get_context()
short_break_duration = 15 # seconds
short_break_interval = 15 # minutes
pre_break_warning_time = 10 # seconds
diff --git a/safeeyes/tests/test_model.py b/safeeyes/tests/test_model.py
index 0be8c516..3ddefba5 100644
--- a/safeeyes/tests/test_model.py
+++ b/safeeyes/tests/test_model.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
+import gettext
import pytest
import random
import typing
@@ -52,6 +53,14 @@ def test_break_long(self) -> None:
class TestBreakQueue:
+ def get_context(self) -> context.Context:
+ return context.Context(
+ api=mock.Mock(spec=context.API),
+ locale=gettext.NullTranslations(),
+ version="0.0.0",
+ session={},
+ )
+
def test_create_empty(self) -> None:
config = model.Config(
user_config={
@@ -66,11 +75,7 @@ def test_create_empty(self) -> None:
system_config={},
)
- ctx = context.Context(
- api=mock.Mock(spec=context.API), locale="en_US", version="0.0.0", session={}
- )
-
- bq = model.BreakQueue.create(config, ctx)
+ bq = model.BreakQueue.create(config, self.get_context())
assert bq is None
@@ -101,11 +106,7 @@ def get_bq_only_short(
system_config={},
)
- ctx = context.Context(
- api=mock.Mock(spec=context.API), locale="en_US", version="0.0.0", session={}
- )
-
- bq = model.BreakQueue.create(config, ctx)
+ bq = model.BreakQueue.create(config, self.get_context())
assert bq is not None
@@ -138,11 +139,7 @@ def get_bq_only_long(
system_config={},
)
- ctx = context.Context(
- api=mock.Mock(spec=context.API), locale="en_US", version="0.0.0", session={}
- )
-
- bq = model.BreakQueue.create(config, ctx)
+ bq = model.BreakQueue.create(config, self.get_context())
assert bq is not None
@@ -180,11 +177,7 @@ def get_bq_full(
system_config={},
)
- ctx = context.Context(
- api=mock.Mock(spec=context.API), locale="en_US", version="0.0.0", session={}
- )
-
- bq = model.BreakQueue.create(config, ctx)
+ bq = model.BreakQueue.create(config, self.get_context())
assert bq is not None
diff --git a/safeeyes/translations.py b/safeeyes/translations.py
index be71d466..fc3dc7a5 100644
--- a/safeeyes/translations.py
+++ b/safeeyes/translations.py
@@ -26,7 +26,7 @@
_translations = gettext.NullTranslations()
-def setup():
+def setup() -> gettext.NullTranslations:
global _translations
_translations = gettext.translation(
"safeeyes",