Exemplo n.º 1
0
    def test_couplet_urls(self):
	''' Tests that couplet returns poem and corresponding url '''
	couplet = generatePoem("#NationalPetDay", 'couplet')
	lines = couplet.split('\n')
	text0 = get_tweet_from_url(connect(), lines[2])
	text1 = get_tweet_from_url(connect(), lines[3])
	self.assertEqual(parse(text0)['line'], lines[0])
	self.assertEqual(parse(text1)['line'], lines[1])
Exemplo n.º 2
0
    def test_haiku_urls(self):
	''' Tests that haiku returns poem and corresponding url '''
	haiku = generatePoem("#NationalPetDay", 'haiku')
	lines = haiku.split('\n')
	text0 = get_tweet_from_url(connect(), lines[3])
	text1 = get_tweet_from_url(connect(), lines[4])
	text2 = get_tweet_from_url(connect(), lines[5])
	self.assertEqual(parse(text0)['line'], lines[0])
	self.assertEqual(parse(text1)['line'], lines[1])
	self.assertEqual(parse(text2)['line'], lines[2])
Exemplo n.º 3
0
    def test_same_syllables(self):
        ''' Tests that a couplet can be made with two lines w/ same # syllables  '''

        corpus = [parse('Well gosh, I hate the bay'), 
              parse('You must go there today!'),
              parse('some filler')]
        poem = couplet.couplet('couplet_test2')
        poem = [t.text for t in poem.tweets]
        print poem
        self.assertTrue((poem[0] == 'Well gosh, I hate the bay' and poem[1] == 'You must go there today!')
                     or (poem[1] == 'Well gosh, I hate the bay' and poem[0] == 'You must go there today!'))
Exemplo n.º 4
0
    def test_same_syllables(self):
        ''' Tests that a couplet can be made with two lines w/ same # syllables  '''

        corpus = [
            parse('Well gosh, I hate the bay'),
            parse('You must go there today!'),
            parse('some filler')
        ]
        poem = couplet.couplet('couplet_test2')
        poem = [t.text for t in poem.tweets]
        print poem
        self.assertTrue((poem[0] == 'Well gosh, I hate the bay'
                         and poem[1] == 'You must go there today!')
                        or (poem[1] == 'Well gosh, I hate the bay'
                            and poem[0] == 'You must go there today!'))
Exemplo n.º 5
0
 def test_invalid(self):
     ''' Tests that invalid lines are properly ignored '''
     while True:
         line = raw_input(r"Enter invalid line (or 'quit' to quit): ")
         if line == 'quit':
             return
         self.assertEqual(parse(line), {})
Exemplo n.º 6
0
 def test_valid(self):
     ''' Tests that valid lines are not ignored '''
     while True:
         line = raw_input(r"Enter valid line (or 'quit' to quit): ")
         if line == 'quit':
             return
         self.assertNotEqual(parse(line), {})
Exemplo n.º 7
0
    def test_parse_tweet_from_url(self):
	''' Tests that tweet from hashtag can be parsed to correct text '''
	tweets = get_fewer_tweets_from_hashtag(connect(), "#musicthatdontmatch")
	parsed_tweets = parse_all(tweets)
	tweet = parsed_tweets[0]
	text = get_tweet_from_url(connect(), tweet['url'])
	self.assertEqual(parse(text)['line'], tweet['line'])
 def test_invalid(self):
     """ Tests that invalid lines are properly ignored """
     while True:
         line = raw_input(r"Enter invalid line (or 'quit' to quit): ")
         if line == "quit":
             return
         self.assertEqual(parse(line), {})
 def test_valid(self):
     """ Tests that valid lines are not ignored """
     while True:
         line = raw_input(r"Enter valid line (or 'quit' to quit): ")
         if line == "quit":
             return
         self.assertNotEqual(parse(line), {})
Exemplo n.º 10
0
    def test_parse(self):
        ''' Test basic text is parsed correctly '''
        line1 = "hello i am dog"
        output = parse(line1)
        self.assertEqual(output['line'], 'hello i am dog')
        self.assertEqual(output['last_word'], 'dog')
        self.assertEqual(output['phone'], 'AO1G')
        self.assertEqual(output['syllables'], 5)
		
	def test_parse_nonalpha(self):
        ''' Tests that non-alphanumeric characters are ignored '''
		line1 = "hello i am dog!"
        output = parse(line1)
        self.assertEqual(output['line'], 'hello i am dog')
        self.assertEqual(output['last_word'], 'dog')
        self.assertEqual(output['phone'], 'AO1G')
        self.assertEqual(output['syllables'], 5)

	def test_bad_input(self):
        ''' Tests that nonenglish words are ignored '''
		line1 = "hello i am dg"
		output = parse(line1)
		self.assertEqual(output, {})
Exemplo n.º 11
0
 def test_emoji(self):
     ''' Tests that emoji are ignored '''
     line = r'dog \xf0\x9f\x98\x9f'
     output = parse(line)
     print output
     self.assertEqual(output, {'phone': 'AO1G', 'line': 'dog', 'syllables': 1, 'url':'', 'last_word':'dog'})
Exemplo n.º 12
0
	def test_bad_input(self):
        ''' Tests that nonenglish words are ignored '''
		line1 = "hello i am dg"
		output = parse(line1)
		self.assertEqual(output, {})