# 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_thetaFileName():
    config['nTopics'] = nTopics
    fName = thetaFileName(config)
    assert_equal(fName, '/theta_{}.csv'.format(nTopics))


def test_topicFileName():
    config['nTopics'] = nTopics
    fName = topicFileName(config)
    assert_equal(fName, '/topics_{}.csv'.format(nTopics))


def test_opinionFileName():
    config['nTopics'] = nTopics
    perspectives = ['p0', 'p1', 'p2']
    for p in perspectives:
        fName = opinionFileName(config, p)
        yield assert_equal, fName, '/opinions_{}_{}.csv'.format(p, nTopics)


def test_experimentName():
    config['outDir'] = '/tmp/test/{}'

    assert_equal('test', experimentName(config))


def test_tarFileName():
    config['outDir'] = '/{}'
    config['nTopics'] = nTopics

# 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_thetaFileName():
    config['nTopics'] = nTopics
    fName = thetaFileName(config)
    assert_equal(fName, '/theta_{}.csv'.format(nTopics))


def test_topicFileName():
    config['nTopics'] = nTopics
    fName = topicFileName(config)
    assert_equal(fName, '/topics_{}.csv'.format(nTopics))


def test_opinionFileName():
    config['nTopics'] = nTopics
    perspectives = ['p0', 'p1', 'p2']
    for p in perspectives:
        fName = opinionFileName(config, p)
        yield assert_equal, fName, '/opinions_{}_{}.csv'.format(p, nTopics)


def test_experimentName():
    config['outDir'] = '/tmp/test/{}'

    assert_equal('test', experimentName(config))


def test_tarFileName():
    config['outDir'] = '/{}'
    config['nTopics'] = nTopics

    name = experimentName(config)