Exemplo n.º 1
0
class TestManager(unittest.TestCase):
    """ Tests the Manager class.

    """
    def setUp(self):
        self.co = Collector()
        self.c = Classifier(CleanTextUtil("french"))
        self.m = Manager(self.co, self.c)
        self.feeds_info = Manager.get_feeds_info()

    def tearDown(self):
        rm_data_dir()

    def test_add_feeds(self):
        """ Tests add_feeds.

        Add feeds.

        For each item with get_feeds_info:
         1- Check if the feed has been added.

        """
        self.m.add_feeds()

        for name, _, _, _ in self.feeds_info:
            self.assertTrue(self.co.has_feed(name)) # 1

    def test_add_texts_vectors(self):
        """ Tests add_texts_vectors.

        Add feeds.
        Add texts vectors:
         1- Check if the dictionary is not empty.
         2- Check if the number of text equals to feeds info.

        """
        self.m.add_feeds()
        self.m.add_texts_vectors()

        self.assertNotEquals(len(self.c.dictionary_db), 0) # 1

        size = len([_ for _, _, _, _ in self.feeds_info])
        self.assertEquals(int(self.c.classifier_state_db.get("text_nb")), size) # 2

    def test_add_general_feed(self):
#TODO
        """ Test .

        """
        pass

    def test_remove_feed(self):
        """ Tests remove_feed .

        Add feeds.
        Add texts vectors:
         1- Check if a feed exists.
         2- Check if a vector exists.

        Remove a feed.
         3- Check if the feed has been removed.
         4- Check if the vector doesn't exist anymore.

        """
        name = self.feeds_info[0][0]
        self.m.add_feeds()
        self.m.add_texts_vectors()

        self.assertTrue(self.co.has_feed(name)) # 1
        self.assertIsNotNone(self.c.get_vector(name)) # 2

        self.m.remove_feed(name)

        self.assertFalse(self.co.has_feed(name)) # 3
        self.assertIsNone(self.c.get_vector(name)) # 4

    def test_get_feeds_info(self):
#TODO
        """ Test .

        """
        pass
Exemplo n.º 2
0
    from collector import Collector, Feed, Item
    from classifier import Classifier, CleanTextUtil, WordInfo, Vector, VectorItem
    from manager import Manager
    import random

    ## uncomment this line to reset the index dir
    #reset() 

    c = Collector()
    indexer = Indexer(c)

    ## populate the indexer with feeds
    # Download feeds first 
    manager = Manager(c, Classifier(CleanTextUtil("english")))
    manager.add_feeds()

    #
    # Next, index feeds
    indexer.add_feeds()
    ##

    # print to help for the search
    def print_random_feed_items_test():
        feeds = Manager.get_feeds_info()
        name, _,_,_, = random.choice(feeds)
        c.print_items(name)

    print_random_feed_items_test()

    ##  active interactive prompt