Beispiel #1
0
    def test_env_variable_overrides_config_value(self):
        config_data = json.loads(self.file_content(self.SIMPLE_JSON_CONFIG))

        any_key_from_config = list(config_data.keys())[0]
        new_key_value = config_data[any_key_from_config] * 2
        os.environ[any_key_from_config.upper()] = new_key_value
        self.assertEquals(os.getenv(any_key_from_config.upper()),
                          new_key_value)
        cfg = SpyCfg(self.SIMPLE_JSON_CONFIG)

        self.assertEqual(cfg[any_key_from_config], new_key_value)

        del os.environ[any_key_from_config.upper()]  # clean up
Beispiel #2
0
import sys
import os

sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src'))

from spycfg import SpyCfg

# or you can ran previous example with env
os.environ['KEY1'] = 'hello from env'

cfg = SpyCfg('src/tests/fixtures/simple.json', cfg_type=SpyCfg.JSON)

print("cfg['key1'] =", cfg['key1'])
print("cfg['key2'] =", cfg['key2'])
Beispiel #3
0
    def test_no_file(self):
        with self.assertRaises(spycfg.errors.IOError) as cf:
            file_name = 'any'
            SpyCfg(file_name)

        self.assertIsInstance(cf.exception, spycfg.errors.IOError)
Beispiel #4
0
    def test_create_from_ini(self):
        cfg = SpyCfg(self.SIMPLE_INI_CONFIG, cfg_type=INI_CFG)

        self.assertEqual(cfg['key1'], 'key1')
Beispiel #5
0
    def test_dev_env_config_loaded_and_overrides_default(self):
        dev_cfg = json.loads(self.file_content(self.DEV_CONFIG))
        cfg = SpyCfg(self.SIMPLE_JSON_CONFIG, env='DEV')

        self.assertEquals(cfg['key1'], dev_cfg['key1'])
Beispiel #6
0
    def test_create_from_json(self):
        cfg = SpyCfg(self.SIMPLE_JSON_CONFIG)

        self.assertEqual(cfg['key1'], 'key1')