# Path: rvic/core/pycompat.py
# def iteritems(d):
# def itervalues(d):
# def iteritems(d):
# def itervalues(d):
# 
# Path: rvic/convert.py
# def convert(config_file):
# 
#     # ---------------------------------------------------------------- #
#     # Initilize
#     dom_data, new_dom_data, outlets, config_dict, \
#         directories = uhs2param_init(config_file)
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Get main logger
#     log = getLogger(LOG_NAME)
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Run
#     log.info('getting outlets now')
#     outlets = uhs2param_run(dom_data, outlets, config_dict)
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Finally, make the parameter file
#     uhs2param_final(outlets, dom_data, new_dom_data, config_dict, directories)
#     # ---------------------------------------------------------------- #
#     return
# 
# Path: rvic/convolution.py
# def convolution(config):
#     '''
#     Top level driver for RVIC convolution model.
# 
#     Parameters
#     ----------
#     config : str or dict.
#         Path to RVIC convolution configuration file or dictionary of
#         configuration options.
#     '''
# 
#     # ---------------------------------------------------------------- #
#     # Initilize
#     hist_tapes, data_model, rout_var, \
#         time_handle, directories = convolution_init(config)
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Run
#     time_handle, hist_tapes = convolution_run(hist_tapes, data_model, rout_var,
#                                               time_handle, directories)
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Finalize
#     convolution_final(time_handle, hist_tapes)
#     # ---------------------------------------------------------------- #
#     return
# 
# Path: rvic/parameters.py
# def parameters(config, numofproc=1):
#     '''
#     Top level function for RVIC parameter generation function.
# 
#     Parameters
#     ----------
#     config : str or dict
#         Path to RVIC parameters configuration file or dictionary of
#         configuration options.
#     numofproc : int
#         Number of processors to use when developing RVIC parameters.
#     '''
# 
#     # ---------------------------------------------------------------- #
#     # Initilize
#     uh_box, fdr_data, fdr_vatts, dom_data, \
#         outlets, config_dict, directories = gen_uh_init(config)
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Get main logger
#     log = getLogger(LOG_NAME)
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Run
#     if numofproc > 1:
#         from multiprocessing import Pool
#         pool = Pool(processes=numofproc)
#         status = []
# 
#         for i, (key, outlet) in enumerate(iteritems(outlets)):
#             log.info('On Outlet #%s of %s', i + 1, len(outlets))
#             stat = pool.apply_async(gen_uh_run,
#                                     (uh_box, fdr_data, fdr_vatts,
#                                      dom_data, outlet, config_dict,
#                                      directories),
#                                     callback=store_result,
#                                     error_callback=error)
#             # Store the result
#             status.append(stat)
# 
#         # Close the pool
#         pool.close()
# 
#         # Check that everything worked
#         [stat.get() for stat in status]
# 
#         pool.join()
# 
#         outlets = OrderedDict(sorted(results.items(), reverse=True))
#     else:
#         for i, (key, outlet) in enumerate(iteritems(outlets)):
#             outlet = gen_uh_run(uh_box, fdr_data, fdr_vatts, dom_data, outlet,
#                                 config_dict, directories)
# 
#     if not outlets:
#         raise ValueError('outlets in parameters are empty')
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Finally, make the parameter file
#     gen_uh_final(outlets, dom_data, config_dict, directories)
#     # ---------------------------------------------------------------- #
#     return
# 
# Path: rvic/core/config.py
# def read_config(config_file):
#     '''
#     Return a dictionary with subdictionaries of all configFile options/values
#     '''
#     config = SafeConfigParser()
#     config.optionxform = str
#     config.read(config_file)
#     sections = config.sections()
#     dict1 = OrderedDict()
#     for section in sections:
#         options = config.options(section)
#         dict2 = OrderedDict()
#         for option in options:
#             dict2[option] = config_type(config.get(section, option))
#         dict1[section] = dict2
#     return dict1
# 
# Path: rvic/core/pycompat.py
# def iteritems(d):
# def itervalues(d):
# def iteritems(d):
# def itervalues(d):


import os
import sys
import textwrap
import argparse
import pytest
import cProfile
import pstats
import io
from rvic.core.pycompat import OrderedDict
from rvic import convert, convolution, parameters
from rvic.core.config import read_config
from rvic.core.pycompat import py3, iteritems
    # run tests
    num_tests = len(list(config_dict.keys()))

    test_outcomes = OrderedDict()

    for i, (test, test_dict) in enumerate(iteritems(config_dict)):
        print(''.center(100, '-'))
        print('Starting Test #{0} of {1}: {2}'.format(i + 1, num_tests,
                                                      test).center(100))
        desc = textwrap.fill(', '.join(test_dict['description']), 100)
        print('Description: {0}'.format(desc))
        print(''.center(100, '-'))

        if 'processors' in test_dict:
            numofproc = test_dict['processors']
        else:
            numofproc = 1

        pr = cProfile.Profile()
        pr.enable()

        if test_dict['function'] == 'convert':
            try:
                convert.convert(test_dict['config_file'])
                test_outcomes[test] = 'Passed'
            except Exception as e:
                print('Error in conversion example: {0}'.format(test))
                test_outcomes[test] = 'Failed: {0}'.format(e)
        elif test_dict['function'] == 'convolution':
            try:

