def test_color_proper_rows(self):
        """Rows are colored corresponding to the document"""
        model = ConcordanceModel()
        model.set_width(2)
        model.set_corpus(self.corpus)
        model.set_word("of", DummyState)

        color1 = model.data(model.index(0, 0), Qt.BackgroundRole)
        self.assertEqual(model.data(model.index(1, 0), Qt.BackgroundRole),
                         color1)
        self.assertNotEqual(model.data(model.index(2, 0), Qt.BackgroundRole),
                            color1)
    def test_color_proper_rows(self):
        """Rows are colored corresponding to the document"""
        model = ConcordanceModel()
        model.set_width(2)
        model.set_corpus(self.corpus)
        model.set_word("of")

        color1 = model.data(model.index(0, 0), Qt.BackgroundRole)
        self.assertEqual(model.data(model.index(1, 0), Qt.BackgroundRole),
                         color1)
        self.assertNotEqual(model.data(model.index(2, 0), Qt.BackgroundRole),
                            color1)
    def test_data(self):
        """data returns proper text to display"""
        model = ConcordanceModel()
        model.set_width(2)
        self.assertEqual(model.rowCount(QModelIndex()), 0)

        model.set_corpus(self.corpus)
        model.set_word("of", DummyState)

        # The same document in two rows
        self.assertEqual(model.rowCount(QModelIndex()), 7)
        self.assertEqual(model.data(model.index(0, 0)), "A survey")
        self.assertEqual(model.data(model.index(0, 1)), "of")
        self.assertEqual(model.data(model.index(0, 2)), "user opinion")

        self.assertEqual(model.data(model.index(1, 0)), "user opinion")
        self.assertEqual(model.data(model.index(1, 1)), "of")
        self.assertEqual(model.data(model.index(1, 2)), "computer system")

        # The third column has just a single word
        self.assertEqual(model.data(model.index(2, 0)), "engineering testing")
        self.assertEqual(model.data(model.index(2, 1)), "of")
        self.assertEqual(model.data(model.index(2, 2)), "EPS")

        # The first column has just a single word
        self.assertEqual(model.data(model.index(3, 0)), "Relation")
        self.assertEqual(model.data(model.index(3, 1)), "of")
        self.assertEqual(model.data(model.index(3, 2)), "user perceived")
    def test_data(self):
        """data returns proper text to display"""
        model = ConcordanceModel()
        model.set_width(2)
        self.assertEqual(model.rowCount(QModelIndex()), 0)

        model.set_corpus(self.corpus)
        model.set_word("of")

        # The same document in two rows
        self.assertEqual(model.rowCount(QModelIndex()), 7)
        self.assertEqual(model.data(model.index(0, 0)), "A survey")
        self.assertEqual(model.data(model.index(0, 1)), "of")
        self.assertEqual(model.data(model.index(0, 2)), "user opinion")

        self.assertEqual(model.data(model.index(1, 0)), "user opinion")
        self.assertEqual(model.data(model.index(1, 1)), "of")
        self.assertEqual(model.data(model.index(1, 2)), "computer system")

        # The third column has just a single word
        self.assertEqual(model.data(model.index(2, 0)), "engineering testing")
        self.assertEqual(model.data(model.index(2, 1)), "of")
        self.assertEqual(model.data(model.index(2, 2)), "EPS")

        # The first column has just a single word
        self.assertEqual(model.data(model.index(3, 0)), "Relation")
        self.assertEqual(model.data(model.index(3, 1)), "of")
        self.assertEqual(model.data(model.index(3, 2)), "user perceived")
    def test_set_word(self):
        """Concondance.set_word resets the indices"""
        # Human machine interface for lab abc computer applications
        model = ConcordanceModel()
        model.set_corpus(self.corpus)
        model.set_width(2)

        model.set_word("of", DummyState)
        self.assertEqual(model.rowCount(QModelIndex()), 7)
        self.assertEqual(model.data(model.index(0, 0)), "A survey")

        model.set_word("lab", DummyState)
        self.assertEqual(model.rowCount(QModelIndex()), 1)
        self.assertEqual(model.data(model.index(0, 0)), "interface for")

        model.set_word(None, DummyState)
        self.assertEqual(model.rowCount(QModelIndex()), 0)
    def test_set_word(self):
        """Concondance.set_word resets the indices"""
        # Human machine interface for lab abc computer applications
        model = ConcordanceModel()
        model.set_corpus(self.corpus)
        model.set_width(2)

        model.set_word("of")
        self.assertEqual(model.rowCount(QModelIndex()), 7)
        self.assertEqual(model.data(model.index(0, 0)), "A survey")

        model.set_word("lab")
        self.assertEqual(model.rowCount(QModelIndex()), 1)
        self.assertEqual(model.data(model.index(0, 0)), "interface for")

        model.set_word(None)
        self.assertEqual(model.rowCount(QModelIndex()), 0)
 def test_data_non_displayroles(self):
     """Other possibly implemented roles return correct types"""
     model = ConcordanceModel()
     model.set_corpus(self.corpus)
     model.set_word("of", DummyState)
     ind00 = model.index(0, 0)
     self.assertIsInstance(model.data(ind00, Qt.ForegroundRole),
                           (QBrush, type(None)))
     self.assertIsInstance(model.data(ind00, Qt.BackgroundRole),
                           (QColor, type(None)))
     self.assertIsInstance(model.data(ind00, Qt.TextAlignmentRole),
                           (Qt.Alignment, type(None)))
 def test_data_non_displayroles(self):
     """Other possibly implemented roles return correct types"""
     model = ConcordanceModel()
     model.set_corpus(self.corpus)
     model.set_word("of")
     ind00 = model.index(0, 0)
     self.assertIsInstance(model.data(ind00, Qt.ForegroundRole),
                           (QBrush, type(None)))
     self.assertIsInstance(model.data(ind00, Qt.BackgroundRole),
                           (QColor, type(None)))
     self.assertIsInstance(model.data(ind00, Qt.TextAlignmentRole),
                           (Qt.Alignment, type(None)))