コード例 #1
0
    def test_message_number_bins_csv(self, mock_util):

        mock_util.correctLastCharCR.side_effect = util.load_from_disk(
            self.test_data_dir + "message_number_bins_csv/correctLastCharCR")
        mock_util.correct_last_char_list.side_effect = util.load_from_disk(
            self.test_data_dir +
            "message_number_bins_csv/correct_last_char_list")
        mock_util.rec_list_splice.side_effect = util.load_from_disk(
            self.test_data_dir + "message_number_bins_csv/rec_list_splice")

        bin_matrix_ = util.load_from_disk(self.test_data_dir +
                                          "message_number_bins_csv/bin_matrix")
        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, bin_matrix_)
        self.assertEqual(tot_msgs, tot_msgs_)
コード例 #2
0
 def setUp(self):
     self.current_directory = os.path.dirname(os.path.realpath(__file__))
     self.test_data_dir = self.current_directory + "/../../../../data/test_slack/test_lib/test_analysis/network_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")
コード例 #3
0
    def test_degree_node_number_csv(self, mock_msg_graph):

        msg_num_graph_day_list = util.load_from_disk(
            self.test_data_dir + "degree_node_number_csv/msg_day_list")
        out_degree_ = util.load_from_disk(self.test_data_dir +
                                          "degree_node_number_csv/out_degree")
        in_degree_ = util.load_from_disk(self.test_data_dir +
                                         "degree_node_number_csv/in_degree")
        total_degree_ = util.load_from_disk(
            self.test_data_dir + "degree_node_number_csv/total_degree")

        mock_msg_graph.return_value = msg_num_graph_day_list

        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput

        out_degree, in_degree, total_degree = network.degree_node_number_csv(
            self.log_data, self.nicks, self.nick_same_list)

        sys.stdout = sys.__stdout__
        capturedOutput.close()

        mock_msg_graph.assert_called_once_with(self.log_data, self.nicks,
                                               self.nick_same_list, True)
        self.assertEqual(out_degree, out_degree_)
        self.assertEqual(in_degree, in_degree_)
        self.assertEqual(total_degree, total_degree_)
コード例 #4
0
    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(current_directory +
                                                 "/data/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(
            current_directory + "/data/truncated_rt_10percent")
        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 10% cutoff percentile."
        assert cutoff_time == expected_cutoff_time, \
                "Error in computing RT cutoff with 10% cutoff percentile."
コード例 #5
0
 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")
コード例 #6
0
    def test_identify_hubs_and_experts(self, mock_keywords, mock_msg_graph):

        top_hub_ = util.load_from_disk(current_directory + "/data/top_hub")
        top_keyword_overlap_ = util.load_from_disk(current_directory +
                                                   "/data/top_keyword_overlap")
        top_auth_ = util.load_from_disk(current_directory + "/data/top_auth")
        message_graph = util.load_from_disk(current_directory +
                                            "/data/message_graph")
        keyword_dict_list = util.load_from_disk(current_directory +
                                                "/data/keyword_dict_list")
        user_keyword_freq_dict = util.load_from_disk(
            current_directory + "/data/user_keyword_freq_dict")
        user_words_dict_list = util.load_from_disk(
            current_directory + "/data/user_words_dict_list")
        nicks_for_stop_words = util.load_from_disk(
            current_directory + "/data/nicks_for_stop_words")
        keywords_for_channels = util.load_from_disk(
            current_directory + "/data/keywords_for_channels")

        # setup mock
        mock_msg_graph.return_value = message_graph
        mock_keywords.return_value = keyword_dict_list, user_keyword_freq_dict, user_words_dict_list, nicks_for_stop_words, keywords_for_channels
        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput

        message_num_graph, top_hub, top_keyword_overlap, top_auth = network.identify_hubs_and_experts(
            self.log_data, self.nicks, self.nick_same_list)

        sys.stdout = sys.__stdout__
        capturedOutput.close()

        self.assertEqual(top_hub, top_hub_)
        self.assertEqual(top_keyword_overlap, top_keyword_overlap_)
        self.assertEqual(top_auth, top_auth_)
        self.assertTrue(nx.is_isomorphic(message_graph, message_num_graph))
