def test_saving_changes(self): widget = ReactionAttributesDisplayWidget() reaction = Reaction("r1") model = Model("id") model.add_reactions((reaction, )) widget.set_item(reaction, model) new_id = "New id" new_name = "New name" new_subsytem = "New Subsystem" new_upper_bound = 200.5 new_lower_bound = -300.5 new_obj_coefficient = 20.4 widget.idLineEdit.setText(new_id) widget.nameLineEdit.setText(new_name) widget.subsystemLineEdit.setText(new_subsytem) widget.upperBoundInput.setValue(new_upper_bound) widget.lowerBoundInput.setValue(new_lower_bound) widget.objectiveCoefficientInput.setValue(new_obj_coefficient) # Action widget.save_state() # Check that inputs are saved assert reaction.id == new_id assert reaction.name == new_name assert reaction.subsystem == new_subsytem assert reaction.lower_bound == new_lower_bound assert reaction.upper_bound == new_upper_bound assert reaction.objective_coefficient == new_obj_coefficient
def test_setting_reaction(self): widget = ReactionAttributesDisplayWidget() reaction = Reaction(id="id", name="name", subsystem="subsystem", lower_bound=-1000., upper_bound=1000.) model = Model() model.add_reactions((reaction, )) reaction.objective_coefficient = 1. assert widget.idLineEdit.text() == "" assert widget.nameLineEdit.text() == "" assert widget.subsystemLineEdit.text() == "" assert widget.lowerBoundInput.value() == 0. assert widget.upperBoundInput.value() == 0. assert widget.objectiveCoefficientInput.value() == 0. assert widget.content_changed is False assert widget.valid_inputs() is False widget.set_item(reaction, model) assert widget.idLineEdit.text() == reaction.id assert widget.nameLineEdit.text() == reaction.name assert widget.subsystemLineEdit.text() == reaction.subsystem assert widget.lowerBoundInput.value() == reaction.lower_bound assert widget.upperBoundInput.value() == reaction.upper_bound assert widget.objectiveCoefficientInput.value( ) == reaction.objective_coefficient assert widget.content_changed is False assert widget.valid_inputs() is True
def test_valid_input(self): reaction = Reaction(id="test") model = Model() widget = ReactionAttributesDisplayWidget() widget.set_item(reaction, model) assert widget.valid_inputs() is True widget.idLineEdit.clear() assert widget.valid_inputs() is False
def test_reaction_enormous_bounds(self): widget = ReactionAttributesDisplayWidget() model = Model() reaction = Reaction(id="test", lower_bound=-999999, upper_bound=999999) widget.set_item(reaction, model) assert widget.lowerBoundInput.value() == -999999 assert widget.upperBoundInput.value() == 999999 assert widget.lowerBoundInput.minimum() == -999999 assert widget.upperBoundInput.maximum() == 999999
def test_setting_subsystem(self): widget = ReactionAttributesDisplayWidget() model = Model() reaction = Reaction(id="id") widget.set_item(reaction, model) assert widget.content_changed is False assert widget.valid_inputs() is True QtTest.QTest.keyClicks(widget.subsystemLineEdit, "Test") assert widget.content_changed is True assert widget.valid_inputs() is True
def test_standard_reaction_bounds(self): """ Check that bounds are set to standard values when the upper and lower bound are smaller""" widget = ReactionAttributesDisplayWidget() model = Model() reaction = Reaction(lower_bound=-500, upper_bound=100) widget.set_item(reaction, model) assert widget.lowerBoundInput.value() == -500 assert widget.lowerBoundInput.maximum() == 100. assert widget.lowerBoundInput.minimum() == -1000. assert widget.upperBoundInput.value() == 100 assert widget.upperBoundInput.maximum() == 1000. assert widget.upperBoundInput.minimum() == -500.
def test_setting_objective_value(self): widget = ReactionAttributesDisplayWidget() model = Model() reaction = Reaction(id="test") model.add_reactions((reaction, )) widget.set_item(reaction, model) new_value = 1. assert reaction.objective_coefficient != new_value widget.objectiveCoefficientInput.clear() QtTest.QTest.keyClicks(widget.objectiveCoefficientInput, str(new_value)) assert widget.objectiveCoefficientInput.value() == new_value assert widget.content_changed is True assert widget.valid_inputs() is True
def test_setting_lower_bound(self): widget = ReactionAttributesDisplayWidget() model = Model() reaction = Reaction(id="test") widget.set_item(reaction, model) current_max = widget.lowerBoundInput.maximum() current_min = widget.lowerBoundInput.minimum() current_max_upper = widget.upperBoundInput.maximum() widget.lowerBoundInput.clear() QtTest.QTest.keyClicks(widget.lowerBoundInput, "-2000") assert widget.lowerBoundInput.value() == -200. assert widget.upperBoundInput.minimum() == -200. assert widget.lowerBoundInput.maximum() == current_max assert widget.lowerBoundInput.minimum() == current_min assert widget.upperBoundInput.maximum() == current_max_upper
def test_setting_upper_bound(self): widget = ReactionAttributesDisplayWidget() model = Model() reaction = Reaction(id="test") widget.set_item(reaction, model) # Clear input first as spinbox is already at max current_max = widget.upperBoundInput.maximum() current_min = widget.upperBoundInput.minimum() current_min_lower = widget.lowerBoundInput.minimum() widget.upperBoundInput.clear() QtTest.QTest.keyClicks(widget.upperBoundInput, "500") assert widget.upperBoundInput.value() == 500 assert widget.lowerBoundInput.maximum() == 500. assert widget.upperBoundInput.maximum() == current_max assert widget.upperBoundInput.minimum() == current_min assert widget.lowerBoundInput.minimum() == current_min_lower