def test_boolean_value(): p = BooleanParameter('Test') with pytest.raises(ValueError): v = p.value # not set p.value = 'a' # a string assert p.value == True p.value = 10 # a number assert p.value == True p.value = 0 # zero assert p.value == False p.value = True assert p.value == True
def test_setValue_should_update_value(self, qtbot, default_value): # set up BooleanInput bool_param = BooleanParameter('potato', default=default_value) bool_input = BooleanInput(bool_param) qtbot.addWidget(bool_input) bool_input.setValue(not default_value) assert bool_input.value() == (not default_value)
def test_init_from_param(self, qtbot, default_value): # set up BooleanInput bool_param = BooleanParameter('potato', default=default_value) bool_input = BooleanInput(bool_param) qtbot.addWidget(bool_input) # test assert bool_input.text() == bool_param.name assert bool_input.value() == default_value
def test_init_from_param(self, qtbot, default_value, value_remains_default): # set up BooleanInput bool_param = BooleanParameter('potato', default=default_value) if (value_remains_default): # Enable check that the value is initialized to default_value check_value = default_value else: # Set to a non default value bool_param.value = not default_value # Enable check that the value is changed after initialization to a non default value check_value = not default_value bool_input = BooleanInput(bool_param) qtbot.addWidget(bool_input) # test assert bool_input.text() == bool_param.name assert bool_input.value() == check_value
def test_leftclick_should_update_parameter(self, qtbot, default_value): # set up BooleanInput bool_param = BooleanParameter('potato', default=default_value) with mock.patch('test_inputs.BooleanParameter.value', new_callable=mock.PropertyMock, return_value=default_value) as p: bool_input = BooleanInput(bool_param) qtbot.addWidget(bool_input) bool_input.show() # TODO: fix: fails to toggle on Windows #qtbot.mouseClick(bool_input, QtCore.Qt.LeftButton) bool_input.setValue(not default_value) assert bool_input.value() == (not default_value) bool_input.parameter # lazy update p.assert_called_once_with(not default_value)
def test_boolean_value(): p = BooleanParameter('Test') with pytest.raises(ValueError): _ = p.value # not set with pytest.raises(ValueError): p.value = 'a' # a string with pytest.raises(ValueError): p.value = 10 # a number other than 0 or 1 p.value = "True" assert p.value is True p.value = "False" assert p.value is False p.value = "true" assert p.value is True p.value = "false" assert p.value is False p.value = 1 # a number assert p.value is True p.value = 0 # zero assert p.value is False p.value = True assert p.value is True