mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-05-23 05:56:19 +03:00
Add tests for partial ini interpolation
This commit is contained in:
parent
6e4e776315
commit
d39fdfe2e9
|
@ -591,17 +591,20 @@ class ConfigFromIniWithEnvInterpolationTests(unittest.TestCase):
|
||||||
self.config = providers.Configuration(name='config')
|
self.config = providers.Configuration(name='config')
|
||||||
|
|
||||||
os.environ['CONFIG_TEST_ENV'] = 'test-value'
|
os.environ['CONFIG_TEST_ENV'] = 'test-value'
|
||||||
|
os.environ['CONFIG_TEST_PATH'] = 'test-path'
|
||||||
|
|
||||||
_, self.config_file = tempfile.mkstemp()
|
_, self.config_file = tempfile.mkstemp()
|
||||||
with open(self.config_file, 'w') as config_file:
|
with open(self.config_file, 'w') as config_file:
|
||||||
config_file.write(
|
config_file.write(
|
||||||
'[section1]\n'
|
'[section1]\n'
|
||||||
'value1=${CONFIG_TEST_ENV}\n'
|
'value1=${CONFIG_TEST_ENV}\n'
|
||||||
|
'value2=${CONFIG_TEST_PATH}/path\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
del self.config
|
del self.config
|
||||||
del os.environ['CONFIG_TEST_ENV']
|
os.environ.pop('CONFIG_TEST_ENV', None)
|
||||||
|
os.environ.pop('CONFIG_TEST_PATH', None)
|
||||||
os.unlink(self.config_file)
|
os.unlink(self.config_file)
|
||||||
|
|
||||||
def test_env_variable_interpolation(self):
|
def test_env_variable_interpolation(self):
|
||||||
|
@ -612,11 +615,44 @@ class ConfigFromIniWithEnvInterpolationTests(unittest.TestCase):
|
||||||
{
|
{
|
||||||
'section1': {
|
'section1': {
|
||||||
'value1': 'test-value',
|
'value1': 'test-value',
|
||||||
|
'value2': 'test-path/path',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
self.assertEqual(self.config.section1(), {'value1': 'test-value'})
|
self.assertEqual(
|
||||||
|
self.config.section1(),
|
||||||
|
{
|
||||||
|
'value1': 'test-value',
|
||||||
|
'value2': 'test-path/path',
|
||||||
|
},
|
||||||
|
)
|
||||||
self.assertEqual(self.config.section1.value1(), 'test-value')
|
self.assertEqual(self.config.section1.value1(), 'test-value')
|
||||||
|
self.assertEqual(self.config.section1.value2(), 'test-path/path')
|
||||||
|
|
||||||
|
def test_missing_envs(self):
|
||||||
|
del os.environ['CONFIG_TEST_ENV']
|
||||||
|
del os.environ['CONFIG_TEST_PATH']
|
||||||
|
|
||||||
|
self.config.from_ini(self.config_file)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
self.config(),
|
||||||
|
{
|
||||||
|
'section1': {
|
||||||
|
'value1': '${CONFIG_TEST_ENV}',
|
||||||
|
'value2': '${CONFIG_TEST_PATH}/path',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
self.config.section1(),
|
||||||
|
{
|
||||||
|
'value1': '${CONFIG_TEST_ENV}',
|
||||||
|
'value2': '${CONFIG_TEST_PATH}/path',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self.assertEqual(self.config.section1.value1(), '${CONFIG_TEST_ENV}')
|
||||||
|
self.assertEqual(self.config.section1.value2(), '${CONFIG_TEST_PATH}/path')
|
||||||
|
|
||||||
|
|
||||||
class ConfigFromYamlTests(unittest.TestCase):
|
class ConfigFromYamlTests(unittest.TestCase):
|
||||||
|
@ -793,8 +829,8 @@ class ConfigFromYamlWithEnvInterpolationTests(unittest.TestCase):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
del self.config
|
del self.config
|
||||||
del os.environ['CONFIG_TEST_ENV']
|
os.environ.pop('CONFIG_TEST_ENV', None)
|
||||||
del os.environ['CONFIG_TEST_PATH']
|
os.environ.pop('CONFIG_TEST_PATH', None)
|
||||||
os.unlink(self.config_file)
|
os.unlink(self.config_file)
|
||||||
|
|
||||||
@unittest.skipIf(sys.version_info[:2] == (3, 4), 'PyYAML does not support Python 3.4')
|
@unittest.skipIf(sys.version_info[:2] == (3, 4), 'PyYAML does not support Python 3.4')
|
||||||
|
@ -820,6 +856,32 @@ class ConfigFromYamlWithEnvInterpolationTests(unittest.TestCase):
|
||||||
self.assertEqual(self.config.section1.value1(), 'test-value')
|
self.assertEqual(self.config.section1.value1(), 'test-value')
|
||||||
self.assertEqual(self.config.section1.value2(), 'test-path/path')
|
self.assertEqual(self.config.section1.value2(), 'test-path/path')
|
||||||
|
|
||||||
|
@unittest.skipIf(sys.version_info[:2] == (3, 4), 'PyYAML does not support Python 3.4')
|
||||||
|
def test_missing_envs(self):
|
||||||
|
del os.environ['CONFIG_TEST_ENV']
|
||||||
|
del os.environ['CONFIG_TEST_PATH']
|
||||||
|
|
||||||
|
self.config.from_yaml(self.config_file)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
self.config(),
|
||||||
|
{
|
||||||
|
'section1': {
|
||||||
|
'value1': '${CONFIG_TEST_ENV}',
|
||||||
|
'value2': '${CONFIG_TEST_PATH}/path',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
self.config.section1(),
|
||||||
|
{
|
||||||
|
'value1': '${CONFIG_TEST_ENV}',
|
||||||
|
'value2': '${CONFIG_TEST_PATH}/path',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self.assertEqual(self.config.section1.value1(), '${CONFIG_TEST_ENV}')
|
||||||
|
self.assertEqual(self.config.section1.value2(), '${CONFIG_TEST_PATH}/path')
|
||||||
|
|
||||||
@unittest.skipIf(sys.version_info[:2] == (3, 4), 'PyYAML does not support Python 3.4')
|
@unittest.skipIf(sys.version_info[:2] == (3, 4), 'PyYAML does not support Python 3.4')
|
||||||
def test_option_env_variable_interpolation(self):
|
def test_option_env_variable_interpolation(self):
|
||||||
self.config.option.from_yaml(self.config_file)
|
self.config.option.from_yaml(self.config_file)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user