def testCheck(self): tm = TwitterMarkov('example_screen_name', [self.corpus], config=self.configfile, dry_run=True, learn=False) self.assertFalse(tm.check_tweet('😀' * 141)) self.assertFalse(tm.check_tweet('')) self.assertFalse(tm.check_tweet('contains the blacklisted word t**s'))
class tweeter_markov_tests(unittest.TestCase): @mock.patch.object(tweepy.API, 'user_timeline', return_value=fake_timeline()) def setUp(self, _): self.corpus = path.join(path.dirname(__file__), 'data', 'tweets.txt') self.configfile = path.join(path.dirname(__file__), '..', 'bots.yaml') self.tm = TwitterMarkov('example_screen_name', [self.corpus], config=self.configfile, dry_run=True, learn=False) self.tm.log.setLevel(100) def testCheckModels(self): for m in self.tm.models.values(): self.assertIsInstance(m, markovify.text.NewlineText) @mock.patch.object(tweepy.API, 'user_timeline', return_value=fake_timeline()) def testTwitterMarkovCompose(self, *_): response = self.tm.compose(tries=150, max_overlap_ratio=2, max_overlap_total=100) assert isinstance(response, basestring) assert len(response) < 140 @mock.patch.object(tweepy.API, 'mentions_timeline', return_value=fake_timeline()) @mock.patch.object(tweepy.API, 'user_timeline', return_value=fake_timeline()) def testTwitterMarkovReply(self, *_): r = self.tm.reply_all(tries=75, max_overlap_ratio=2, max_overlap_total=100) @mock.patch.object(tweepy.API, 'user_timeline', return_value=fake_timeline()) def testTwitterMarkovRecentlyTweeted(self, _): recents = self.tm.recently_tweeted assert recents[0] == TIMELINE[0]['text'] @mock.patch.object(tweepy.API, 'user_timeline', return_value=fake_timeline()) def testTwitterMarkovCheckTweet(self, _): assert self.tm.check_tweet('') is False assert self.tm.check_tweet('badword') is False assert self.tm.check_tweet('Lorem ipsum dolor sit amet') is False assert self.tm.check_tweet('Lorem ipsum dolor sit amet!') is False assert self.tm.check_tweet('Lorem ipsum dolor set namet') is False assert self.tm.check_tweet('Random Text that should work totally') is True assert self.tm.check_tweet('@reply Random Text') is True @mock.patch.object(tweepy.API, 'user_timeline', return_value=fake_timeline()) def testTwitterMarkovLearn(self, _): tmp = path.join(path.dirname(__file__), 'data', 'tmp.txt') self.tm.learn_parent(corpus=tmp) try: with open(tmp) as f: result = f.read() assert TIMELINE[0]['text'] in result assert TIMELINE[1]['text'] in result assert TIMELINE[2]['text'] in result finally: os.remove(tmp)
class tweeter_markov_tests(unittest.TestCase): @mock.patch.object(tweepy.API, 'user_timeline', return_value=fake_timeline()) def setUp(self, _): self.corpus = path.join(path.dirname(__file__), 'data', 'tweets.txt') self.configfile = path.join(path.dirname(__file__), '..', 'bots.yaml') self.tm = TwitterMarkov('example_screen_name', [self.corpus], config=self.configfile, dry_run=True, learn=False) self.tm.log.setLevel(100) @mock.patch.object(tweepy.API, 'user_timeline', return_value=fake_timeline()) def testTwitterMarkovCompose(self, *_): response = self.tm.compose(tries=150, max_overlap_ratio=2, max_overlap_total=100) assert isinstance(response, basestring) assert len(response) < 140 @mock.patch.object(tweepy.API, 'mentions_timeline', return_value=fake_timeline()) @mock.patch.object(tweepy.API, 'user_timeline', return_value=fake_timeline()) def testTwitterMarkovReply(self, *_): r = self.tm.reply_all(tries=75, max_overlap_ratio=2, max_overlap_total=100) @mock.patch.object(tweepy.API, 'user_timeline', return_value=fake_timeline()) def testTwitterMarkovRecentlyTweeted(self, _): recents = self.tm.recently_tweeted assert recents[0] == TIMELINE[0]['text'] @mock.patch.object(tweepy.API, 'user_timeline', return_value=fake_timeline()) def testTwitterMarkovCheckTweet(self, _): assert self.tm.check_tweet('') is False assert self.tm.check_tweet('badword') is False assert self.tm.check_tweet('Lorem ipsum dolor sit amet') is False assert self.tm.check_tweet('Lorem ipsum dolor sit amet!') is False assert self.tm.check_tweet('Lorem ipsum dolor set namet') is False assert self.tm.check_tweet('Random Text that should work totally') is True assert self.tm.check_tweet('@reply Random Text') is True @mock.patch.object(tweepy.API, 'user_timeline', return_value=fake_timeline()) def testTwitterMarkovLearn(self, _): tmp = path.join(path.dirname(__file__), 'data', 'tmp.txt') self.tm.learn_parent(corpus=tmp) try: with open(tmp) as f: result = f.read() assert TIMELINE[0]['text'] in result assert TIMELINE[1]['text'] in result assert TIMELINE[2]['text'] in result finally: os.remove(tmp)