def test_setting_item(self):
        parent = QWidget()
        widget = OutcomeDisplayWidget(parent)
        test = ModelTest()
        reaction = Reaction()
        outcome = Outcome(reaction, 0., "greater than")
        model = Model()

        test.add_outcome(outcome)

        widget.dataTable.populate_table = Mock()

        widget.set_item(test, model)

        widget.dataTable.populate_table.assert_called_once_with(test.outcomes)
        assert widget.model is model
        assert widget.model_test is test
    def test_modification_emits_changed(self):

        parent = QWidget()
        widget = OutcomeDisplayWidget(parent)
        test = ModelTest()
        reaction = Reaction()
        outcome = Outcome(reaction, 0., "greater than")
        model = Model()

        test.add_outcome(outcome)
        widget.set_item(test, model)

        detector = Mock()
        widget.changed.connect(detector.test)

        widget.dataTable.item(0, 1).setText("less than")
        assert detector.test.called is True
        assert widget.content_changed is True
    def test_addition_emits_changed(self):

        parent = QWidget()
        widget = OutcomeDisplayWidget(parent)
        test = ModelTest()
        reaction = Reaction()
        outcome = Outcome(reaction, 0., "greater than")
        model = Model()

        test.add_outcome(outcome)
        widget.set_item(test, model)

        detector = Mock()
        widget.changed.connect(detector.test)

        widget.dataTable.update_row_from_item(Outcome(Reaction()))
        assert detector.test.called is True
        assert widget.content_changed is True
    def test_deletion_emits_changed(self):

        parent = QWidget()
        widget = OutcomeDisplayWidget(parent)
        test = ModelTest()
        reaction = Reaction()
        outcome = Outcome(reaction, 0., "greater than")
        model = Model()

        test.add_outcome(outcome)
        widget.set_item(test, model)

        detector = Mock()
        widget.changed.connect(detector.test)

        widget.tableView.selectRow(0)
        QtTest.QTest.mouseClick(widget.button_del_item, QtCore.Qt.LeftButton)
        assert widget.dataTable.rowCount() == 0
        assert detector.test.called is True
        assert widget.content_changed is True
    def test_saving_items(self):

        parent = QWidget()
        widget = OutcomeDisplayWidget(parent)
        test = ModelTest()
        reaction = Reaction()
        outcome = Outcome(reaction, 0., "greater than")
        model = Model()

        test.add_outcome(outcome)
        widget.set_item(test, model)

        new_test = ModelTest()
        widget.model_test = new_test

        assert len(new_test.outcomes) == 0
        widget.save_state()
        assert len(new_test.outcomes) == 1

        new_setting = list(new_test.outcomes)[0]

        assert new_setting == outcome
        assert new_setting is not outcome