def test_forward_in_book_does_not_forward_if_no_book_is_loaded(mocker): from cozy.media.player import Player mocker.patch("cozy.media.player.Player._load_last_book") player = Player() player._forward_in_book()
def test_load_book_does_not_load_book_if_it_is_none(mocker): from cozy.media.player import Player mocker.patch("cozy.media.player.Player._load_last_book") player = Player() player._load_book(None) assert player.loaded_book is None
def test_emit_tick_does_not_emit_tick_when_nothing_is_loaded(mocker): from cozy.media.player import Player mocker.patch("cozy.media.player.Player._load_last_book") player = Player() spy = mocker.spy(player, "emit_event_main_thread") player._emit_tick() spy.assert_not_called()
def test_emit_tick_does_emit_tick_on_startup_when_last_book_is_loaded(mocker): from cozy.media.player import Player mocker.patch("cozy.media.player.Player._rewind_feature") player = Player() spy = mocker.spy(player, "emit_event_main_thread") player._emit_tick() spy.assert_has_calls( calls=[call('position', player.loaded_chapter.position)])
def test_loading_new_chapter_loads_chapter(mocker): from cozy.media.player import Player mocker.patch("cozy.media.player.Player._rewind_in_book") library = inject.instance(Library) player = Player() book = library.books[0] player._load_chapter(book.current_chapter) assert player._book.current_chapter == book.current_chapter
def test_loading_new_book_emits_changed_event(mocker): from cozy.media.player import Player mocker.patch("cozy.media.player.Player._rewind_in_book") library = inject.instance(Library) player = Player() spy = mocker.spy(player, "emit_event_main_thread") book = library.books[2] player._continue_book(book) spy.assert_has_calls(calls=[call("chapter-changed", book)])
def test_loading_new_chapter_sets_playback_speed(mocker): from cozy.media.player import Player mocker.patch("cozy.media.player.Player._rewind_in_book") library = inject.instance(Library) player = Player() book = library.books[0] book.playback_speed = 2.5 player._load_chapter(book.current_chapter) print(player.playback_speed) assert player.playback_speed == book.playback_speed
def test_should_jump_to_chapter_position_returns_false_for_less_than_one_second_difference( mocker): from cozy.media.player import Player mocker.patch("cozy.media.player.Player._load_last_book") mock = mocker.patch("cozy.media.player.Player.position", new_callable=PropertyMock) mock.return_value = 10**9 player = Player() jump = player._should_jump_to_chapter_position(1.9 * 10**9) assert not jump
def test_should_jump_to_chapter_position_returns_true_for_lager_position( mocker): from cozy.media.player import Player mocker.patch("cozy.media.player.Player._load_last_book") mock = mocker.patch("cozy.media.player.Player.position", new_callable=PropertyMock) mock.return_value = 1000000000000 player = Player() jump = player._should_jump_to_chapter_position(100000000000) assert jump
def configure_inject(self, binder): binder.bind_to_provider(SqliteDatabase, get_db) binder.bind("MainWindow", self.main_window) binder.bind_to_constructor( Gio.Settings, lambda: Gio.Settings("com.github.geigi.cozy")) binder.bind_to_constructor(ApplicationSettings, lambda: ApplicationSettings()) binder.bind_to_constructor(Settings, lambda: Settings()) binder.bind_to_constructor("FilesystemMonitor", lambda: FilesystemMonitor()) binder.bind_to_constructor(OfflineCache, lambda: OfflineCache()) binder.bind_to_constructor(Player, lambda: Player()) binder.bind_to_constructor(Library, lambda: Library()) binder.bind_to_constructor(LibraryViewModel, lambda: LibraryViewModel()) binder.bind_to_constructor(SearchViewModel, lambda: SearchViewModel()) binder.bind_to_constructor(UISettings, lambda: UISettings()) binder.bind_to_constructor(StorageBlockList, lambda: StorageBlockList()) binder.bind_to_constructor(Files, lambda: Files()) binder.bind_to_constructor(BookDetailViewModel, lambda: BookDetailViewModel()) binder.bind_to_constructor(PlaybackControlViewModel, lambda: PlaybackControlViewModel()) binder.bind_to_constructor(HeaderbarViewModel, lambda: HeaderbarViewModel()) binder.bind_to_constructor(PlaybackSpeedViewModel, lambda: PlaybackSpeedViewModel()) binder.bind_to_constructor(SleepTimerViewModel, lambda: SleepTimerViewModel())
def test_initializing_player_loads_last_book(mocker): from cozy.media.player import Player mocker.patch("cozy.media.player.Player._rewind_in_book") library = inject.instance(Library) library.last_played_book = library.books[0] player = Player() assert player._book == library.last_played_book
def __init__(self): super().__init__() super(Observable, self).__init__() self._player: Player = Player() self._library_view_mode: LibraryViewMode = LibraryViewMode.CURRENT self._selected_filter: str = _("All") self._connect()
def __init__(self): super().__init__() self._model = Library(get_db()) self._fs_monitor: FilesystemMonitor = FilesystemMonitor() self._application_settings: ApplicationSettings = ApplicationSettings() self._importer: Importer = importer_instance self._player: Player = Player() self._library_view_mode: LibraryViewMode = LibraryViewMode.CURRENT self._selected_filter: str = _("All") self._connect()
def configure_inject(binder): binder.bind_to_provider(SqliteDatabase, get_db) binder.bind_to_constructor( Gio.Settings, lambda: Gio.Settings("com.github.geigi.cozy")) binder.bind_to_constructor(ApplicationSettings, lambda: ApplicationSettings()) binder.bind_to_constructor(Settings, lambda: Settings()) binder.bind_to_constructor("FilesystemMonitor", lambda: FilesystemMonitor()) binder.bind_to_constructor(Player, lambda: Player()) binder.bind_to_constructor(Library, lambda: Library()) binder.bind_to_constructor(LibraryViewModel, lambda: LibraryViewModel()) binder.bind_to_constructor(SearchViewModel, lambda: SearchViewModel()) binder.bind_to_constructor(UISettings, lambda: UISettings()) binder.bind_to_constructor(StorageBlockList, lambda: StorageBlockList()) binder.bind_to_constructor(Files, lambda: Files())
def test_play_pause_chapter_does_not_trigger_chapter_or_book_reload_when_book_has_been_played_before( mocker): from cozy.media.player import Player mocker.patch("cozy.media.player.Player._load_last_book") player = Player() library = inject.instance(Library) book = library.books[0] chapter = book.chapters[0] # Start Playback player.play_pause_chapter(book, chapter) spy_book = mocker.spy(player, "_load_book") spy_chapter = mocker.spy(player, "_load_chapter") # Pause Playback. Spies should not record any book or chapter reload player.play_pause_chapter(book, chapter) spy_book.assert_not_called() spy_chapter.assert_not_called()