本文整理汇总了Python中feed.Feed.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Feed.to_dict方法的具体用法?Python Feed.to_dict怎么用?Python Feed.to_dict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类feed.Feed
的用法示例。
在下文中一共展示了Feed.to_dict方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestFeed
# 需要导入模块: from feed import Feed [as 别名]
# 或者: from feed.Feed import to_dict [as 别名]
class TestFeed(unittest.TestCase):
def setUp(self):
self.feed = Feed('name_here', 'uri_here')
def tearDown(self):
self.feed = None
def test_lock(self):
self.assertIsNotNone(self.feed.lock)
self.feed.lock.acquire(blocking=False)
self.feed.lock.release()
def test_from_dict(self):
example_name = 'Name here'
example_uri = 'URI here'
attribute_dict = {'name': example_name, 'uri': example_uri}
f = Feed.from_dict(attribute_dict)
self.assertEquals(f.name, example_name)
self.assertEquals(f.uri, example_uri)
# Unsupported attributes should just be ignored
invalid = 'invalid'
attribute_dict[invalid] = 'better not show up'
f = Feed.from_dict(attribute_dict)
with self.assertRaises(AttributeError):
f.invalid
attribute_dict.pop(invalid)
# Missing attributes should trigger an error
attribute_dict.pop('name')
with self.assertRaises(RuntimeError):
Feed.from_dict(attribute_dict)
def test_to_dict(self):
d = self.feed.to_dict()
self.assertEquals(d['name'], self.feed.name)
self.assertEquals(d['uri'], self.feed.uri)
# The items attribute should not be written out
with self.assertRaises(KeyError):
d['items']