def test_message_number_bins_csv(self, mock_util): mock_util.correctLastCharCR.side_effect = util.load_from_disk( current_directory + "/data/message_number_bins_csv/correctLastCharCR") mock_util.correct_last_char_list.side_effect = util.load_from_disk( current_directory + "/data/message_number_bins_csv/correct_last_char_list") mock_util.rec_list_splice.side_effect = util.load_from_disk( current_directory + "/data/message_number_bins_csv/rec_list_splice") bin_matrix_ = util.load_from_disk( current_directory + "/data/message_number_bins_csv/bin_matrix") tot_msgs_ = util.load_from_disk( current_directory + "/data/message_number_bins_csv/tot_msgs") capturedOutput = StringIO.StringIO() sys.stdout = capturedOutput bin_matrix, tot_msgs = network.message_number_bins_csv( self.log_data, self.nicks, self.nick_same_list) sys.stdout = sys.__stdout__ capturedOutput.close() self.assertEqual(bin_matrix, bin_matrix_) self.assertEqual(tot_msgs, tot_msgs_)
def test_message_number_bins_csv(self, mock_rec_list, mock_correct_last_char_list, mock_correct_last_char_CR): mock_correct_last_char_CR.side_effect = util.load_from_disk( self.test_data_dir + "message_number_bins_csv/correctLastCharCR") mock_correct_last_char_list.side_effect = util.load_from_disk( self.test_data_dir + "message_number_bins_csv/correct_last_char_list") mock_rec_list.side_effect = util.load_from_disk( self.test_data_dir + "message_number_bins_csv/rec_list_splice") expected_bin_matrix = util.load_from_disk( self.test_data_dir + "message_number_bins_csv/bin_matrix") expected_tot_msgs = util.load_from_disk( self.test_data_dir + "message_number_bins_csv/tot_msgs") capturedOutput = StringIO.StringIO() sys.stdout = capturedOutput bin_matrix, tot_msgs = network.message_number_bins_csv( self.log_data, self.nicks, self.nick_same_list) sys.stdout = sys.__stdout__ capturedOutput.close() self.assertEqual(bin_matrix, expected_bin_matrix) self.assertEqual(tot_msgs, expected_tot_msgs)
def test_nick_change_graph(self, mock_get_year_month_day, mock_build_graphs, mock_splice_find): mock_splice_find_data = util.load_from_disk( self.current_directory + "/data/user_test/nick_change_graph/splice_find_list") mock_build_graphs_data = util.load_from_disk( self.current_directory + "/data/user_test/build_graphs_list") mock_get_year_month_day_data = util.load_from_disk( self.current_directory + "/data/user_test/get_year_month_day_list") mock_splice_find.side_effect = mock_splice_find_data mock_build_graphs.side_effect = mock_build_graphs_data mock_get_year_month_day.side_effect = mock_get_year_month_day_data expected_nick_change_graph_list = util.load_from_disk( self.current_directory + "/data/user_test/nick_change_graph_list") expected_aggregate_nick_change_graph = util.load_from_disk( self.current_directory + "/data/user_test/aggregate_nick_change_graph") nick_change_graph_list = user.nick_change_graph(self.log_data, True) mock_splice_find.side_effect = mock_splice_find_data mock_build_graphs.side_effect = mock_build_graphs_data mock_get_year_month_day.side_effect = mock_get_year_month_day_data aggregate_nick_change_graph = user.nick_change_graph( self.log_data, False) for i in xrange(len(nick_change_graph_list)): self.assertTrue( nx.is_isomorphic(expected_nick_change_graph_list[i], nick_change_graph_list[i])) self.assertTrue( nx.is_isomorphic(expected_aggregate_nick_change_graph, aggregate_nick_change_graph))
def setUp(self): self.current_directory = os.path.dirname(os.path.realpath(__file__)) self.test_data_dir = self.current_directory + "/../../../data/test_lib/test_analysis/user_test/" self.log_data = util.load_from_disk(self.test_data_dir + "log_data") self.nicks = util.load_from_disk(self.test_data_dir + "nicks") self.nick_same_list = util.load_from_disk(self.test_data_dir + "nick_same_list")
def test_response_time_high_cutoff_percentile(self): # this test assumes config.CUTOFF_TIME_STRATEGY = "TWO_SIGMA" cutoff_percentile = 5.0 expected_resp_time = util.load_from_disk( self.test_data_dir + "/channel/truncated_rt_5percent") expected_cutoff_time = 2 resp_time, cutoff_time = channel.response_time(self.log_data, self.nicks, self.nick_same_list, cutoff_percentile) assert resp_time == expected_resp_time, \ "Error in computing response time with 5% cutoff percentile." assert cutoff_time == expected_cutoff_time, \ "Error in computing RT cutoff with 5% cutoff percentile." cutoff_percentile = 10.0 expected_resp_time = util.load_from_disk( self.test_data_dir + "/channel/truncated_rt_10percent") expected_cutoff_time = 3 resp_time, cutoff_time = channel.response_time(self.log_data, self.nicks, self.nick_same_list, cutoff_percentile) assert resp_time == expected_resp_time, \ "Error in computing response time with 10% cutoff percentile." assert cutoff_time == expected_cutoff_time, \ "Error in computing RT cutoff with 10% cutoff percentile."
def test_conv_len_conv_refr_time(self,mock_to_graph, mock_connected_nick_list, mock_nick_sen,\ mock_correct_last_char_list,mock_correct_last_char_CR, mock_rec_list_splice,\ mock_msg_line,mock_splice_find, mock_stat_dist, mock_truncate_table): mock_to_graph.return_value = self.to_graph mock_connected_nick_list.side_effect = self.mock_create_connected_nick_list mock_nick_sen.side_effect = self.mock_get_nick_sen_rec mock_correct_last_char_list.side_effect = self.mock_correct_last_char_list mock_correct_last_char_CR.side_effect = self.mock_correctLastCharCR mock_rec_list_splice.side_effect = self.mock_rec_list_splice mock_msg_line.side_effect = self.mock_check_if_msg_line mock_splice_find.side_effect = self.mock_splice_find mock_truncate_table.side_effect = [ util.load_from_disk(self.test_data_dir + "/channel/truncate_cl"), util.load_from_disk(self.test_data_dir + "/channel/truncate_crt") ] rt_cutoff_time = 1 cutoff_percentile = 0 expected_conv_len = util.load_from_disk(self.test_data_dir + "/channel/conv_len") expected_conv_ref_time = util.load_from_disk(self.test_data_dir + "/channel/conv_ref_time") conv_len, conv_ref_time = \ channel.conv_len_conv_refr_time(self.log_data, self.nicks, self.nick_same_list, rt_cutoff_time, cutoff_percentile) self.assertEqual(conv_len, expected_conv_len, \ "Error in computing conversation length correctly.") self.assertEqual(conv_ref_time, expected_conv_ref_time, \ "Error in computing conversation refresh time correctly.")
def setUp(self): self.log_data = util.load_from_disk(current_directory + "/data/user_test/log_data") self.nicks = util.load_from_disk(current_directory + "/data/user_test/nicks") self.nick_same_list = util.load_from_disk( current_directory + "/data/user_test/nick_same_list")
def test_plot_infomap_igraph_show_edges(self,mock_igraph_plot): message_graph = util.load_from_disk(current_dir+'/data/message_graph') membership = util.load_from_disk(current_dir+'/data/membership') igraph = util.load_from_disk(current_dir+'/data/igraph') # test for infomap generation with edges vis.plot_infomap_igraph(message_graph,membership, current_dir, "message", show_edges=True) self.assertTrue(mock_igraph_plot.call_args[0][0].isomorphic_vf2(igraph))
def setUp(self): current_directory = os.path.dirname(os.path.abspath(__file__)) self.test_data_dir = current_directory + "/../../../data/test_lib/test_analysis/" self.log_data = util.load_from_disk(self.test_data_dir + "/channel/log_data") self.nicks = util.load_from_disk(self.test_data_dir + "/channel/nicks") self.nick_same_list = util.load_from_disk(self.test_data_dir + "/channel/nick_same_list")
def setUp(self): self.current_directory = os.path.dirname(os.path.realpath(__file__)) self.log_data = util.load_from_disk(self.current_directory + "/data/log_data") self.nicks_hash = util.load_from_disk(self.current_directory + "/data/nicks_hash") self.sample_igraph = Graph() self.sample_igraph.add_vertices(8)
def setUp(self): self.current_directory = os.path.dirname(os.path.realpath(__file__)) self.log_data = util.load_from_disk( self.current_directory + "/../../../data/user_test/log_data") self.nicks = util.load_from_disk(self.current_directory + "/../../../data/user_test/nicks") self.nick_same_list = util.load_from_disk( self.current_directory + "/../../../data/user_test/nick_same_list")
def test_plot_infomap_igraph_aux_data(self,mock_igraph_plot): message_graph = util.load_from_disk(current_dir+'/data/vis/message_exchange_graph') membership = util.load_from_disk(current_dir+'/data/vis/message_exchange_graph_membership') igraph = util.load_from_disk(current_dir+'/data/vis/message_exchange_igraph') aux = util.load_from_disk(current_dir+'/data/vis/aux_data') # test for infomap generation with auxiliary data vis.plot_infomap_igraph(message_graph,membership, current_dir, "message", aux_data = aux) self.assertTrue(mock_igraph_plot.call_args[0][0].isomorphic_vf2(igraph))
def test_user_nick_change_tracking(self): expected_nicks = util.load_from_disk(self.out_dir + "nicks") expected_nick_same_list = util.load_from_disk(self.out_dir + "nick_same_list") nicks, nick_same_list = nickTracker.nick_tracker(self.log_data) self.assertEqual(expected_nicks, nicks) self.assertEqual(expected_nick_same_list, nick_same_list)
def test_generate_log_plots(self, mock_calc_plot): data = util.load_from_disk(self.test_data_dir + "/vis/degree_msg_number") expected_result = util.load_from_disk(self.test_data_dir + "/vis/out_degree_analysis") mock_calc_plot.return_value = util.load_from_disk(self.test_data_dir + "vis/calc_plot_data") expected_output = vis.generate_log_plots(data, self.test_data_dir, "log_plot_test") self.assertTrue(np.allclose(expected_output, expected_result))
def test_plot_infomap_igraph_no_edges(self,mock_igraph_plot): message_graph = util.load_from_disk(current_dir+'/data/message_graph') membership = util.load_from_disk(current_dir+'/data/membership') igraph = util.load_from_disk(current_dir+'/data/igraph') # test infomap plotting with edges not shown vis.plot_infomap_igraph(message_graph,membership, current_dir, "message", show_edges=False) self.assertTrue(mock_igraph_plot.call_args[0][0].isomorphic_vf2(igraph)) # check infomap generation with None membership vis.plot_infomap_igraph(message_graph,None, current_dir, "message") self.assertTrue(mock_igraph_plot.call_args[0][0].isomorphic_vf2(igraph))
def test_extended_stop_words(self): nicks_for_stop_words = util.load_from_disk( current_directory + "/data/user_test/keywords/nicks_for_stop_words") stop_word_without_apostrophe = util.load_from_disk( current_directory + "/data/user_test/stop_word_without_apostrophe") expected_stop_words_extended = util.load_from_disk( current_directory + "/data/user_test/keywords/extended_stop_words") stop_words_extended = user.extended_stop_words( nicks_for_stop_words, stop_word_without_apostrophe) self.assertEqual(expected_stop_words_extended, stop_words_extended)
def test_channel_user_presence_graph_and_csv(self): nicks = util.load_from_disk(self.current_directory + '/data/test_presence_nicks') nick_same_list = util.load_from_disk( self.current_directory + '/data/test_presence_nick_same_list') channels_for_user = util.load_from_disk( self.current_directory + '/data/test_presence_channels_for_user') nick_channel_dict = util.load_from_disk( self.current_directory + '/data/test_presence_nick_channel_dict') nicks_hash = util.load_from_disk(self.current_directory + '/data/test_presence_nicks_hash') channels_hash = util.load_from_disk( self.current_directory + '/data/test_presence_channels_hash') expected_dict_out = util.load_from_disk(self.current_directory + '/data/dict_out') expected_graph = util.load_from_disk(self.current_directory + '/data/graph') capturedOutput = StringIO.StringIO() sys.stdout = capturedOutput dict_out, graph = network.channel_user_presence_graph_and_csv( nicks, nick_same_list, channels_for_user, nick_channel_dict, nicks_hash, channels_hash) sys.stdout = sys.__stdout__ capturedOutput.close() self.assertTrue(nx.is_isomorphic(expected_graph, graph)) self.assertTrue( nx.is_isomorphic(expected_dict_out['CC']['graph'], dict_out['CC']['graph'])) self.assertTrue( nx.is_isomorphic(expected_dict_out['CC']['reducedGraph'], dict_out['CC']['reducedGraph'])) self.assertTrue( nx.is_isomorphic(expected_dict_out['CU']['graph'], dict_out['CU']['graph'])) self.assertTrue( nx.is_isomorphic(expected_dict_out['CU']['reducedGraph'], dict_out['CU']['reducedGraph'])) self.assertTrue( nx.is_isomorphic(expected_dict_out['UU']['graph'], dict_out['UU']['graph'])) self.assertTrue( nx.is_isomorphic(expected_dict_out['UU']['reducedGraph'], dict_out['UU']['reducedGraph'])) assert_array_equal(expected_dict_out['CC']['matrix'], dict_out['CC']['matrix']) assert_array_equal(expected_dict_out['CC']['reducedMatrix'], dict_out['CC']['reducedMatrix']) assert_array_equal(expected_dict_out['CU']['matrix'], dict_out['CU']['matrix']) assert_array_equal(expected_dict_out['CU']['reducedMatrix'], dict_out['CU']['reducedMatrix']) assert_array_equal(expected_dict_out['UU']['matrix'], dict_out['UU']['matrix']) assert_array_equal(expected_dict_out['UU']['reducedMatrix'], dict_out['UU']['reducedMatrix'])
def test_conv_len_conv_refr_time(self): rt_cutoff_time = 1 cutoff_percentile = 0 expected_conv_len = util.load_from_disk(current_directory + "/data/conv_len") expected_conv_ref_time = util.load_from_disk(current_directory+ "/data/conv_ref_time") conv_len, conv_ref_time = \ channel.conv_len_conv_refr_time(self.log_data, self.nicks, self.nick_same_list, rt_cutoff_time, cutoff_percentile) assert conv_len == expected_conv_len, \ "Error in computing conversation length correctly." assert conv_ref_time == expected_conv_ref_time, \ "Error in computing conversation refresh time correctly."
def setUp(self): self.current_directory = os.path.dirname(os.path.realpath(__file__)) self.log_data = util.load_from_disk(self.current_directory+ "/data/log_data") self.nicks1 = util.load_from_disk(self.current_directory+ "/data/nicks1") self.nick_same_list1 = util.load_from_disk(self.current_directory+ "/data/nick_same_list1") self.nicks2 = util.load_from_disk(self.current_directory+ "/data/nicks2") self.nick_same_list2 = util.load_from_disk(self.current_directory+ "/data/nick_same_list2") self.channels_for_user = util.load_from_disk(self.current_directory+ "/data/channels_for_user") self.nick_channel_dict = util.load_from_disk(self.current_directory+ "/data/nick_channel_dict") self.nicks_hash = util.load_from_disk(self.current_directory+ "/data/nicks_hash") self.channels_hash = util.load_from_disk(self.current_directory+ "/data/channels_hash")
def test_exponential_curve_fit_and_plot(self, mock_curve_fit, mock_curve_func, mock_probability_distribution): data = util.load_from_disk(self.test_data_dir + "/vis/conv_len") expected_result = util.load_from_disk(self.test_data_dir + "/vis/conv_len_fit") mock_curve_fit.return_value = util.load_from_disk(self.test_data_dir + "/vis/curve_fit") mock_curve_func.side_effect = self.mock_exponential_curve_func mock_probability_distribution.side_effect = self.mock_generate_probability_distribution expected_output = vis.exponential_curve_fit_and_plot( data, self.test_data_dir, "exponential_plot_test") os.remove(self.test_data_dir + '/exponential_plot_test.png') self.assertTrue(np.allclose(expected_output, expected_result))
def test_top_keywords_for_nick(self): user_keyword_freq_dict = util.load_from_disk( current_directory + "/data/user_test/user_keyword_freq_dict") expected_top_keywords = util.load_from_disk( current_directory + "/data/user_test/top_keywords") expected_top_keywords_normal_freq = util.load_from_disk( current_directory + "/data/user_test/top_keywords_normal_freq") top_keywords, top_keywords_normal_freq = user.top_keywords_for_nick( user_keyword_freq_dict, user_keyword_freq_dict[0]['nick'], 0.01, 100) self.assertEqual(top_keywords, expected_top_keywords) self.assertEqual(top_keywords_normal_freq, expected_top_keywords_normal_freq)
def test_community_analysis_single_channel_cutoff_20(self): log_data = reader.linux_input(self.log_data_dir, ["#kubuntu-devel"], self.start_date, self.end_date) expected_result = util.load_from_disk( self.current_directory + '/data/output/community_analysis_single_channel_cutoff_20') nicks, nick_same_list = nickTracker.nick_tracker(log_data) default_cutoff = config.THRESHOLD_MESSAGE_NUMBER_GRAPH config.THRESHOLD_MESSAGE_NUMBER_GRAPH = 20 message_number_graph = network.message_number_graph( log_data, nicks, nick_same_list, False) saver.save_net_nx_graph( message_number_graph, self.current_directory, "message-exchange-" + self.start_date + "-cutoff-" + str(config.THRESHOLD_MESSAGE_NUMBER_GRAPH)) expected_output = community.infomap_igraph( ig_graph=None, net_file_location=self.current_directory + "/message-exchange-" + self.start_date + "-cutoff-" + str(config.THRESHOLD_MESSAGE_NUMBER_GRAPH) + '.net') os.remove(self.current_directory + "/message-exchange-" + self.start_date + "-cutoff-" + str(config.THRESHOLD_MESSAGE_NUMBER_GRAPH) + '.net') config.THRESHOLD_MESSAGE_NUMBER_GRAPH = default_cutoff self.assertTrue(expected_result[0].isomorphic(expected_output[0])) self.assertEqual( compare_communities(expected_result[1], expected_output[1]), 0)
def test_infomap_igraph(self): message_graph, message_comm = community.infomap_igraph(ig_graph=None, net_file_location= self.current_directory + '/data/message_number_graph.net') expected_result = util.load_from_disk(self.current_directory + '/data/community') dis = clustering.compare_communities(message_comm, expected_result) #calculate distance between two communities self.assertEqual(dis, 0.0)
def test_exponential_curve_fit_and_plot_x_shifted( self, mock_curve_fit, mock_curve_func, mock_probability_distribution): data = util.load_from_disk(self.test_data_dir + "/vis/conv_ref_time") expected_result = util.load_from_disk(self.test_data_dir + "/vis/conv_ref_time_fit_params") mock_curve_fit.return_value = util.load_from_disk( self.test_data_dir + "/vis/curve_fit_x_shifted") mock_curve_func.side_effect = self.mock_exponential_curve_func mock_probability_distribution.side_effect = self.mock_generate_probability_distribution expected_output = vis.exponential_curve_fit_and_plot_x_shifted( data, self.test_data_dir, "exponential_plot_test_shifted") # delete the plot created os.remove(self.test_data_dir + '/exponential_plot_test_shifted.png') self.assertTrue(np.allclose(expected_output, expected_result))
def test_linux_input_all_channels(self): expected_capturedOutput = util.load_from_disk(self.current_directory + "/data/stdout_captured_linux_input_all_channels") expected_log_data = util.load_from_disk(self.current_directory + "/data/log_data_for_test_linux_input_all_channels") capturedOutput = StringIO.StringIO() sys.stdout = capturedOutput log_data = reader.linux_input(self.current_directory + "/data/log_to_test_for_all_channels/", ["ALL"], "2013-1-1", "2013-1-2") output = capturedOutput.getvalue() capturedOutput.close() sys.stdout = sys.__stdout__ #See https://docs.python.org/2/library/re.html for more details. output = re.sub(r'(?P<begin>.+ )/.+/(?P<constant>IRCLogParser/.+\n)', r'\g<begin>\g<constant>', output) self.assertEqual(expected_log_data, log_data) self.assertEqual(expected_capturedOutput, output)
def test_degree_distribution_multi_channel(self): log_data = reader.linux_input(self.log_data_dir, ["ALL"], self.start_date, self.end_date) expected_result_CC_degree_curve_fit = util.load_from_disk( self.current_directory + '/data/output/CC_degree_curve_fit') expected_result_CU_degree_curve_fit = util.load_from_disk( self.current_directory + '/data/output/CU_degree_curve_fit') expected_result_UU_degree_curve_fit = util.load_from_disk( self.current_directory + '/data/output/UU_degree_curve_fit') nicks, nick_same_list, channels_for_user, nick_channel_dict, nicks_hash, channels_hash = nickTracker.nick_tracker( log_data, True) dict_out, graph = network.channel_user_presence_graph_and_csv( nicks, nick_same_list, channels_for_user, nick_channel_dict, nicks_hash, channels_hash) degree_anal_message_number_CC = network.degree_analysis_on_graph( dict_out["CC"]["graph"], directed=False) degree_anal_message_number_UU = network.degree_analysis_on_graph( dict_out["UU"]["graph"], directed=False) degree_anal_message_number_CU = network.degree_analysis_on_graph( dict_out["CU"]["graph"], directed=False) Y = degree_anal_message_number_CU["degree"]["raw_for_vis"][1:] data = [(i, Y[i]) for i in range(len(Y))] CU_truncated, cutoff = channel.truncate_table(data, 0.5) CU_T = [data[1] for data in list(CU_truncated)] expected_output_CC_degree_curve_fit = vis.generate_log_plots( degree_anal_message_number_CC["degree"]["raw_for_vis"], self.current_directory, "CC_degree_curve_fit") expected_output_CU_degree_curve_fit = vis.generate_log_plots( CU_T, self.current_directory, "CU_degree_curve_fit") expected_output_UU_degree_curve_fit = vis.generate_log_plots( degree_anal_message_number_UU["degree"]["raw_for_vis"], self.current_directory, "UU_degree_curve_fit") os.remove(self.current_directory + "/CC_degree_curve_fit" + ".png") os.remove(self.current_directory + "/CU_degree_curve_fit" + ".png") os.remove(self.current_directory + "/UU_degree_curve_fit" + ".png") self.assertEqual(expected_result_CC_degree_curve_fit, expected_output_CC_degree_curve_fit) self.assertEqual(expected_result_CU_degree_curve_fit, expected_output_CU_degree_curve_fit) self.assertEqual(expected_result_UU_degree_curve_fit, expected_output_UU_degree_curve_fit)
def test_activity_graph(self): self.expected_result = util.load_from_disk( self.current_directory + "/data/output/activity_graph") bin_matrix, total_messages = network.message_number_bins_csv( self.log_data_kubuntu_devel, self.nicks, self.nick_same_list) expected_output = [[i for i in range(len(bin_matrix[0]))]] expected_output.append([sum(i) for i in zip(*bin_matrix)]) self.assertTrue(expected_output, self.expected_result)
def test_response_time_high_cutoff_percentile(self,mock_to_graph, mock_connected_nick_list, mock_nick_sen,\ mock_correct_last_char_list,mock_correct_last_char_CR, mock_rec_list_splice,\ mock_msg_line,mock_splice_find, mock_stat_dist, mock_truncate_table): # this test assumes config.CUTOFF_TIME_STRATEGY = "TWO_SIGMA" mock_to_graph.return_value = self.to_graph mock_connected_nick_list.side_effect = self.mock_create_connected_nick_list mock_nick_sen.side_effect = self.mock_get_nick_sen_rec mock_correct_last_char_list.side_effect = self.mock_correct_last_char_list mock_correct_last_char_CR.side_effect = self.mock_correctLastCharCR mock_rec_list_splice.side_effect = self.mock_rec_list_splice mock_msg_line.side_effect = self.mock_check_if_msg_line mock_splice_find.side_effect = self.mock_splice_find mock_truncate_table.side_effect = [ util.load_from_disk(self.test_data_dir + "/channel/rt_high_5_percent"), util.load_from_disk(self.test_data_dir + "/channel/rt_high_10_percent") ] cutoff_percentile = 5.0 expected_resp_time = util.load_from_disk( self.test_data_dir + "/channel/truncated_rt_5percent") expected_cutoff_time = 2 resp_time, cutoff_time = channel.response_time(self.log_data, self.nicks, self.nick_same_list, cutoff_percentile) self.assertEqual(resp_time, expected_resp_time, \ "Error in computing response time with 5% cutoff percentile.") self.assertEqual(cutoff_time, expected_cutoff_time, \ "Error in computing RT cutoff with 5% cutoff percentile.") cutoff_percentile = 10.0 expected_resp_time = util.load_from_disk( self.test_data_dir + "/channel/truncated_rt_10percent") expected_cutoff_time = 3 resp_time, cutoff_time = channel.response_time(self.log_data, self.nicks, self.nick_same_list, cutoff_percentile) self.assertEqual(resp_time, expected_resp_time, \ "Error in computing response time with 10% cutoff percentile.") self.assertEqual(cutoff_time, expected_cutoff_time, \ "Error in computing RT cutoff with 10% cutoff percentile.")
def test_identify_hubs_and_experts(self): log_data = util.load_from_disk(self.test_data_dir + "hits/log_data") nicks = util.load_from_disk(self.test_data_dir + "hits/nicks") nick_same_list = util.load_from_disk(self.test_data_dir + "hits/nick_same_list") expected_top_hub = util.load_from_disk(self.test_data_dir + "hits/top_hub") expected_top_keyword_overlap = util.load_from_disk( self.test_data_dir + "hits/top_keyword_overlap") expected_top_auth = util.load_from_disk(self.test_data_dir + "hits/top_auth") message_graph = util.load_from_disk(self.test_data_dir + "hits/message_graph") capturedOutput = StringIO.StringIO() sys.stdout = capturedOutput message_num_graph, top_hub, top_keyword_overlap, top_auth = network.identify_hubs_and_experts( log_data, nicks, nick_same_list) sys.stdout = sys.__stdout__ capturedOutput.close() self.assertEqual(top_hub, expected_top_hub) self.assertEqual(top_keyword_overlap, expected_top_keyword_overlap) self.assertEqual(top_auth, expected_top_auth) self.assertTrue(nx.is_isomorphic(message_graph, message_num_graph))
def test_message_number_bins_csv(self): expected_bin_matrix = util.load_from_disk( self.test_data_dir + "message_number_bins_csv/bin_matrix") expected_tot_msgs = util.load_from_disk( self.test_data_dir + "message_number_bins_csv/tot_msgs") capturedOutput = StringIO.StringIO() sys.stdout = capturedOutput bin_matrix, tot_msgs = network.message_number_bins_csv( self.log_data, self.nicks, self.nick_same_list) sys.stdout = sys.__stdout__ capturedOutput.close() self.assertEqual(bin_matrix, expected_bin_matrix) self.assertEqual(tot_msgs, expected_tot_msgs)