def test_saving_changes(self): reaction = Reaction() reference = Reference() model = Model() evidence = Evidence(entity=reaction) evidence.add_reference(reference) widget = EvidenceDisplayWidget() model.all_evidences[evidence.internal_id] = evidence assert evidence in reaction.evidences assert evidence.internal_id in model.all_evidences assert reference in evidence.references # Set reaction and model to widget widget.set_item(reaction, model) assert widget.dataTable.rowCount() == 1 # Remove evidence copy from data table widget.dataTable.setRowCount(0) # Setup new evidence item new_evidence = Evidence() new_evidence.assertion = "Catalyzed by" new_evidence.entity = reaction reference = Reference() new_evidence.add_reference(reference, reciprocal=False) # Test the setup i.e. that items are only linked in a one way (evidence -> item) fashion assert new_evidence not in reaction.evidences assert new_evidence not in reference.linked_items # Add new reference to widget table widget.dataTable.update_row_from_item(new_evidence) assert widget.dataTable.rowCount() == 1 assert widget.dataTable.item(0).link is new_evidence # Action - Save evidences widget.save_state() # Check that old instance is detached from all links assert evidence not in reaction.evidences assert len(evidence.references) == 0 # Old evidence still kept alive by this test old_id = evidence.internal_id assert old_id in model.all_evidences evidence = None gc.collect() assert old_id not in model.all_evidences # Check that new evidence is linked properly assert new_evidence in reaction.evidences assert new_evidence.internal_id in model.all_evidences
def test_setup_links(self): entity = Reaction() target = Gene() eco = "ECO:000000" assertion = "Presence" comment = "test comment" reference = Reference() evidence = Evidence() evidence.entity = entity evidence.target = target evidence.eco = eco evidence.assertion = assertion evidence.comment = comment evidence.add_reference(reference, reciprocal=False) assert evidence not in entity.evidences assert evidence not in reference.linked_items assert evidence not in target.evidences evidence.setup_links() assert evidence in entity.evidences assert evidence in reference.linked_items assert evidence in target.evidences