Пример #1
0
    def test_normal_tweet(self):
        """ Test extract_hashtags with a normal tweet including 
        two identical hashtags. """

        actual_hashtags = tweets.extract_hashtags('Go vote! #MAGA, #MAGA')
        expected_hashtags = ['MAGA']
        self.assertEqual(actual_hashtags, expected_hashtags, 'normal tweet')
 def test_hashtags_with_punctuation(self):
     """ Test extract_hashtags with a tweet with hashtag with punctuation. """
     
     actual_hashtags = tweets.extract_hashtags('#CSC148, #CSC108')
     expected_hashtags = ['CSC148', 'CSC108']
     self.assertEqual(actual_hashtags, expected_hashtags, 
                      ['CSC148', 'CSC108'])  
Пример #3
0
    def test_all_hashtags(self):
        """ Test extract_hashtags with a tweet of nothing but hashtags. """

        actual_hashtags = tweets.extract_hashtags(
            '#MAGA #Vote2016 #FeelTheBern')
        expected_hashtags = ['MAGA', 'Vote2016', 'FeelTheBern']
        self.assertEqual(actual_hashtags, expected_hashtags, 'only hashtags')
    def test_hashtags_with_space(self):
        """ Test extract_hashtags with a tweet with hashtag with space. """

        actual_hashtags = tweets.extract_hashtags('#CSC148 #CSC108')
        expected_hashtags = ['CSC148', 'CSC108']
        self.assertEqual(actual_hashtags, expected_hashtags, 
                         ['CSC148', 'CSC108'])
Пример #5
0
    def test_abnormal_tweet(self):
        """ Test extract_hashtags with a poorly formatted tweet including
        multiple poorly formatted hashtags. """

        actual_hashtags = tweets.extract_hashtags(
            '#MAGA abcd #abc@aa@#abcd^^^')
        expected_hashtags = ['MAGA', 'abc', 'abcd']
        self.assertEqual(actual_hashtags, expected_hashtags, 'abnormal tweet')
Пример #6
0
# tweets.extract_mentions
result = tweets.extract_mentions(
    '@AndreaTantaros Statement Regarding British Referendum on E.U. Membership'
)
assert isinstance(result, list), \
    '''tweets.extract_mentions should return a list, but returned {0}\n'''.format(type(result))
try:
    assert isinstance(result[0], str), \
        '''tweets.extract_mentions should return a list of strings, but the first item of the list returned was a {0}
        '''.format(type(result[0]))
except IndexError:
    assert False, \
      '''The list returned by extract_hashtags was empty and should have contained data.\n'''

# tweets.extract_hashtags
result = tweets.extract_hashtags(
    'Statement Regarding British Referendum on E.U. Membership #DemsInPhilly')
assert isinstance(result, list), \
    '''tweets.extract_hashtags should return a list, but returned {0}\n'''.format(type(result))
try:
    assert isinstance(result[0], str), \
        '''tweets.extract_hashtags should return a list of strings, but the first item of the list returned was a {0}
        '''.format(type(result[0]))
except IndexError:
    assert False, \
        '''The list returned by extract_hashtags was empty and should have contained data.\n'''

# tweets.count_words
word_d = {'statement': 1, 'regarding': 1}
result = tweets.count_words('Statement Regarding British Referendum', word_d)
assert isinstance(result, type(None)), \
    '''tweets.count_words should return None, but returned {0}\n'''.format(type(result))
Пример #7
0
    '#UofT Prof @ArvindUofT co-authors a '
    'report on retraining mid-career workers for #tech '
    'https://t.co/L80Ch8FUQb (via @ConversationCA)')
assert isinstance(result, list), \
    '''tweets.extract_mentions should return a list, but returned {0}\n'''.format(type(result))
try:
    assert isinstance(result[0], str), \
        '''tweets.extract_mentions should return a list of strings, but the first item of the list returned was a {0}
        '''.format(type(result[0]))
