Beispiel #1
0
 def test_empty_yaml_mapping_from_envvar(self):
     os.environ['EASY_CONFIG'] = ''
     with pytest.raises(IOError) as exc:
         yaml_mapping('EASY_CONFIG', silent=False, is_envvar=True)
     assert str(
         exc.value) == ("[Errno 2] Unable to load configuration file "
                        "(No such file or directory): ''")
Beispiel #2
0
 def test_empty_yaml_mapping(self):
     with pytest.raises(IOError) as exc:
         yaml_mapping('')
     assert str(exc.value) == (
         "[Errno 2] Unable to load configuration file "
         "(No such file or directory): ''"
     )
Beispiel #3
0
 def test_empty_yaml_mapping_from_envvar(self):
     os.environ['EASY_CONFIG'] = ''
     with pytest.raises(IOError) as exc:
         yaml_mapping('EASY_CONFIG', silent=False, is_envvar=True)
     assert str(exc.value) == (
         "[Errno 2] Unable to load configuration file "
         "(No such file or directory): ''"
     )
Beispiel #4
0
 def test_nonexistent_yaml_object_from_envvar(self):
     os.environ.pop('EASY_CONFIG', None)
     with pytest.raises(RuntimeError) as exc:
         yaml_mapping('EASY_CONFIG', silent=False, is_envvar=True)
     assert str(
         exc.value) == ("The environment variable 'EASY_CONFIG' is not set "
                        "and as such configuration could not be "
                        "loaded. Set this variable and make it "
                        "point to a configuration file")
Beispiel #5
0
 def test_nonexistent_yaml_object_from_envvar(self):
     os.environ.pop('EASY_CONFIG', None)
     with pytest.raises(RuntimeError) as exc:
         yaml_mapping('EASY_CONFIG', silent=False, is_envvar=True)
     assert str(exc.value) == (
         "The environment variable 'EASY_CONFIG' is not set "
         "and as such configuration could not be "
         "loaded. Set this variable and make it "
         "point to a configuration file"
     )
Beispiel #6
0
 def test_valid_yaml_mapping_from_envvar(self):
     os.environ['EASY_CONFIG'] = yaml_filename
     mapping = yaml_mapping('EASY_CONFIG', is_envvar=True)
     assert mapping['DEBUG']
     assert mapping['PORT'] == 5000
     assert mapping['SECRET_KEY'] == '123***456'
Beispiel #7
0
 def test_valid_yaml_mapping(self):
     mapping = yaml_mapping(yaml_filename)
     assert mapping['DEBUG']
     assert mapping['PORT'] == 5000
     assert mapping['SECRET_KEY'] == '123***456'
Beispiel #8
0
 def test_empty_yaml_mapping_from_envvar_in_silent(self):
     os.environ['EASY_CONFIG'] = ''
     mapping = yaml_mapping('EASY_CONFIG', silent=True, is_envvar=True)
     assert not mapping
Beispiel #9
0
 def test_nonexistent_yaml_object_from_envvar_in_silent(self):
     os.environ.pop('EASY_CONFIG', None)
     mapping = yaml_mapping('EASY_CONFIG', silent=True, is_envvar=True)
     assert not mapping
Beispiel #10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import

import os

from easyconfig import Config, yaml_mapping

# Initialize config
config = Config({
    'COMMANDS_PATH': '',
    'ENTRY_POINT': 'main',
})

# Override config
yaml_filename = os.environ.get('CMDR_CONFIG_YAML')
if yaml_filename:
    config.from_mapping(yaml_mapping(yaml_filename))

# Validate config
if not config.COMMANDS_PATH:
    raise RuntimeError('Configuration `COMMANDS_PATH` is empty')
if not config.ENTRY_POINT:
    raise RuntimeError('Configuration `ENTRY_POINT` is empty')
Beispiel #11
0
 def test_valid_yaml_mapping_from_envvar(self):
     os.environ['EASY_CONFIG'] = yaml_filename
     mapping = yaml_mapping('EASY_CONFIG', is_envvar=True)
     assert mapping['DEBUG']
     assert mapping['PORT'] == 5000
     assert mapping['SECRET_KEY'] == '123***456'
Beispiel #12
0
 def test_empty_yaml_mapping(self):
     with pytest.raises(IOError) as exc:
         yaml_mapping('')
     assert str(
         exc.value) == ("[Errno 2] Unable to load configuration file "
                        "(No such file or directory): ''")
Beispiel #13
0
 def test_valid_yaml_mapping(self):
     mapping = yaml_mapping(yaml_filename)
     assert mapping['DEBUG']
     assert mapping['PORT'] == 5000
     assert mapping['SECRET_KEY'] == '123***456'
Beispiel #14
0
 def test_empty_yaml_mapping_from_envvar_in_silent(self):
     os.environ['EASY_CONFIG'] = ''
     mapping = yaml_mapping('EASY_CONFIG', silent=True, is_envvar=True)
     assert not mapping
Beispiel #15
0
 def test_nonexistent_yaml_object_from_envvar_in_silent(self):
     os.environ.pop('EASY_CONFIG', None)
     mapping = yaml_mapping('EASY_CONFIG', silent=True, is_envvar=True)
     assert not mapping