# 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

    
class NetworkTest(unittest.TestCase):

    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")

    def tearDown(self):
        self.current_directory = None
        self.test_data_dir = None
        self.log_data = None
        self.nicks = None
        self.nick_same_list = None
        
    @mock.patch('lib.slack.config.MAX_EXPECTED_DIFF_NICKS', 5000)
    @mock.patch('lib.slack.config.THRESHOLD_MESSAGE_NUMBER_GRAPH', 0)
    @mock.patch('lib.slack.config.MINIMUM_NICK_LENGTH', 3)
    @mock.patch('lib.slack.config.DEBUGGER', True)
    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
        

# 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/integration-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


    
class NetworkTest(unittest.TestCase):

    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")

    def tearDown(self):
        self.current_directory = None
        self.test_data_dir = None
        self.log_data = None
        self.nicks = None
        self.nick_same_list = None
        
    @mock.patch('lib.slack.config.MAX_EXPECTED_DIFF_NICKS', 5000)
    @mock.patch('lib.slack.config.THRESHOLD_MESSAGE_NUMBER_GRAPH', 0)
    @mock.patch('lib.slack.config.MINIMUM_NICK_LENGTH', 3)
    @mock.patch('lib.slack.config.DEBUGGER', True)
    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)