# Path: pypi_portal/application.py
# def get_config(config_class_string, yaml_files=None):
#     """Load the Flask config from a class.
# 
#     Positional arguments:
#     config_class_string -- string representation of a configuration class that will be loaded (e.g.
#         'pypi_portal.config.Production').
#     yaml_files -- List of YAML files to load. This is for testing, leave None in dev/production.
# 
#     Returns:
#     A class object to be fed into app.config.from_object().
#     """
#     config_module, config_class = config_class_string.rsplit('.', 1)
#     config_class_object = getattr(import_module(config_module), config_class)
#     config_obj = config_class_object()
# 
#     # Expand some options.
#     celery_fmt = 'pypi_portal.tasks.{}'
#     db_fmt = 'pypi_portal.models.{}'
#     if getattr(config_obj, 'CELERY_IMPORTS', False):
#         config_obj.CELERY_IMPORTS = [celery_fmt.format(m) for m in config_obj.CELERY_IMPORTS]
#     for definition in getattr(config_obj, 'CELERYBEAT_SCHEDULE', dict()).values():
#         definition.update(task=celery_fmt.format(definition['task']))
#     if getattr(config_obj, 'DB_MODELS_IMPORTS', False):
#         config_obj.DB_MODELS_IMPORTS = [db_fmt.format(m) for m in config_obj.DB_MODELS_IMPORTS]
#     #for script_name, script_file in getattr(config_obj, 'REDIS_SCRIPTS', dict()).items():
#     #    config_obj.REDIS_SCRIPTS[script_name] = os.path.join(REDIS_SCRIPTS_FOLDER, script_file)
# 
#     # Load additional configuration settings.
#     yaml_files = yaml_files or [f for f in [
#         os.path.join('/', 'etc', 'pypi_portal', 'config.yml'),
#         os.path.abspath(os.path.join(APP_ROOT_FOLDER, '..', 'config.yml')),
#         os.path.join(APP_ROOT_FOLDER, 'config.yml'),
#     ] if os.path.exists(f)]
#     additional_dict = dict()
#     for y in yaml_files:
#         with open(y) as f:
#             additional_dict.update(load(f.read()))
# 
#     # Merge the rest into the Flask app config.
#     for key, value in additional_dict.items():
#         setattr(config_obj, key, value)
# 
#     return config_obj


from pypi_portal.application import get_config


def test_get_config_yaml(tmpdir):
    f = tmpdir.join('config.yml')
    f.write('TEST_VAR: true')

    config = get_config('pypi_portal.config.Testing', yaml_files=[str(f)])


# Path: pypi_portal/application.py
# def get_config(config_class_string, yaml_files=None):
#     """Load the Flask config from a class.
# 
#     Positional arguments:
#     config_class_string -- string representation of a configuration class that will be loaded (e.g.
#         'pypi_portal.config.Production').
#     yaml_files -- List of YAML files to load. This is for testing, leave None in dev/production.
# 
#     Returns:
#     A class object to be fed into app.config.from_object().
#     """
#     config_module, config_class = config_class_string.rsplit('.', 1)
#     config_class_object = getattr(import_module(config_module), config_class)
#     config_obj = config_class_object()
# 
#     # Expand some options.
#     celery_fmt = 'pypi_portal.tasks.{}'
#     db_fmt = 'pypi_portal.models.{}'
#     if getattr(config_obj, 'CELERY_IMPORTS', False):
#         config_obj.CELERY_IMPORTS = [celery_fmt.format(m) for m in config_obj.CELERY_IMPORTS]
#     for definition in getattr(config_obj, 'CELERYBEAT_SCHEDULE', dict()).values():
#         definition.update(task=celery_fmt.format(definition['task']))
#     if getattr(config_obj, 'DB_MODELS_IMPORTS', False):
#         config_obj.DB_MODELS_IMPORTS = [db_fmt.format(m) for m in config_obj.DB_MODELS_IMPORTS]
#     #for script_name, script_file in getattr(config_obj, 'REDIS_SCRIPTS', dict()).items():
#     #    config_obj.REDIS_SCRIPTS[script_name] = os.path.join(REDIS_SCRIPTS_FOLDER, script_file)
# 
#     # Load additional configuration settings.
#     yaml_files = yaml_files or [f for f in [
#         os.path.join('/', 'etc', 'pypi_portal', 'config.yml'),
#         os.path.abspath(os.path.join(APP_ROOT_FOLDER, '..', 'config.yml')),
#         os.path.join(APP_ROOT_FOLDER, 'config.yml'),
#     ] if os.path.exists(f)]
#     additional_dict = dict()
#     for y in yaml_files:
#         with open(y) as f:
#             additional_dict.update(load(f.read()))
# 
#     # Merge the rest into the Flask app config.
#     for key, value in additional_dict.items():
#         setattr(config_obj, key, value)
# 
#     return config_obj


# Path: tests/test_application.py
from pypi_portal.application import get_config



def test_get_config_yaml(tmpdir):
    f = tmpdir.join('config.yml')
    f.write('TEST_VAR: true')

    config = get_config('pypi_portal.config.Testing', yaml_files=[str(f)])


    assert config.TEST_VAR is True