本文整理汇总了Python中models.Article.most_common_word方法的典型用法代码示例。如果您正苦于以下问题:Python Article.most_common_word方法的具体用法?Python Article.most_common_word怎么用?Python Article.most_common_word使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Article
的用法示例。
在下文中一共展示了Article.most_common_word方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ArticleTest
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import most_common_word [as 别名]
class ArticleTest(unittest.TestCase):
"""
Unit tests for the articles methods
"""
a = None
def setUp(self):
self.a = Article('Dummy title')
def test_load_story(self):
# mock the fetch with a local file
self.a.html = open(FILE_DIR + 'article_dummy.html', 'r')
self.a.load_story()
self.assertTrue(self.a.story)
@mock.patch('models.blwp')
def test_clean_story(self, mock_blwp):
mock_blwp.get_words.return_value = ['gaga', 'afterwards', 'wa']
self.a.story = 'afterwards you win';
self.a.clean_story()
mock_blwp.get_words.assert_called_with()
self.assertEquals(self.a.story, 'you win')
def test_most_used_word(self):
# mock story text
self.a.story = 'afterwards you win and win';
self.a.most_common_word()
self.assertEquals(self.a.most_used_word, 'win')
@mock.patch('models.twitter')
def test_load_related_tweets(self, mock_twitter):
mock_twitter.search.return_value = ['t1', 't2', 't3']
self.a.most_used_word = 'hashtag'
self.a.load_related_tweets()
mock_twitter.search.assert_called_with('hashtag')
self.assertEquals(len(self.a.tweets), 3)