'''tweets.count_words should return None, but returned {0}\n'''.format(type(result))
assert len(word_d) == 4, \
    '''tweets.count_words should modify the argument dictionary\n'''

# tweets.common_words
word_d = {'statement': 10, 'regarding': 1}
result = tweets.common_words(word_d, 1)
assert isinstance(result, type(None)), \
    '''tweets.common_words should return None, but returned {0}\n'''.format(type(result))
assert len(word_d) == 1, \
    '''tweets.common_words should modify the argument dictionary'''

# tweets.read_tweets
try:
    tweet_file = open('short_data.txt')
    result = tweets.read_tweets(tweet_file)
    tweet_file.close()
    assert isinstance(result, dict), \
        '''tweets.read_tweets should return a dict, but returned {0}\n'''.format(type(result))
    key = list(result.keys())[0]
    assert isinstance(key, str), \
        '''tweets.read_tweets should contains strings as keys, but the key we checked was a {0}
        '''.format(type(key))
    assert isinstance(result[key], list), \
        '''tweets.read_tweets should contains lists as values, but the value we checked was a {0}
        '''.format(type(result[key]))
except FileNotFoundError:
    assert False, \
        '''The typechecker uses the data file 'short_data.txt'. 
        Please download it from the handout page, and make sure it is in the same directory as
        your tweets.py file and the typechecker.'''
Beispiel #2
0
assert isinstance(result, type(None)), \
    '''tweets.count_words should return None, but returned {0}\n'''.format(type(result))
assert len(word_d) == 6, \
    '''tweets.count_words should modify the argument dictionary {0}\n'''.format(word_d)

# tweets.common_words
word_d = {'statement': 10, 'regarding': 1}
result = tweets.common_words(word_d, 1)
assert isinstance(result, type(None)), \
    '''tweets.common_words should return None, but returned {0}\n'''.format(type(result))
assert len(word_d) == 1, \
    '''tweets.common_words should modify the argument dictionary'''

# tweets.read_tweets
try:
    result = tweets.read_tweets(TWEETS_FILE)
    assert isinstance(result, dict), \
        '''tweets.read_tweets should return a dict, but returned {0}\n'''.format(type(result))
    key = list(result.keys())[0]
    assert isinstance(key, str), \
        '''tweets.read_tweets should contains strings as keys, but the key we checked was a {0}
        '''.format(type(key))
    assert isinstance(result[key], list), \
        '''tweets.read_tweets should contains lists as values, but the value we checked was a {0}
        '''.format(type(result[key]))
except IndexError:
    assert False, \
        '''The dictionary returned by read_tweets was empty and should have contained data.\n'''

# tweets.most_popular
tweet_d = {key: value[:] for (key, value) in TWEETS_DICTIONARY.items()}