# Path: rvic/core/pycompat.py
# def iteritems(d):
# def itervalues(d):
# def iteritems(d):
# def itervalues(d):
# 
# Path: rvic/convert.py
# def convert(config_file):
# 
#     # ---------------------------------------------------------------- #
#     # Initilize
#     dom_data, new_dom_data, outlets, config_dict, \
#         directories = uhs2param_init(config_file)
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Get main logger
#     log = getLogger(LOG_NAME)
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Run
#     log.info('getting outlets now')
#     outlets = uhs2param_run(dom_data, outlets, config_dict)
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Finally, make the parameter file
#     uhs2param_final(outlets, dom_data, new_dom_data, config_dict, directories)
#     # ---------------------------------------------------------------- #
#     return
# 
# Path: rvic/convolution.py
# def convolution(config):
#     '''
#     Top level driver for RVIC convolution model.
# 
#     Parameters
#     ----------
#     config : str or dict.
#         Path to RVIC convolution configuration file or dictionary of
#         configuration options.
#     '''
# 
#     # ---------------------------------------------------------------- #
#     # Initilize
#     hist_tapes, data_model, rout_var, \
#         time_handle, directories = convolution_init(config)
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Run
#     time_handle, hist_tapes = convolution_run(hist_tapes, data_model, rout_var,
#                                               time_handle, directories)
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Finalize
#     convolution_final(time_handle, hist_tapes)
#     # ---------------------------------------------------------------- #
#     return
# 
# Path: rvic/parameters.py
# def parameters(config, numofproc=1):
#     '''
#     Top level function for RVIC parameter generation function.
# 
#     Parameters
#     ----------
#     config : str or dict
#         Path to RVIC parameters configuration file or dictionary of
#         configuration options.
#     numofproc : int
#         Number of processors to use when developing RVIC parameters.
#     '''
# 
#     # ---------------------------------------------------------------- #
#     # Initilize
#     uh_box, fdr_data, fdr_vatts, dom_data, \
#         outlets, config_dict, directories = gen_uh_init(config)
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Get main logger
#     log = getLogger(LOG_NAME)
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Run
#     if numofproc > 1:
#         from multiprocessing import Pool
#         pool = Pool(processes=numofproc)
#         status = []
# 
#         for i, (key, outlet) in enumerate(iteritems(outlets)):
#             log.info('On Outlet #%s of %s', i + 1, len(outlets))
#             stat = pool.apply_async(gen_uh_run,
#                                     (uh_box, fdr_data, fdr_vatts,
#                                      dom_data, outlet, config_dict,
#                                      directories),
#                                     callback=store_result,
#                                     error_callback=error)
#             # Store the result
#             status.append(stat)
# 
#         # Close the pool
#         pool.close()
# 
#         # Check that everything worked
#         [stat.get() for stat in status]
# 
#         pool.join()
# 
#         outlets = OrderedDict(sorted(results.items(), reverse=True))
#     else:
#         for i, (key, outlet) in enumerate(iteritems(outlets)):
#             outlet = gen_uh_run(uh_box, fdr_data, fdr_vatts, dom_data, outlet,
#                                 config_dict, directories)
# 
#     if not outlets:
#         raise ValueError('outlets in parameters are empty')
#     # ---------------------------------------------------------------- #
# 
#     # ---------------------------------------------------------------- #
#     # Finally, make the parameter file
#     gen_uh_final(outlets, dom_data, config_dict, directories)
#     # ---------------------------------------------------------------- #
#     return
# 
# Path: rvic/core/config.py
# def read_config(config_file):
#     '''
#     Return a dictionary with subdictionaries of all configFile options/values
#     '''
#     config = SafeConfigParser()
#     config.optionxform = str
#     config.read(config_file)
#     sections = config.sections()
#     dict1 = OrderedDict()
#     for section in sections:
#         options = config.options(section)
#         dict2 = OrderedDict()
#         for option in options:
#             dict2[option] = config_type(config.get(section, option))
#         dict1[section] = dict2
#     return dict1
# 
# Path: rvic/core/pycompat.py
# def iteritems(d):
# def itervalues(d):
# def iteritems(d):
# def itervalues(d):


# Path: tests/run_tests.py
import os
import sys
import textwrap
import argparse
import pytest
import cProfile
import pstats
import io
from rvic.core.pycompat import OrderedDict
from rvic import convert, convolution, parameters
from rvic.core.config import read_config
from rvic.core.pycompat import py3, iteritems

    # run tests
    num_tests = len(list(config_dict.keys()))

    test_outcomes = OrderedDict()

    for i, (test, test_dict) in enumerate(iteritems(config_dict)):
        print(''.center(100, '-'))
        print('Starting Test #{0} of {1}: {2}'.format(i + 1, num_tests,
                                                      test).center(100))
        desc = textwrap.fill(', '.join(test_dict['description']), 100)
        print('Description: {0}'.format(desc))
        print(''.center(100, '-'))

        if 'processors' in test_dict:
            numofproc = test_dict['processors']
        else:
            numofproc = 1

        pr = cProfile.Profile()
        pr.enable()

        if test_dict['function'] == 'convert':
            try:
                convert.convert(test_dict['config_file'])
                test_outcomes[test] = 'Passed'
            except Exception as e:
                print('Error in conversion example: {0}'.format(test))
                test_outcomes[test] = 'Failed: {0}'.format(e)
        elif test_dict['function'] == 'convolution':
            try:

                convolution.convolution(test_dict['config_file'])