コード例 #7
0
    def test_conv_len_conv_refr_time(self):
        rt_cutoff_time = 1
        cutoff_percentile = 0
        expected_conv_len = util.load_from_disk(self.current_directory + "/data/conv_len")
        expected_conv_ref_time = util.load_from_disk(self.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)

        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.")
コード例 #8
0
    def test_degree_analysis_on_graph(self):
        directed_graph = util.load_from_disk(self.test_data_dir +
                                             'directed_graph')
        directed_deg_analysis_expected = util.load_from_disk(
            self.test_data_dir + 'directed_deg_analysis_result')

        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput

        directed_deg_analysis = network.degree_analysis_on_graph(
            directed_graph)

        sys.stdout = sys.__stdout__
        capturedOutput.close()

        self.assertEqual(directed_deg_analysis, directed_deg_analysis_expected)
コード例 #9
0
    def test_message_number_bins_csv(self):

        bin_matrix_ = util.load_from_disk(self.test_data_dir +
                                          "message_number_bins_csv/bin_matrix")
        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, bin_matrix_)
        self.assertEqual(tot_msgs, tot_msgs_)
コード例 #10
0
    def test_message_number_graph(self, mock_rec_list_splice, mock_correctLastCharCR, mock_get_nick_sen_rec, mock_get_year_month_day,\
                         mock_get_nick_representative, mock_check_if_msg_line, mock_create_connected_nick_list, mock_to_graph):
        to_graph_ret = util.load_from_disk(
            current_directory + "/data/message_number_graph/to_graph")

        conn_list = list(connected_components(to_graph_ret))

        mock_to_graph.return_value = to_graph_ret
        mock_rec_list_splice.side_effect = util.load_from_disk(
            current_directory + "/data/message_number_graph/rec_list_splice")
        mock_create_connected_nick_list.return_value = util.load_from_disk(
            current_directory + "/data/message_number_graph/conn_comp_list")
        #mock_correct_last_char_list.side_effect = util.load_from_disk(current_directory + "/data/message_number_graph/correct_last_char_list")
        mock_check_if_msg_line.side_effect = util.load_from_disk(
            current_directory + "/data/message_number_graph/check_if_msg_line")
        mock_correctLastCharCR.side_effect = util.load_from_disk(
            current_directory + "/data/message_number_graph/correctLastCharCR")
        mock_get_nick_sen_rec.side_effect = util.load_from_disk(
            current_directory + "/data/message_number_graph/get_nick_sen_rec")
        #mock_extend_conversation_list.side_effect = util.load_from_disk(current_directory + "/data/message_number_graph/extend_conversation_list")
        mock_get_nick_representative.side_effect = util.load_from_disk(
            current_directory +
            "/data/message_number_graph/get_nick_representative")
        mock_get_year_month_day.side_effect = util.load_from_disk(
            current_directory +
            "/data/message_number_graph/get_year_month_day")

        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput

        ret = network.message_number_graph(self.log_data,
                                           self.nicks,
                                           self.nick_same_list,
                                           DAY_BY_DAY_ANALYSIS=False)

        sys.stdout = sys.__stdout__
        capturedOutput.close()

        mock_to_graph.assert_called_once_with(self.nick_same_list)
        mock_create_connected_nick_list.assert_called_once_with(conn_list)
        self.assertTrue(
            nx.is_isomorphic(
                ret,
                util.load_from_disk(
                    current_directory +
                    "/data/message_number_graph/aggregate_message_number_graph"
                )))
コード例 #11
0
    def test_degree_node_number_csv(self):

        out_degree_ = util.load_from_disk(self.test_data_dir +
                                          "degree_node_number_csv/out_degree")
        in_degree_ = util.load_from_disk(self.test_data_dir +
                                         "degree_node_number_csv/in_degree")
        total_degree_ = util.load_from_disk(
            self.test_data_dir + "degree_node_number_csv/total_degree")

        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput

        out_degree, in_degree, total_degree = network.degree_node_number_csv(
            self.log_data, self.nicks, self.nick_same_list)

        sys.stdout = sys.__stdout__
        capturedOutput.close()

        self.assertEqual(out_degree, out_degree_)
        self.assertEqual(in_degree, in_degree_)
        self.assertEqual(total_degree, total_degree_)
