# Path: lib/slack/analysis/network.py
# def message_number_graph(log_dict, nicks, nick_same_list, DAY_BY_DAY_ANALYSIS=False):
#     def msg_no_analysis_helper(rec_list, nick_sender, nick, conn_comp_list,conversations,today_conversation):
#     def message_no_add_egde(message_graph, conversation):
# def filter_edge_list(edgelist_file_loc, max_hash, how_many_top):
# def degree_analysis_on_graph(nx_graph, date=None):
#     def nodes_with_degree_populator(degree_values, label): 
#     def give_userlist_where_degree_helper(degree_dict, degree):
#     def raw_node_append(nodes, raw, degree_type):        
# def message_time_graph(log_dict, nicks, nick_same_list, DAY_BY_DAY_ANALYSIS=False):
#     def compare_spliced_nick(nick_to_compare, spliced_nick, nick_name, line):
# def message_number_bins_csv(log_dict, nicks, nick_same_list):
#     def bin_increment(nick_name, messager, nick_spliced, bins, bin_index):
# def degree_node_number_csv(log_dict, nicks, nick_same_list):
#     def format_degree_list(degree_list, max_range, degree_type):
# def nick_receiver_from_conn_comp(nick, conn_comp_list):
# def identify_hubs_and_experts(log_dict, nicks, nick_same_list):
#     G = util.to_graph(nick_same_list)
#     G = util.to_graph(nick_same_list)


import unittest
import networkx as nx
import lib.slack.util as util
import lib.slack.config as config 
import os, mock, sys
import StringIO
from lib.slack.analysis import network
from networkx.algorithms.components.connected import connected_components
from numpy.testing import assert_array_equal
    @mock.patch('lib.slack.config.MINIMUM_NICK_LENGTH', 3)
    @mock.patch('lib.slack.config.DEBUGGER', True)
    @mock.patch('lib.slack.util.to_graph', autospec=True)
    @mock.patch('lib.slack.util.create_connected_nick_list', autospec=True)
    @mock.patch('lib.slack.util.check_if_msg_line', autospec=True)
    @mock.patch('lib.slack.util.get_nick_representative', autospec=True)
    @mock.patch('lib.slack.util.get_year_month_day', autospec=True)
    @mock.patch('lib.slack.util.get_nick_sen_rec', autospec=True)
    @mock.patch('lib.slack.util.correctLastCharCR', autospec=True)
    @mock.patch('lib.slack.util.rec_list_splice', autospec=True)
    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(self.test_data_dir + "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(self.test_data_dir + "message_number_graph/rec_list_splice")
        mock_create_connected_nick_list.return_value = util.load_from_disk(self.test_data_dir + "message_number_graph/conn_comp_list")
        #mock_correct_last_char_list.side_effect = util.load_from_disk(self.test_data_dir + "message_number_graph/correct_last_char_list")
        mock_check_if_msg_line.side_effect = util.load_from_disk(self.test_data_dir + "message_number_graph/check_if_msg_line")
        mock_correctLastCharCR.side_effect = util.load_from_disk(self.test_data_dir + "message_number_graph/correctLastCharCR")
        mock_get_nick_sen_rec.side_effect = util.load_from_disk(self.test_data_dir + "message_number_graph/get_nick_sen_rec")
        #mock_extend_conversation_list.side_effect = util.load_from_disk(self.test_data_dir + "message_number_graph/extend_conversation_list")
        mock_get_nick_representative.side_effect = util.load_from_disk(self.test_data_dir + "message_number_graph/get_nick_representative")
        mock_get_year_month_day.side_effect = util.load_from_disk(self.test_data_dir + "message_number_graph/get_year_month_day")
        
        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput
        

# Path: lib/slack/analysis/network.py
# def message_number_graph(log_dict, nicks, nick_same_list, DAY_BY_DAY_ANALYSIS=False):
#     def msg_no_analysis_helper(rec_list, nick_sender, nick, conn_comp_list,conversations,today_conversation):
#     def message_no_add_egde(message_graph, conversation):
# def filter_edge_list(edgelist_file_loc, max_hash, how_many_top):
# def degree_analysis_on_graph(nx_graph, date=None):
#     def nodes_with_degree_populator(degree_values, label): 
#     def give_userlist_where_degree_helper(degree_dict, degree):
#     def raw_node_append(nodes, raw, degree_type):        
# def message_time_graph(log_dict, nicks, nick_same_list, DAY_BY_DAY_ANALYSIS=False):
#     def compare_spliced_nick(nick_to_compare, spliced_nick, nick_name, line):
# def message_number_bins_csv(log_dict, nicks, nick_same_list):
#     def bin_increment(nick_name, messager, nick_spliced, bins, bin_index):
# def degree_node_number_csv(log_dict, nicks, nick_same_list):
#     def format_degree_list(degree_list, max_range, degree_type):
# def nick_receiver_from_conn_comp(nick, conn_comp_list):
# def identify_hubs_and_experts(log_dict, nicks, nick_same_list):
#     G = util.to_graph(nick_same_list)
#     G = util.to_graph(nick_same_list)


# Path: test/unit-test/test_slack/test_lib/test_analysis/test_network.py
import unittest
import networkx as nx
import lib.slack.util as util
import lib.slack.config as config 
import os, mock, sys
import StringIO
from lib.slack.analysis import network
from networkx.algorithms.components.connected import connected_components
from numpy.testing import assert_array_equal

    @mock.patch('lib.slack.config.MINIMUM_NICK_LENGTH', 3)
    @mock.patch('lib.slack.config.DEBUGGER', True)
    @mock.patch('lib.slack.util.to_graph', autospec=True)
    @mock.patch('lib.slack.util.create_connected_nick_list', autospec=True)
    @mock.patch('lib.slack.util.check_if_msg_line', autospec=True)
    @mock.patch('lib.slack.util.get_nick_representative', autospec=True)
    @mock.patch('lib.slack.util.get_year_month_day', autospec=True)
    @mock.patch('lib.slack.util.get_nick_sen_rec', autospec=True)
    @mock.patch('lib.slack.util.correctLastCharCR', autospec=True)
    @mock.patch('lib.slack.util.rec_list_splice', autospec=True)
    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(self.test_data_dir + "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(self.test_data_dir + "message_number_graph/rec_list_splice")
        mock_create_connected_nick_list.return_value = util.load_from_disk(self.test_data_dir + "message_number_graph/conn_comp_list")
        #mock_correct_last_char_list.side_effect = util.load_from_disk(self.test_data_dir + "message_number_graph/correct_last_char_list")
        mock_check_if_msg_line.side_effect = util.load_from_disk(self.test_data_dir + "message_number_graph/check_if_msg_line")
        mock_correctLastCharCR.side_effect = util.load_from_disk(self.test_data_dir + "message_number_graph/correctLastCharCR")
        mock_get_nick_sen_rec.side_effect = util.load_from_disk(self.test_data_dir + "message_number_graph/get_nick_sen_rec")
        #mock_extend_conversation_list.side_effect = util.load_from_disk(self.test_data_dir + "message_number_graph/extend_conversation_list")
        mock_get_nick_representative.side_effect = util.load_from_disk(self.test_data_dir + "message_number_graph/get_nick_representative")
        mock_get_year_month_day.side_effect = util.load_from_disk(self.test_data_dir + "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)