本文整理匯總了Python中hackernews.HackerNews.get_user方法的典型用法代碼示例。如果您正苦於以下問題:Python HackerNews.get_user方法的具體用法?Python HackerNews.get_user怎麽用?Python HackerNews.get_user使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類hackernews.HackerNews
的用法示例。
在下文中一共展示了HackerNews.get_user方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestGetUser
# 需要導入模塊: from hackernews import HackerNews [as 別名]
# 或者: from hackernews.HackerNews import get_user [as 別名]
class TestGetUser(unittest.TestCase):
def setUp(self):
self.hn = HackerNews()
def test_get_user(self):
user = self.hn.get_user('pg')
self.assertIsInstance(user, User)
self.assertEqual(user.user_id, 'pg')
self.assertEqual(user.created,
datetime.datetime.fromtimestamp(1160418092))
self.assertEqual(repr(user), '<hackernews.User: pg>')
def test_get_invalid_user(self):
self.assertRaises(InvalidUserID, self.hn.get_user, 'a')
def test_get_user_expand(self):
user = self.hn.get_user('avinassh', expand=True)
self.assertIsInstance(user, User)
self.assertEqual(user.user_id, 'avinassh')
self.assertIsInstance(user.comments[0], Item)
self.assertIsInstance(user.stories[0], Item)
def tearDown(self):
self.hn.session.close()
示例2: TestGetUser
# 需要導入模塊: from hackernews import HackerNews [as 別名]
# 或者: from hackernews.HackerNews import get_user [as 別名]
class TestGetUser(unittest.TestCase):
def setUp(self):
self.hn = HackerNews()
def test_get_user(self):
user = self.hn.get_user('pg')
self.assertIsInstance(user, User)
self.assertEqual(user.user_id, 'pg')
self.assertEqual(user.created, datetime.datetime.fromtimestamp(1160418092))