except IndexError:
    assert False, \
      '''The list returned by extract_mentions was empty and should have contained data.\n'''

# tweets.extract_hashtags
result = tweets.extract_hashtags(
    '#UofT Prof @ArvindUofT co-authors a report'
    'report on retraining mid-career workers for #tech '
    'https://t.co/L80Ch8FUQb (via @ConversationCA)')
assert isinstance(result, list), \
    '''tweets.extract_hashtags should return a list, but returned {0}\n'''.format(type(result))
try:
    assert isinstance(result[0], str), \
        '''tweets.extract_hashtags should return a list of strings, but the first item of the list returned was a {0}
        '''.format(type(result[0]))
except IndexError:
    assert False, \
        '''The list returned by extract_hashtags was empty and should have contained data.\n'''

# tweets.count_words
word_d = {'computer': 1, 'day': 1}
result = tweets.count_words(
    "#UofT researcher by day, singer @goodkidband by night", word_d)
    def test_no_hashtags(self):
        """ Test extract_hashtags with a tweet with no hashtags. """

        actual_hashtags = tweets.extract_hashtags('this is a tweet!')
        expected_hashtags = []
        self.assertEqual(actual_hashtags, expected_hashtags, 'empty list')
 def test_repeated_hashtags(self):
     """ Test extract_hashtags with a tweet with repeated hashtags. """
     
     actual_hashtags = tweets.extract_hashtags('#Life #keep, #Life!')
     expected_hashtags = ['life', 'keep']
     self.assertEqual(actual_hashtags, expected_hashtags, 'unique hashtags') 
 def test_unique_hashtags(self):
     """ Test extract_hashtags with a tweet with unique hashtags. """
     
     actual_hashtags = tweets.extract_hashtags('#Life #keep #hi-')
     expected_hashtags = ['life', 'keep', 'hi']
     self.assertEqual(actual_hashtags, expected_hashtags, 'many hashtags')
 def test_hashtags_with_normal_tweet(self):
     """ Test extract_hashtags with a normal tweet with hashtag. """
     
     actual_hashtags = tweets.extract_hashtags('While Hillary profits off the rigged system, I am fighting for you! Remember the simple phrase: #FollowTheMoney... https://t.co/8mVInc82E9')
     expected_hashtags = ['FollowTheMoney']
     self.assertEqual(actual_hashtags, expected_hashtags, ['FollowTheMoney'])       
 def test_same_hashtags(self):
     """ Test extract_hashtags with a tweet with same hashtags. """
     
     actual_hashtags = tweets.extract_hashtags('#CSC108, #CSC108')
     expected_hashtags = ['CSC108']
     self.assertEqual(actual_hashtags, expected_hashtags, ['CSC108'])
 def test_end_hashtags(self):
     """ Test extract_hashtags with a tweet with hashtag at the end. """
     
     actual_hashtags = tweets.extract_hashtags('I LOVE #CSC108')
     expected_hashtags = ['CSC108']
     self.assertEqual(actual_hashtags, expected_hashtags, ['CSC108'])
    def test_middle_hashtags(self):
        """ Test extract_hashtags with a tweet with hashtag at the middle. """

        actual_hashtags = tweets.extract_hashtags('Love #CSC108 forever')
        expected_hashtags = ['CSC108']
        self.assertEqual(actual_hashtags, expected_hashtags, ['CSC108'])
    def test_beginning_hashtags(self):
        """ Test extract_hashtags with a tweet with hashtag at the beginning. """

        actual_hashtags = tweets.extract_hashtags('#CSC108')
        expected_hashtags = ['CSC108']
        self.assertEqual(actual_hashtags, expected_hashtags, ['CSC108'])
    def test_only_hashtags(self):
        """ Test extract_hashtags with a tweet with only hashtag. """

        actual_hashtags = tweets.extract_hashtags('###')
        expected_hashtags = ['']
        self.assertEqual(actual_hashtags, expected_hashtags, [''])