コード例 #12
0
    def test_linux_input_non_existent_file_slack(self):
        expected_captured_output = util.load_from_disk(
            self.current_directory +
            "/data/stdout_captured_linux_input_slack_non_existent_file")
        expected_log_data = util.load_from_disk(
            self.current_directory +
            "/data/log_data_for_test_linux_input_non_existent_file_slack")

        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput
        log_data = reader.linux_input_slack(
            self.current_directory + "/data/slackware_with_missing_files/",
            "2013-1-1", "2013-1-6")
        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_captured_output, output)
コード例 #13
0
    def test_response_time_low_cutoff_percentile(self):
        # this test assumes config.CUTOFF_TIME_STRATEGY = "TWO_SIGMA"

        cutoff_percentile = 0.0
        expected_resp_time = util.load_from_disk(self.current_directory + "/data/resp_time")
        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 0% cutoff percentile.")
        self.assertEqual(cutoff_time, expected_cutoff_time, \
                "Error in computing RT cutoff with 0% cutoff percentile.")

        cutoff_percentile = 1.0
        expected_resp_time = util.load_from_disk(self.current_directory + "/data/truncated_rt_1percent")
        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 1% cutoff percentile.")
        self.assertEqual(cutoff_time, expected_cutoff_time, \
                "Error in computing RT cutoff with 1% cutoff percentile.")
コード例 #14
0
    def test_identify_hubs_and_experts(self):

        top_hub_ = util.load_from_disk(self.test_data_dir + "hits/top_hub")
        top_keyword_overlap_ = util.load_from_disk(self.test_data_dir +
                                                   "hits/top_keyword_overlap")
        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(
            self.log_data, self.nicks, self.nick_same_list)

        sys.stdout = sys.__stdout__
        capturedOutput.close()

        self.assertEqual(top_hub, top_hub_)
        self.assertEqual(top_keyword_overlap, top_keyword_overlap_)
        self.assertEqual(top_auth, top_auth_)
        self.assertTrue(nx.is_isomorphic(message_graph, message_num_graph))
コード例 #15
0
    def test_truncate_table_with_long_table(self):
        resp_time = util.load_from_disk(self.current_directory + "/data/resp_time")

        expected_cutoff_time = 1067
        cutoff_percentile = 5
        truncated_table, cutoff_time = channel.truncate_table(resp_time, cutoff_percentile)
        self.assertEqual(cutoff_time, expected_cutoff_time, \
                "Error in computing percentile cutoff value")

        cutoff_percentile = 1
        expected_cutoff_time = 1172
        truncated_table, cutoff_time = channel.truncate_table(resp_time, cutoff_percentile)
        self.assertEqual(cutoff_time, expected_cutoff_time, \
                "Error in computing percentile cutoff value")
コード例 #16
0
    def test_message_number_graph(self):
        to_graph_ret = util.load_from_disk(self.test_data_dir +
                                           "message_number_graph/to_graph")

        conn_list = list(connected_components(to_graph_ret))

        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput

        ret = network.message_number_graph(self.log_data,
                                           self.nicks,
                                           self.nick_same_list,
                                           DAY_BY_DAY_ANALYSIS=False)

        sys.stdout = sys.__stdout__
        capturedOutput.close()

        self.assertTrue(
            nx.is_isomorphic(
                ret,
                util.load_from_disk(
                    self.test_data_dir +
                    "message_number_graph/aggregate_message_number_graph")))
コード例 #17
0
    def test_message_time_graph_day_analysis(self):

        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput

        ret = network.message_time_graph(self.log_data,
                                         self.nicks,
                                         self.nick_same_list,
                                         DAY_BY_DAY_ANALYSIS=True)
        expected_graph_list = util.load_from_disk(
            self.test_data_dir + "message_time_graph/msg_time_graph_list")

        sys.stdout = sys.__stdout__
        capturedOutput.close()

        self.assertTrue(nx.is_isomorphic(ret[0], expected_graph_list[0]))
コード例 #18
0
    def test_message_time_graph(self):

        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput

        ret = network.message_time_graph(self.log_data,
                                         self.nicks,
                                         self.nick_same_list,
                                         DAY_BY_DAY_ANALYSIS=False)

        sys.stdout = sys.__stdout__
        capturedOutput.close()

        self.assertTrue(
            nx.is_isomorphic(
                ret,
                util.load_from_disk(self.test_data_dir +
                                    "message_time_graph/msg_time_aggr_graph")))
