old_contents: import unittest
  
  from orangecontrib.text.lda import LDA
  from orangecontrib.text.corpus import Corpus
  
  
  class LDATests(unittest.TestCase):
      corp = Corpus.from_file('deerwester')
      text = [d.split() for d in corp.documents]
      model = LDA(text, num_topics=5)
  
      def test_insert_topic_into_corpus(self):
          corp_topics = self.model.insert_topics_into_corpus(self.corp)
          self.assertEqual(len(corp_topics), len(self.corp))
          self.assertEqual(len(corp_topics.domain.attributes), 5)
          self.assertEqual(corp_topics.X.shape, (len(self.corp), 5))
  
      def test_get_topic_table_by_id(self):
          topic1 = self.model.get_topics_table_by_id(1)
          self.assertEqual(len(topic1), 45)
          self.assertEqual(topic1.metas.shape, (45, 2))
  
      def test_top_words_by_topic(self):
          words = self.model.get_top_words_by_id(1)
          self.assertEqual(len(words), 10)
  
      def test_too_large_id(self):
          with self.assertRaises(ValueError):
              self.model.get_topics_table_by_id(6)
  
new_contents: import unittest
  
  import numpy as np
  
  from Orange.data import Table
  from orangecontrib.text import vectorization
  from orangecontrib.text.topics import LdaWrapper, HdpWrapper, LsiWrapper
  from orangecontrib.text.corpus import Corpus
  
  
  class BaseTests:
      def test_fit_transform(self):
          topics = self.model.fit_transform(self.corpus)
          self.assertEqual(len(topics), len(self.corpus))
          # np.testing.assert_allclose(topics.X.sum(axis=1), np.ones(len(self.corpus)), rtol=.01)
          return topics
  
      def test_get_topic_table_by_id(self):
          self.model.fit(self.corpus)
          topic1 = self.model.get_topics_table_by_id(1)
          self.assertEqual(len(topic1), len(self.corpus.dictionary))
          self.assertEqual(topic1.metas.shape, (len(self.corpus.dictionary), 2))
          # self.assertAlmostEqual(topic1.W.sum(), 1.)
          self.assertFalse(any(topic1.W == np.nan))
  
      def test_top_words_by_topic(self):
          self.model.fit(self.corpus)
          words = self.model.get_top_words_by_id(1, num_of_words=10)
          self.assertTrue(all([isinstance(word, str) for word in words]))
          self.assertEqual(len(words), 10)
  
      def test_vectorized(self):
          corpus = vectorization.TfidfVectorizer().transform(self.corpus, copy=True)
          topics = self.model.fit_transform(corpus)
          self.assertIsInstance(topics, Table)
  
      def test_report_callback(self):
          prev_progress = -1
  
          def callback(progress):
              nonlocal prev_progress
              self.assertGreater(progress, prev_progress)
              prev_progress = progress
  
          self.model.fit(self.corpus, progress_callback=callback)
          self.assertLessEqual(prev_progress, 100)
  
  
  class LDATests(unittest.TestCase, BaseTests):
      def setUp(self):
          self.corpus = Corpus.from_file('deerwester')
          self.model = LdaWrapper(num_topics=5)
  
      def test_too_large_id(self):
          self.model.fit(self.corpus)
          with self.assertRaises(ValueError):
              self.model.get_topics_table_by_id(6)
  
      def test_fit_transform(self):
          topics = super().test_fit_transform()
          self.assertEqual(len(topics.domain.attributes), 5)
          self.assertEqual(topics.X.shape, (len(self.corpus), 5))
  
  
  class HdpTest(unittest.TestCase, BaseTests):
      def setUp(self):
          self.corpus = Corpus.from_file('deerwester')
          self.model = HdpWrapper()
  
  
  class LsiTest(unittest.TestCase, BaseTests):
      def setUp(self):
          self.corpus = Corpus.from_file('deerwester')
          self.model = LsiWrapper(num_topics=5)
  
subject: cover topics module with tests