def test_refresher_exit_exception(self): """ Tests whether the Refresher deactivates when it receives an exit exception. """ i = get_mock_input() o = get_mock_output() def get_data(): raise RefresherExitException r = Refresher(get_data, i, o, name=r_name, refresh_interval=0.1) #Doing what an activate() would do, but without a loop r.to_foreground() #Should've caught the exception and exited, since to_foreground() calls refresh() assert r.in_foreground == False
def test_keymap_restore_on_resume(self): """Tests whether the Refresher re-sets the keymap upon resume.""" i = get_mock_input() o = get_mock_output() r = Refresher(lambda: "Hello", i, o, name=r_name, refresh_interval=0.1) r.refresh = lambda *args, **kwargs: None r.to_foreground() assert i.set_keymap.called assert i.set_keymap.call_count == 1 assert i.set_keymap.call_args[0][0] == r.keymap r.pause() assert i.set_keymap.call_count == 1 #paused, so count shouldn't change i.set_keymap(None) assert i.set_keymap.call_args[0][0] != r.keymap r.resume() assert i.set_keymap.call_count == 3 #one explicitly done in the test right beforehand assert i.set_keymap.call_args[0][0] == r.keymap
def test_refresher_view(self): text_cb = Mock() text_cb.return_value = "Test" monochrome_cb = Mock() monochrome_cb.return_value = Image.new("1", (128, 64)) color_cb = Mock() color_cb.return_value = Image.new("RGB", (128, 64)) view = RefresherView(text_cb, monochrome_cb, color_cb) i = get_mock_input() o = get_mock_output() r = Refresher(view, i, o) r.to_foreground() r.refresh() assert(text_cb.called) assert(o.display_data.called) assert(o.display_data.call_count == 2) o = get_mock_graphical_output() r = Refresher(view, i, o) r.to_foreground() r.refresh() assert(monochrome_cb.called) assert(o.display_image.called) assert(o.display_image.call_count == 2) o.type.append("color") r = Refresher(view, i, o) r.to_foreground() r.refresh() assert(color_cb.called) assert(o.display_image.called) assert(o.display_image.call_count == 4)
def test_pause_resume(self): """Tests whether the Refresher stops outputting data on the screen when it's paused, and resumes outputting data on the screen when resumed.""" i = get_mock_input() o = get_mock_output() r = Refresher(lambda: "Hello", i, o, name=r_name, refresh_interval=0.1) #refresh_interval is 0.1 so that _counter always stays 0 #and idle_loop always refreshes #Doing what an activate() would do, but without a loop r.to_foreground() assert o.display_data.called assert o.display_data.call_count == 1 #to_foreground calls refresh() r.idle_loop() assert o.display_data.call_count == 2 #not paused r.pause() r.idle_loop() assert o.display_data.call_count == 2 #paused, so count shouldn't change r.resume() assert o.display_data.call_count == 3 #resume() refreshes the display r.idle_loop() assert o.display_data.call_count == 4 #should be refresh the display normally now