def test_getconfig_os_env_types(self): """Test type conversion for values read from the environment. """ m = Environment(None, None) f = Filter() f.set_context(ContextWrapper(m)) get_config = f.get_config with os_environ_sandbox(): os.environ['foo'] = 'one,two\,three' assert list(get_config(env='foo', type=list)) == ['one', 'two,three'] # Make sure the split is not applied to env config values m.config['foo'] = 'one,two\,three' assert get_config(setting='foo', type=list) == 'one,two\,three'
def test_get_config(self): """Test the ``get_config`` helper. """ m = Environment(None, None) f = Filter() f.set_context(ContextWrapper(m)) get_config = f.get_config # For the purposes of the following tests, we use two test # names which we expect to be undefined in os.env. NAME = 'FOO%s' % id(object()) NAME2 = 'FOO%s' % id(NAME) assert NAME != NAME2 assert not NAME in os.environ and not NAME2 in os.environ with os_environ_sandbox(): # Test raising of error, and test not raising it. assert_raises(EnvironmentError, get_config, NAME) assert get_config(NAME, require=False) is None # Start with only the environment variable set. os.environ[NAME] = 'bar' assert get_config(NAME) == 'bar' assert get_config(env=NAME, setting=False) == 'bar' assert_raises(EnvironmentError, get_config, setting=NAME, env=False) # Set the value in the environment as well. m.config[NAME] = 'foo' # Ensure that settings take precedence. assert_equal(get_config(NAME), 'foo') # Two different names can be supplied. assert get_config(setting=NAME2, env=NAME) == 'bar' # Unset the env variable, now with only the setting. del os.environ[NAME] assert get_config(NAME) == 'foo' assert get_config(setting=NAME, env=False) == 'foo' assert_raises(EnvironmentError, get_config, env=NAME)