def test_card_form_value_textarea(): """ Return the current value of the textarea widget. """ card = Card("title", form=Inputs.TEXTAREA, text="Form label...") mock_screen_manager = mock.MagicMock() data_store = {} card.screen(mock_screen_manager, data_store) card.textarea.text = "foobarbaz" assert card.form_value() == "foobarbaz"
def test_card_next_card_with_string(): """ Ensure the string value set as the auto_target is used to transition the screen manager. """ card = Card("title") card.data_store = {} card.form_value = mock.MagicMock(return_value=None) card.auto_target = "AnotherCard" card.screen_manager = mock.MagicMock() card._next_card(0.1) assert card.screen_manager.current == "AnotherCard"
def test_card_form_value_slider(): """ Return the current value of the slider widget. """ card = Card( "title", form=Inputs.SLIDER, text="Form label...", options=[1, 100] ) mock_screen_manager = mock.MagicMock() data_store = {} card.screen(mock_screen_manager, data_store) card.slider_label.text = "50" assert card.form_value() == 50.0
def test_card_button_click_with_string(): """ Ensure the function returned from the _button_click method works by transitioning the screen manager to the string value it returns. """ card = Card("title") card.data_store = {} card.form_value = mock.MagicMock(return_value=None) card.screen_manager = mock.MagicMock() handler = card._button_click("AnotherCard") assert callable(handler) handler(None) assert card.screen_manager.current == "AnotherCard"
def test_card_form_value_select_nothing(): """ Return the current value of the select widget, if none are selected (should return None). """ card = Card( "title", form=Inputs.SELECT, text="Form label...", options=["foo", "bar", "baz"], ) mock_screen_manager = mock.MagicMock() data_store = {} card.screen(mock_screen_manager, data_store) assert card.form_value() is None
def test_card_form_value_select(): """ Return the current value of the select widget. """ card = Card( "title", form=Inputs.SELECT, text="Form label...", options=["foo", "bar", "baz"], ) mock_screen_manager = mock.MagicMock() data_store = {} card.screen(mock_screen_manager, data_store) card.select[0].state = "down" assert card.form_value() == "foo"
def test_card_next_card_with_callable(): """ Ensure the string return value of the function set as the auto_target is used to transition the screen manager. """ def fn(data_store, form_value): return "AnotherCard" card = Card("title") card.data_store = {} card.form_value = mock.MagicMock(return_value=None) card.auto_target = fn card.screen_manager = mock.MagicMock() card._next_card(0.1) assert card.screen_manager.current == "AnotherCard"
def test_card_form_value_multichoice(): """ Return the current value of the multichoice widget. """ card = Card( "title", form=Inputs.MULTICHOICE, text="Form label...", options=["foo", "bar", "baz"], ) mock_screen_manager = mock.MagicMock() data_store = {} card.screen(mock_screen_manager, data_store) card.multichoice[0].state = "down" card.multichoice[2].state = "down" assert card.form_value() == ["foo", "baz"]
def test_card_form_value_no_form(): """ Must return None if there is no form associated with the card. """ card = Card("title") assert card.form_value() is None