# Path: cptm/utils/experiment.py
# def load_config(fName):
#     with open(fName) as f:
#         config = json.load(f)
# 
#     logger.debug('configuration of experiment: ')
#     params = ['{}: {}'.format(p, v) for p, v in config.iteritems()]
#     for p in params:
#         logger.debug(p)
# 
#     params = {}
#     params['inputData'] = config.get('inputData')
#     params['outDir'] = config.get('outDir', '/{}')
#     params['testSplit'] = config.get('testSplit', 20)
#     params['minFreq'] = config.get('minFreq')
#     params['removeTopTF'] = config.get('removeTopTF')
#     params['removeTopDF'] = config.get('removeTopDF')
#     params['nIter'] = config.get('nIter', 200)
#     params['beta'] = config.get('beta', 0.02)
#     params['beta_o'] = config.get('beta_o', 0.02)
#     params['expNumTopics'] = config.get('expNumTopics', range(20, 201, 20))
#     params['nTopics'] = config.get('nTopics')
#     params['nProcesses'] = config.get('nProcesses', None)
#     params['topicLines'] = config.get('topicLines', [0])
#     params['opinionLines'] = config.get('opinionLines', [1])
#     params['sampleEstimateStart'] = config.get('sampleEstimateStart')
#     params['sampleEstimateEnd'] = config.get('sampleEstimateEnd')
# 
#     return params
# 
# def add_parameter(name, value, fName):
#     with open(fName) as f:
#         config = json.load(f)
#     config[name] = value
#     with open(fName, 'w') as f:
#         json.dump(config, f)
# 
# def thetaFileName(params):
#     nTopics = params.get('nTopics')
#     return os.path.join(params.get('outDir').format(''),
#                         'theta_{}.csv'.format(nTopics))
# 
# def topicFileName(params):
#     nTopics = params.get('nTopics')
#     return os.path.join(params.get('outDir').format(''),
#                         'topics_{}.csv'.format(nTopics))
# 
# def opinionFileName(params, name):
#     nTopics = params.get('nTopics')
#     return os.path.join(params.get('outDir').format(''),
#                         'opinions_{}_{}.csv'.format(name, nTopics))
# 
# def tarFileName(params):
#     nTopics = params.get('nTopics')
#     name = experimentName(params)
#     return os.path.join(params.get('outDir').format(''),
#                         '{}_{}.tgz'.format(name, nTopics))
# 
# def experimentName(params):
#     fName = params.get('outDir')
#     fName = fName.replace('/{}', '')
#     _p, name = os.path.split(fName)
#     return name


from nose.tools import assert_equal, assert_false
from os import remove
from os.path import join
from json import dump
from cptm.utils.experiment import load_config, add_parameter, thetaFileName, \
    topicFileName, opinionFileName, tarFileName, experimentName

def test_load_config_default_values():
    params = {}
    params['inputData'] = None
    params['outDir'] = '/{}'
    params['testSplit'] = 20
    params['minFreq'] = None
    params['removeTopTF'] = None
    params['removeTopDF'] = None
    params['nIter'] = 200
    params['beta'] = 0.02
    params['beta_o'] = 0.02
    params['expNumTopics'] = range(20, 201, 20)
    params['nTopics'] = None
    params['nProcesses'] = None
    params['topicLines'] = [0]
    params['opinionLines'] = [1]
    params['sampleEstimateStart'] = None
    params['sampleEstimateEnd'] = None

    for p, v in params.iteritems():
        yield assert_equal, v, config[p]


def test_add_parameter():
    pName = 'nTopics'

    yield assert_false, hasattr(config, pName)

    add_parameter(pName, nTopics, jsonFile)

# Path: cptm/utils/experiment.py
# def load_config(fName):
#     with open(fName) as f:
#         config = json.load(f)
# 
#     logger.debug('configuration of experiment: ')
#     params = ['{}: {}'.format(p, v) for p, v in config.iteritems()]
#     for p in params:
#         logger.debug(p)
# 
#     params = {}
#     params['inputData'] = config.get('inputData')
#     params['outDir'] = config.get('outDir', '/{}')
#     params['testSplit'] = config.get('testSplit', 20)
#     params['minFreq'] = config.get('minFreq')
#     params['removeTopTF'] = config.get('removeTopTF')
#     params['removeTopDF'] = config.get('removeTopDF')
#     params['nIter'] = config.get('nIter', 200)
#     params['beta'] = config.get('beta', 0.02)
#     params['beta_o'] = config.get('beta_o', 0.02)
#     params['expNumTopics'] = config.get('expNumTopics', range(20, 201, 20))
#     params['nTopics'] = config.get('nTopics')
#     params['nProcesses'] = config.get('nProcesses', None)
#     params['topicLines'] = config.get('topicLines', [0])
#     params['opinionLines'] = config.get('opinionLines', [1])
#     params['sampleEstimateStart'] = config.get('sampleEstimateStart')
#     params['sampleEstimateEnd'] = config.get('sampleEstimateEnd')
# 
#     return params
# 
# def add_parameter(name, value, fName):
#     with open(fName) as f:
#         config = json.load(f)
#     config[name] = value
#     with open(fName, 'w') as f:
#         json.dump(config, f)
# 
# def thetaFileName(params):
#     nTopics = params.get('nTopics')
#     return os.path.join(params.get('outDir').format(''),
#                         'theta_{}.csv'.format(nTopics))
# 
# def topicFileName(params):
#     nTopics = params.get('nTopics')
#     return os.path.join(params.get('outDir').format(''),
#                         'topics_{}.csv'.format(nTopics))
# 
# def opinionFileName(params, name):
#     nTopics = params.get('nTopics')
#     return os.path.join(params.get('outDir').format(''),
#                         'opinions_{}_{}.csv'.format(name, nTopics))
# 
# def tarFileName(params):
#     nTopics = params.get('nTopics')
#     name = experimentName(params)
#     return os.path.join(params.get('outDir').format(''),
#                         '{}_{}.tgz'.format(name, nTopics))
# 
# def experimentName(params):
#     fName = params.get('outDir')
#     fName = fName.replace('/{}', '')
#     _p, name = os.path.split(fName)
#     return name


# Path: cptm/tests/test_utils_experiment.py
from nose.tools import assert_equal, assert_false
from os import remove
from os.path import join
from json import dump
from cptm.utils.experiment import load_config, add_parameter, thetaFileName, \
    topicFileName, opinionFileName, tarFileName, experimentName


def test_load_config_default_values():
    params = {}
    params['inputData'] = None
    params['outDir'] = '/{}'
    params['testSplit'] = 20
    params['minFreq'] = None
    params['removeTopTF'] = None
    params['removeTopDF'] = None
    params['nIter'] = 200
    params['beta'] = 0.02
    params['beta_o'] = 0.02
    params['expNumTopics'] = range(20, 201, 20)
    params['nTopics'] = None
    params['nProcesses'] = None
    params['topicLines'] = [0]
    params['opinionLines'] = [1]
    params['sampleEstimateStart'] = None
    params['sampleEstimateEnd'] = None

    for p, v in params.iteritems():
        yield assert_equal, v, config[p]


def test_add_parameter():
    pName = 'nTopics'

    yield assert_false, hasattr(config, pName)

    add_parameter(pName, nTopics, jsonFile)

    config2 = load_config(jsonFile)