#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Automated tests for DTM/DIM model
"""


import logging
import gensim
import os
import unittest
from gensim import corpora
from gensim import utils


# needed because sample data files are located in the same folder
module_path = os.path.dirname(__file__)
datapath = lambda fname: os.path.join(module_path, 'test_data', fname)


def testfile():
    # temporary data will be stored to this file
    return os.path.join(tempfile.gettempdir(), 'gensim_dtm.tst')


class DTMcorpus(corpora.textcorpus.TextCorpus):
    def get_texts(self):
        return self.input

    def __len__(self):
        return len(self.input)

class TestDtmModel(unittest.TestCase):
    def setUp(self):
        self.corpus, self.time_seq = utils.unpickle(datapath('dtm_test'))
        # first you need to setup the environment variable for the dtm binary
        dtm_home = os.environ.get('DTM_HOME', "C:/Users/Artyom/SkyDrive/TopicModels/dtm-master/")
        self.dtm_path = os.path.join(dtm_home, 'bin', 'dtm') if dtm_home else None

    def testDtm(self):
        model = gensim.models.DtmModel(self.dtm_path, self.corpus, self.time_seq, num_topics=2, id2word=self.corpus.dictionary, model='dtm', initialize_lda=True)
        topics = model.show_topics(topics=2, times=2, topn=10)

    def testDim(self):
        model = gensim.models.DtmModel(self.dtm_path, self.corpus, self.time_seq, num_topics=2, id2word=self.corpus.dictionary, model='fixed', initialize_lda=True)
        topics = model.show_topics(topics=2, times=2, topn=10)


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    unittest.main()

@@ -170,33 +170,8 @@
 ora%0A
-from gensim import utils%0A
 %0A%0A# 
@@ -351,196 +351,56 @@
 )%0A%0A%0A
-def testfile():%0A    # temporary data will be stored to this file%0A    return os.path.join(tempfile.gettempdir(), 'gensim_dtm.tst')%0A%0A%0Aclass DTMcorpus(corpora.textcorpus.TextCorpus
+class TestDtmModel(unittest.TestCase
 ):%0A
+%0A
     def 
 get_
@@ -399,17 +399,13 @@
 def 
-get_texts
+setUp
 (sel
@@ -420,193 +420,153 @@
     
-return self.input%0A%0A    def __len__(self):%0A        return len(self.input)%0A%0Aclass TestDtmModel(unittest.TestCase):%0A    def setUp(self):%0A        self.corpus, self.time_seq = utils.unpickle
+self.time_slices = %5B3, 7%5D%0A        self.corpus = corpora.mmcorpus.MmCorpus(datapath('dtm_test.mm'))%0A        self.id2word = corpora.Dictionary.load
 (dat
@@ -580,16 +580,21 @@
 dtm_test
+.dict
 '))%0A    
@@ -648,16 +648,26 @@
 ariable 
+$DTM_PATH 
 for the 
@@ -674,111 +674,79 @@
 dtm 
-binary%0A        dtm_home = os.environ.get('DTM_HOME', %22C:/Users/Artyom/SkyDrive/TopicModels/dtm-master/%22
+executable file%0A        self.dtm_path = os.environ.get('DTM_PATH', None
 )%0A  
@@ -743,32 +743,35 @@
 , None)%0A        
+if 
 self.dtm_path = 
@@ -772,68 +772,79 @@
 ath 
-= os.path.join(dtm_home, 'bin', 'dtm') if dtm_home else None
+is None:%0A            self.skipTest(%22$DTM_PATH is not properly set up.%22)
 %0A%0A  
@@ -934,34 +934,37 @@
 pus, self.time_s
-eq
+lices
 , num_topics=2, 
@@ -976,33 +976,23 @@
 rd=self.
-corpus.dictionary
+id2word
 , model=
@@ -1188,10 +1188,13 @@
 me_s
-eq
+lices
 , nu
@@ -1222,25 +1222,15 @@
 elf.
-corpus.dictionary
+id2word
 , mo

change test codes for dtm model