def test_setValue_within_range_should_set(self, qtbot): float_param = FloatParameter('potato', minimum=-10, maximum=10, default=0) sci_input = ScientificInput(float_param) qtbot.addWidget(sci_input) # test sci_input.setValue(5) assert sci_input.value() == 5
def test_setValue_out_of_range_should_constrain(self, qtbot): float_param = FloatParameter('potato', minimum=-1000, maximum=1000, default=0) sci_input = ScientificInput(float_param) qtbot.addWidget(sci_input) # test sci_input.setValue(1024) assert sci_input.value() == 1000 sci_input.setValue(-1024) assert sci_input.value() == -1000
def test_init_from_param(self, qtbot, min_, max_, default_value): float_param = FloatParameter('potato', minimum=min_, maximum=max_, default=default_value, units='m') sci_input = ScientificInput(float_param) qtbot.addWidget(sci_input) assert sci_input.minimum() == min_ assert sci_input.maximum() == max_ assert sci_input.value() == default_value assert sci_input.suffix() == ' m'
def test_setValue_should_update_param(self, qtbot): float_param = FloatParameter('potato', minimum=-1000, maximum=1000, default=10.0) sci_input = ScientificInput(float_param) qtbot.addWidget(sci_input) with mock.patch('test_inputs.FloatParameter.value', new_callable=mock.PropertyMock, return_value=10.0) as p: # test sci_input.setValue(5.0) sci_input.parameter # lazy update p.assert_called_once_with(5.0)
def test_setValue_within_range_should_set_regression_118(self, qtbot): float_param = FloatParameter('potato', minimum=-1000, maximum=1000, default=0) sci_input = ScientificInput(float_param) qtbot.addWidget(sci_input) # test - validate min/max beyond QDoubleSpinBox defaults # QDoubleSpinBox defaults are 0 to 99.9 - so test value >= 100 sci_input.setValue(999) assert sci_input.value() == 999 sci_input.setValue(-999) assert sci_input.value() == -999
def test_init_from_param(self, qtbot, min_, max_, default_value, value_remains_default): float_param = FloatParameter('potato', minimum=min_, maximum=max_, default=default_value, units='m') 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 float_param.value = min_ # Enable check that the value is changed after initialization to a non default value check_value = min_ sci_input = ScientificInput(float_param) qtbot.addWidget(sci_input) assert sci_input.minimum() == min_ assert sci_input.maximum() == max_ assert sci_input.value() == check_value assert sci_input.suffix() == ' m'