コード例 #19
0
    def test_message_time_graph_day_analysis(
            self, mock_rec_list_splice, mock_correctLastCharCR,
            mock_get_year_month_day, mock_get_nick_sen_rec,
            mock_check_if_msg_line, mock_create_connected_nick_list,
            mock_to_graph):
        to_graph_ret = util.load_from_disk(self.test_data_dir +
                                           "message_time_graph/to_graph")

        conn_list = list(connected_components(to_graph_ret))

        mock_to_graph.return_value = to_graph_ret
        mock_rec_list_splice.side_effect = util.load_from_disk(
            self.test_data_dir + "message_time_graph/rec_list_splice")
        mock_create_connected_nick_list.return_value = util.load_from_disk(
            self.test_data_dir + "message_time_graph/conn_comp_list")
        mock_check_if_msg_line.side_effect = util.load_from_disk(
            self.test_data_dir + "message_time_graph/check_if_msg_line")
        mock_correctLastCharCR.side_effect = util.load_from_disk(
            self.test_data_dir + "message_time_graph/correctLastCharCR")
        mock_get_nick_sen_rec.side_effect = util.load_from_disk(
            self.test_data_dir + "message_time_graph/get_nick_sen_rec")
        #mock_correct_last_char_list.side_effect = util.load_from_disk(self.test_data_dir + "message_time_graph/correct_last_char_list")
        mock_get_year_month_day.side_effect = util.load_from_disk(
            self.test_data_dir + "message_time_graph/get_year_month_day")

        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput

        ret = network.message_time_graph(self.log_data,
                                         self.nicks,
                                         self.nick_same_list,
                                         DAY_BY_DAY_ANALYSIS=True)
        expected_graph_list = util.load_from_disk(
            self.test_data_dir + "message_time_graph/msg_time_graph_list")

        sys.stdout = sys.__stdout__
        capturedOutput.close()

        mock_to_graph.assert_called_once_with(self.nick_same_list)
        mock_create_connected_nick_list.assert_called_once_with(conn_list)
        self.assertTrue(nx.is_isomorphic(ret[0], expected_graph_list[0]))
コード例 #20
0
    def test_linux_input_slack(self):
        expected_captured_output = util.load_from_disk(
            self.current_directory + "/data/stdout_captured_linux_input_slack")

        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput
        log_data = reader.linux_input_slack(
            self.current_directory + "/data/slackware/", self.starting_date,
            self.ending_date)
        output = capturedOutput.getvalue()
        capturedOutput.close()
        sys.stdout = sys.__stdout__

        #See https://docs.python.org/2/library/re.html for more details.
        # string 'Working on: /any_valid_path/IRCLogParser/test/unit-test/test_lib/test_in_out/data/log/2013/01/04/#kubuntu-devel.txt\n' is replaced by
        # 'Working on: IRCLogParser/test/unit-test/test_lib/test_in_out/data/log/2013/01/04/#kubuntu-devel.txt\n'
        output = re.sub(r'(?P<begin>.+ )/.+/(?P<constant>IRCLogParser/.+\n)',
                        r'\g<begin>\g<constant>', output)
        self.assertEqual(log_data, self.log_data)
        self.assertEqual(expected_captured_output, output)
コード例 #21
0
 def setUp(self):
     self.log_data = util.load_from_disk(current_directory +
                                         "/data/log_data")
     self.nicks = util.load_from_disk(current_directory + "/data/nicks")
     self.nick_same_list = util.load_from_disk(current_directory +
                                               "/data/nick_same_list")
コード例 #22
0
 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.starting_date = "2013-1-1"
     self.ending_date = "2013-1-31"
コード例 #23
0
 def test_load_from_disk(self):
     nicks = util.load_from_disk(current_directory + '/data/nicks')
     assert nicks == self.expected_nicks, "Failure to load from disk."
コード例 #24
0
ファイル: test_util.py プロジェクト: soundarya98/IRCLogParser
 def test_load_from_disk(self):
     nicks = util.load_from_disk(self.current_directory + '/data/nicks')
     self.assertEqual(nicks, self.expected_nicks,
                      "Failure to load from disk.")
コード例 #25
0
 def setUp(self):
     self.log_data = util.load_from_disk(current_directory +
                                         "/data/log_data")
     self.starting_date = "2013-1-1"
     self.ending_date = "2013-1-31"