# Path: lib/analysis/user.py
# def nick_change_graph(log_dict, DAY_BY_DAY_ANALYSIS=False):
# def top_keywords_for_nick(user_keyword_freq_dict, nick, threshold, min_words_spoken):
# def keywords(log_dict, nicks, nick_same_list):
#     def get_nick_receiver(nick_receiver, rec, nick_to_compare, nick_name, nicks, nick_same_list):
# def keywords_clusters(log_dict, nicks, nick_same_list, output_directory, out_file_name):
#     def build_centroid(km):
# def extended_stop_words(nicks_for_stop_words, stop_word_without_apostrophe):


import unittest
import lib.config as config
import lib.util as util
import os
import StringIO
import sys
import filecmp
import networkx as nx
from lib.analysis import user
from mock import patch

    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 tearDown(self):
        self.current_directory = None
        self.test_data_dir = None
        self.log_data = None
        self.nicks = None
        self.nick_same_list = None


    @patch("lib.config.DEBUGGER", new = True)
    @patch("lib.config.PRINT_WORDS", new = True)
    @patch("lib.config.KEYWORDS_THRESHOLD", new = 0.01)
    @patch("lib.config.KEYWORDS_MIN_WORDS", new = 100)
    def test_keywords(self):
        expected_keywords_filtered = util.load_from_disk(self.test_data_dir + "keywords/keywords_filtered")
        expected_user_keyword_freq_dict = util.load_from_disk(self.test_data_dir + "user_keyword_freq_dict")
        expected_user_words_dict = util.load_from_disk(self.test_data_dir + "keywords/user_words_dict")
        expected_nicks_for_stop_words = util.load_from_disk(self.test_data_dir + "keywords/nicks_for_stop_words")
        expected_sorted_keywords_for_channels = util.load_from_disk(self.test_data_dir + "keywords/sorted_keywords_for_channels")
        expected_captured_output = util.load_from_disk(self.current_directory +  "/data/user_test/keywords/stdout_captured_output")
        captured_output = StringIO.StringIO()
        sys.stdout = captured_output

# Path: lib/analysis/user.py
# def nick_change_graph(log_dict, DAY_BY_DAY_ANALYSIS=False):
# def top_keywords_for_nick(user_keyword_freq_dict, nick, threshold, min_words_spoken):
# def keywords(log_dict, nicks, nick_same_list):
#     def get_nick_receiver(nick_receiver, rec, nick_to_compare, nick_name, nicks, nick_same_list):
# def keywords_clusters(log_dict, nicks, nick_same_list, output_directory, out_file_name):
#     def build_centroid(km):
# def extended_stop_words(nicks_for_stop_words, stop_word_without_apostrophe):


# Path: test/integration-test/test_lib/test_analysis/test_user.py
import unittest
import lib.config as config
import lib.util as util
import os
import StringIO
import sys
import filecmp
import networkx as nx
from lib.analysis import user
from mock import patch


    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 tearDown(self):
        self.current_directory = None
        self.test_data_dir = None
        self.log_data = None
        self.nicks = None
        self.nick_same_list = None


    @patch("lib.config.DEBUGGER", new = True)
    @patch("lib.config.PRINT_WORDS", new = True)
    @patch("lib.config.KEYWORDS_THRESHOLD", new = 0.01)
    @patch("lib.config.KEYWORDS_MIN_WORDS", new = 100)
    def test_keywords(self):
        expected_keywords_filtered = util.load_from_disk(self.test_data_dir + "keywords/keywords_filtered")
        expected_user_keyword_freq_dict = util.load_from_disk(self.test_data_dir + "user_keyword_freq_dict")
        expected_user_words_dict = util.load_from_disk(self.test_data_dir + "keywords/user_words_dict")
        expected_nicks_for_stop_words = util.load_from_disk(self.test_data_dir + "keywords/nicks_for_stop_words")
        expected_sorted_keywords_for_channels = util.load_from_disk(self.test_data_dir + "keywords/sorted_keywords_for_channels")
        expected_captured_output = util.load_from_disk(self.current_directory +  "/data/user_test/keywords/stdout_captured_output")
        captured_output = StringIO.StringIO()
        sys.stdout = captured_output

        keywords_filtered, user_keyword_freq_dict, user_words_dict, nicks_for_stop_words, sorted_keywords_for_channels = user.keywords(self.log_data , self.nicks, self.nick_same_list)