本文整理匯總了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']