当前位置: 首页>>代码示例>>Python>>正文


Python Collector.has_feed方法代码示例

本文整理汇总了Python中collector.Collector.has_feed方法的典型用法代码示例。如果您正苦于以下问题:Python Collector.has_feed方法的具体用法?Python Collector.has_feed怎么用?Python Collector.has_feed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在collector.Collector的用法示例。


在下文中一共展示了Collector.has_feed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestManager

# 需要导入模块: from collector import Collector [as 别名]
# 或者: from collector.Collector import has_feed [as 别名]
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
开发者ID:damiendev,项目名称:RSS-Intelligence,代码行数:84,代码来源:test.py

示例2: TestCollector

# 需要导入模块: from collector import Collector [as 别名]
# 或者: from collector.Collector import has_feed [as 别名]
class TestCollector(unittest.TestCase):
    """ Tests the Collector class.

    """
    def setUp(self):
        self.co = Collector()
        self.feed_info = Manager.get_feeds_info()

    def tearDown(self):
        rm_data_dir()

    def test_add_feed(self):
        """ Tests add_feed.

        Add feeds with "add_feed":
         1- Test if the feeds has been added.
         2- Test if the feeds exists in the database.

        Try adding a feed already added: 
         3- Test if the feed has not been added.

        """
        for name, url, tag, _ in self.feed_info:
            feed = self.co.add_feed(name, url, tag)
            self.assertIsNotNone(feed) # 1
            self.assertTrue(self.co.has_feed(name)) # 2

        name, url, tag = self.feed_info[0][:3]
        feed = self.co.add_feed(name, url, tag)
        self.assertIsNone(feed) # 3

    def test_update_feed(self):
        """ Tests update_feed.

        Add feeds.

        Try updating feed with "update_feed":
         1- Test if the feed doesn't need to be updated.

        #TODO
        Find a way to update a feed in the test.

        """
        for name, url, tag, _ in self.feed_info:
            self.co.add_feed(name, url, tag)

            updated = self.co.update_feed(name)
            self.assertFalse(updated) # 1

    def test_rm_feed(self):
        """ Tests rm_feed.

        Add feeds:
         1- Test if the feeds exists first.

        Remove feeds with "rm_feed".
         2- Test if the feeds has been removed.

        """
        for name, url, tag, _ in self.feed_info:
            self.co.add_feed(name, url, tag)

            self.assertTrue(self.co.has_feed(name)) # 1
            self.co.rm_feed(name)
            self.assertFalse(self.co.has_feed(name)) # 2

    def test_update_item_tag(self):
        """ Tests update_item_tag.

        Add a feed:
         1- Test if an item has not the tag attribute.

        Add a category with "update_item_tag".
         2- Test if the item updated is the same with the id.
         3- Test if the item updated has the tag attribute. 
         4- Test if the item updated has the correct category.

        """
        category = "SPORT"

        name, url, tag = self.feed_info[0][:3]
        feed = self.co.add_feed(name, url, tag)
        item_id, item = self.co.get_items(name).next()
        self.assertFalse(hasattr(item, "tag")) # 1

        self.co.update_item_tag(feed.item_db_filename, item_id, category)
        item_id_updated, item_updated = self.co.get_items(name).next()

        self.assertEquals(item_id, item_id_updated) # 2
        self.assertTrue(hasattr(item_updated, "tag")) # 3
        self.assertEquals(item_updated.tag, category) # 4

    def test_has_feed(self):
        """ Tests has_feed.

        Verify with "has_feed" if the feed exists.
         1- The feed doesn't exists.

        Add a feed.

#.........这里部分代码省略.........
开发者ID:damiendev,项目名称:RSS-Intelligence,代码行数:103,代码来源:test.py


注:本文中的collector.Collector.has_feed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。