def test_csv_serialization(): csv_filename = get_temp_test_file_name('csv') tweets_collector = st.CollectorTweetOutput() get_tweets_to_tweet_output_test( [st.CsvTweetOutput(csv_filename), tweets_collector]) tweets_from_csv = st.read_tweets_from_csv_file(csv_filename) two_lists_assert_equal(tweets_from_csv, tweets_collector.get_raw_list())
def test_file_json_lines_serialization(): jl_filename = get_temp_test_file_name('jl') tweets_collector = st.CollectorTweetOutput() get_tweets_to_tweet_output_test( [st.JsonLineFileTweetOutput(jl_filename), tweets_collector]) tweets_from_jl = st.read_tweets_from_json_lines_file(jl_filename) two_lists_assert_equal(tweets_from_jl, tweets_collector.get_raw_list())
def test_tweet_csv_read_iterator(): file_name = get_temp_test_file_name('csv') collector = st.CollectorTweetOutput() get_tweets_to_tweet_output_test([collector, st.CsvTweetOutput(file_name)]) iterator = st.TweetCsvFileIterator(file_name, 4) list_from_iterator = [] iterator.open() while True: try: list_from_iterator.extend(next(iterator)) except StopIteration: break two_lists_assert_equal(list_from_iterator, collector.get_raw_list())
def test_user_json_lines_read_iterator(): file_name = get_temp_test_file_name('jl') collector = st.CollectorUserOutput() get_users_to_tweet_output_test([collector, st.JsonLineFileUserOutput(file_name)]) iterator = st.UserJsonLineFileIterator(file_name, 2) list_from_iterator = [] iterator.open() while True: try: list_from_iterator.extend(next(iterator)) except StopIteration: break iterator.close() two_lists_assert_equal(list_from_iterator, collector.get_scrapped_users())
def test_user_csv_serialization(): csv_filename = get_temp_test_file_name('csv') users = get_users() st.export_users_to_csv(users, csv_filename) imported_tweets = st.read_users_from_csv_file(csv_filename) two_lists_assert_equal(users, imported_tweets)
def test_user_json_lines_serialization(): jl_filename = get_temp_test_file_name('jl') users = get_users() st.export_users_to_json_lines(users, jl_filename) imported_tweets = st.read_users_from_json_lines_file(jl_filename) two_lists_assert_equal(imported_tweets, users)