def test_default_hooks(): from pomito.hooks.activity import ActivityHook pomito = main.Pomito() assert len(pomito._hooks) == 1 assert isinstance(pomito._hooks[0], ActivityHook) pomito.exit()
def pomito_instance(memory_db): test_factory = PomitoTestFactory() dummy_config = test_factory.create_fake_config() pomito = main.Pomito(config=dummy_config, database=memory_db) _setup_pomito_plugins(pomito) _setup_pomito_hooks(pomito) return pomito
def test_initialize_uses_injected_database(): dummy_db = SqliteDatabase(':memory:') pomito = main.Pomito(database=dummy_db) _setup_pomito_plugins(pomito) with patch('sqlite3.connect', MagicMock()): pomito.initialize() assert pomito.get_db() == dummy_db pomito.exit()
def test_initialize_creates_database_if_not_present(): with _setup_data_dir(): pomito = main.Pomito() _setup_pomito_plugins(pomito) with patch('sqlite3.connect', MagicMock()): pomito.initialize() assert pomito.get_db() is not None pomito.exit()
def test_initialize_setup_plugins_and_hooks(): with _setup_data_dir(): pomito = main.Pomito() _setup_pomito_plugins(pomito) _setup_pomito_hooks(pomito) with patch('sqlite3.connect', MagicMock()): pomito.initialize() assert pomito.ui_plugin.initialize.call_count == 1 assert pomito.task_plugin.initialize.call_count == 1 assert pomito._hooks[0].initialize.call_count == 1 pomito.exit()
def create_fake_service(self): """Create a fake instance of `Pomodoro` service. Note: call `create_patch` before calling this method if you want to replace os/path calls. See tests/hooks/test_activity.py for example. """ database = SqliteDatabase(':memory:') config = self.create_fake_config() pomito = main.Pomito(config, database, self.message_dispatcher) pomito.initialize() def create_fake_timer(duration, callback, interval=0.1): """Create a fake timer.""" return FakeTimer(duration, callback, interval) return pomodoro.Pomodoro(pomito, create_timer=create_fake_timer)
def test_session_started_perf(self): t = Mock(spec=task.Task) pomito = main.Pomito(None) pomito.ui_plugin = DummyUIPlugin() pomito.task_plugin = Mock(spec=TaskPlugin) pomito._message_dispatcher.start() pomito.pomodoro_service.signal_session_started \ .connect(pomito.ui_plugin.notify_session_started, weak=False) time_start = time.time() # initial timestamp pomito.pomodoro_service.start_session(t) time.sleep(1) time_end = pomito.ui_plugin.timestamp self.assertAlmostEqual(time_start, time_end, delta=0.1) pomito.ui_plugin.timestamp = None pomito.pomodoro_service.stop_session() pomito.exit()
def test_get_db_returns_a_valid_database(self): test_db = "dummy_db" pomodoro_service = pomodoro.Pomodoro(main.Pomito(database=test_db)) assert pomodoro_service.get_db() == test_db