def test_dojo_dojo_timer_running(input, mocked_dojo): mocked_dojo.is_running = True mocked_dojo.timer.is_running = True def stop_dojo(): mocked_dojo.is_running = False def stop_timer(): mocked_dojo.timer.is_running = False mocked_dojo.round_info = mock.Mock(side_effect=stop_timer) mocked_dojo.round_finished = mock.Mock(side_effect=stop_dojo) mocked_dojo.dojo()
def test_code_handler_on_modified(get_interval, mocked_code_handler): mocked_code_handler.test_runner.run.return_value = True get_interval.return_value = 10 mocked_code_handler.on_modified(mock.Mock()) assert get_interval.called assert mocked_code_handler.test_runner.run.called
def __init__(self, code_path, round_time=None, mute=False, test_runner=None): self.code_path = code_path self.round_time = round_time or self.ROUND_TIME self.sound_player = mock.Mock() if mute else SoundHandler() test_runner = test_runner or DoctestTestRunner( code_path=code_path, sound_player=self.sound_player) event_handler = DojoCodeHandler(dojo=self, test_runner=test_runner) self.observer = Observer() self.observer.schedule(event_handler, self.code_path, recursive=False) self.timer = Timer(self.round_time)
def mocked_dojo(): with mock.patch('dojo_toolkit.dojo.Observer'), \ mock.patch('dojo_toolkit.dojo.Timer'), \ mock.patch('dojo_toolkit.dojo.SoundHandler'): return Dojo('/foo/bar', test_runner=mock.Mock())
def test_dojo_dojo(input, mocked_dojo): mocked_dojo.is_running = True mocked_dojo.timer.is_running = False mocked_dojo.round_finished = mock.Mock(side_effect=KeyboardInterrupt) with pytest.raises(KeyboardInterrupt): mocked_dojo.dojo()
def wrong_test_runner(code_path): with mock.patch('dojo_toolkit.test_runner.notifier'): return WrongTestRunner(code_path, sound_player=mock.Mock())
def mock_test_runner(code_path): return MockTestRunner(code_path, sound_player=mock.Mock())
def test_code_handler(): code_handler = DojoCodeHandler(test_runner=mock.Mock(), dojo=mock.Mock()) assert code_handler.last_test_run_time
def mocked_code_handler(): code_handler = DojoCodeHandler(test_runner=mock.Mock(), dojo=mock.Mock()) return code_handler