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 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)
def testTwitterMarkovModel(self, *_): tm = TwitterMarkov('example_screen_name', self.corpus, config=self.configfile, dry_run=True, learn=False) assert isinstance(tm.models['tweets.txt'], markovify.text.Text)
def testTwitterMarkovListCorpus(self): tm = TwitterMarkov('example_screen_name', [self.corpus], config=self.configfile, dry_run=True, learn=False) assert isinstance(tm, TwitterMarkov) del tm
def testTwitterMarkovConfigCorpus(self): tm = TwitterMarkov('example_screen_name', config=self.configfile, dry_run=True, learn=False) tm.log.setLevel(100) del tm
def testTwitterMarkovAttribs(self): tm = TwitterMarkov('example_screen_name', self.corpus, config=self.configfile, dry_run=True, learn=False) tm.log.setLevel(100) assert isinstance(tm, TwitterMarkov) assert hasattr(tm, 'screen_name') assert hasattr(tm, 'api') assert hasattr(tm, 'config') assert hasattr(tm, 'wordfilter') del tm
state_sz = max(2, state_sz - 3) else: if (probability > 0.7): state_sz = max(2, state_sz - 2) else: if (probability > 0.6): state_sz = max(2, state_sz - 1) print 'state_sz is ' + str(state_sz) return state_sz #-- random.seed() tm = TwitterMarkov( 'example_screen_name', '/home/celesteh/Dropbox/debbie/gifs/twitter_markov/corpus.txt', config_file='/home/celesteh/Dropbox/debbie/gifs/twitter_markov/bots.yaml') dict = enchant.DictWithPWL("en_US", tm.config.get('dictionary_words')) #load dictionary gifs = tm.config.get('gifs') files = glob.glob((str(gifs) + '/out*.gif')) if len(files) < 15: if len(files) == 1: title = 'Last Gif' remain = 'This is the last tweet you can send.' else: title = 'Low Gifs' remain = 'There are only ' + str(len(files)) + ' gifs remianing.'
else: if(probability > 0.8): state_sz = max(2, state_sz -3) else: if(probability > 0.7): state_sz = max(2, state_sz -2) else: if (probability > 0.6): state_sz = max(2, state_sz -1) print 'state_sz is ' + str(state_sz) return state_sz #-- random.seed() tm = TwitterMarkov('example_screen_name', '/home/celesteh/Dropbox/debbie/gifs/twitter_markov/corpus.txt', config_file='/home/celesteh/Dropbox/debbie/gifs/twitter_markov/bots.yaml') dict = enchant.DictWithPWL("en_US",tm.config.get('dictionary_words')) #load dictionary gifs = tm.config.get('gifs') files = glob.glob((str(gifs) +'/out*.gif')) if len(files) < 15: if len(files) == 1: title = 'Last Gif' remain = 'This is the last tweet you can send.' else: title = 'Low Gifs' remain = 'There are only '+ str(len(files)) + ' gifs remianing.' print 'WARNING: make more gifs!\n' + remain