def test_returns_right_values(self): """Checking that going to different options returns the right values""" # Checking first option - Yes db = DialogBox("ync", get_mock_input(), get_mock_output(), name=db_name) def scenario(): db.accept_value() # KEY_ENTER assert not db.in_foreground # Should exit with patch.object(db, 'idle_loop', side_effect=scenario) as p: return_value = db.activate() assert return_value is True #First element - Yes, means True # Checking second option - No db = DialogBox("ync", get_mock_input(), get_mock_output(), name=db_name) def scenario(): db.move_right() db.accept_value() # KEY_ENTER assert not db.in_foreground # Should exit with patch.object(db, 'idle_loop', side_effect=scenario) as p: return_value = db.activate() assert return_value is False #Second element - No, means False # Checking second option - Cancel db = DialogBox("ync", get_mock_input(), get_mock_output(), name=db_name) def scenario(): db.move_right() db.move_right() db.accept_value() # KEY_ENTER assert not db.in_foreground # Should exit with patch.object(db, 'idle_loop', side_effect=scenario) as p: return_value = db.activate() assert return_value is None #Last element - Cancel, means None
def test_left_key_returns_none(self): db = DialogBox("ync", get_mock_input(), get_mock_output(), name=db_name) db.refresh = lambda *args, **kwargs: None # Checking at the start of the options def scenario(): db.move_left() assert not db.in_foreground with patch.object(db, 'idle_loop', side_effect=scenario) as p: return_value = db.activate() assert return_value is None # Going to the right and then going to the left again def scenario(): db.move_right() db.move_left() #At this point, shouldn't exit assert db.in_foreground db.move_left() assert not db.in_foreground with patch.object(db, 'idle_loop', side_effect=scenario) as p: return_value = db.activate() assert return_value is None
def control_autosend(): is_autosent = config.get("autosend", False) d = DialogBox("yn", i, o, message="Automatically send bugreports?", name="Autosend control dialog box") d.set_start_option(0 if is_autosent else 1) choice = d.activate() if choice is not None: config["autosend"] = True if choice else False save_config(config)
def test_shows_data_on_screen(self): """Tests whether the DialogBox outputs data on screen when it's ran""" i = get_mock_input() o = get_mock_output() db = DialogBox("ync", i, o, name=db_name) def scenario(): db.deactivate() with patch.object(db, 'idle_loop', side_effect=scenario) as p: db.activate() #The scenario should only be called once assert db.idle_loop.called assert db.idle_loop.call_count == 1 assert o.display_data.called assert o.display_data.call_count == 1 #One in to_foreground assert o.display_data.call_args[0] == ('Are you sure?', ' Yes No Cancel')
def test_start_option(self): db = DialogBox("ync", get_mock_input(), get_mock_output(), name=db_name) db.refresh = lambda *args, **kwargs: None db.set_start_option(1) #So, "No" option would be selected def scenario(): db.accept_value() # KEY_ENTER assert not db.in_foreground # Should exit with patch.object(db, 'idle_loop', side_effect=scenario) as p: return_value = db.activate() assert return_value is False #Second element - No, means False
def test_graphical_display_redraw(self): o = get_mock_graphical_output() db = DialogBox("ync", get_mock_input(), o, name=db_name) Canvas.fonts_dir = fonts_dir # Exiting immediately, but we should get at least one redraw def scenario(): db.deactivate() # KEY_LEFT assert not db.in_foreground with patch.object(db, 'idle_loop', side_effect=scenario) as p: return_value = db.activate() assert o.display_image.called assert o.display_image.call_count == 1 #One in to_foreground
def change_range(): global config dialogbox_options = [["Safe", "conservative"], ["Full", "full"], "c"] dialogbox = DialogBox(dialogbox_options, i, o, message="Scan range", name="I2C tools app range setting dialogbox") if config.get("scan_range", "conservative") == "full": # setting dialogbox position to the "full" option as it's currently selected dialogbox.set_start_option(1) new_range = dialogbox.activate() if new_range is not None: config["scan_range"] = new_range save_config(config)