Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion safeeyes/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions safeeyes/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from collections.abc import MutableMapping
import datetime
import gettext
import typing

from safeeyes import utility
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions safeeyes/safeeyes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"""

import atexit
import gettext
import logging
from importlib import metadata
import typing
Expand Down Expand Up @@ -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,
Expand Down
37 changes: 16 additions & 21 deletions safeeyes/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import datetime
import gettext
import pytest
import typing

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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": [],
Expand All @@ -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": [
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
33 changes: 13 additions & 20 deletions safeeyes/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import gettext
import pytest
import random
import typing
Expand Down Expand Up @@ -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={
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion safeeyes/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
_translations = gettext.NullTranslations()


def setup():
def setup() -> gettext.NullTranslations:
global _translations
_translations = gettext.translation(
"safeeyes",
Expand Down