Skip to content

Commit d39fdfe

Browse files
committed
Add tests for partial ini interpolation
1 parent 6e4e776 commit d39fdfe

File tree

1 file changed

+66
-4
lines changed

1 file changed

+66
-4
lines changed

tests/unit/providers/test_configuration_py2_py3.py

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,17 +591,20 @@ def setUp(self):
591591
self.config = providers.Configuration(name='config')
592592

593593
os.environ['CONFIG_TEST_ENV'] = 'test-value'
594+
os.environ['CONFIG_TEST_PATH'] = 'test-path'
594595

595596
_, self.config_file = tempfile.mkstemp()
596597
with open(self.config_file, 'w') as config_file:
597598
config_file.write(
598599
'[section1]\n'
599600
'value1=${CONFIG_TEST_ENV}\n'
601+
'value2=${CONFIG_TEST_PATH}/path\n'
600602
)
601603

602604
def tearDown(self):
603605
del self.config
604-
del os.environ['CONFIG_TEST_ENV']
606+
os.environ.pop('CONFIG_TEST_ENV', None)
607+
os.environ.pop('CONFIG_TEST_PATH', None)
605608
os.unlink(self.config_file)
606609

607610
def test_env_variable_interpolation(self):
@@ -612,11 +615,44 @@ def test_env_variable_interpolation(self):
612615
{
613616
'section1': {
614617
'value1': 'test-value',
618+
'value2': 'test-path/path',
615619
},
616620
},
617621
)
618-
self.assertEqual(self.config.section1(), {'value1': 'test-value'})
622+
self.assertEqual(
623+
self.config.section1(),
624+
{
625+
'value1': 'test-value',
626+
'value2': 'test-path/path',
627+
},
628+
)
619629
self.assertEqual(self.config.section1.value1(), 'test-value')
630+
self.assertEqual(self.config.section1.value2(), 'test-path/path')
631+
632+
def test_missing_envs(self):
633+
del os.environ['CONFIG_TEST_ENV']
634+
del os.environ['CONFIG_TEST_PATH']
635+
636+
self.config.from_ini(self.config_file)
637+
638+
self.assertEqual(
639+
self.config(),
640+
{
641+
'section1': {
642+
'value1': '${CONFIG_TEST_ENV}',
643+
'value2': '${CONFIG_TEST_PATH}/path',
644+
},
645+
},
646+
)
647+
self.assertEqual(
648+
self.config.section1(),
649+
{
650+
'value1': '${CONFIG_TEST_ENV}',
651+
'value2': '${CONFIG_TEST_PATH}/path',
652+
},
653+
)
654+
self.assertEqual(self.config.section1.value1(), '${CONFIG_TEST_ENV}')
655+
self.assertEqual(self.config.section1.value2(), '${CONFIG_TEST_PATH}/path')
620656

621657

622658
class ConfigFromYamlTests(unittest.TestCase):
@@ -793,8 +829,8 @@ def setUp(self):
793829

794830
def tearDown(self):
795831
del self.config
796-
del os.environ['CONFIG_TEST_ENV']
797-
del os.environ['CONFIG_TEST_PATH']
832+
os.environ.pop('CONFIG_TEST_ENV', None)
833+
os.environ.pop('CONFIG_TEST_PATH', None)
798834
os.unlink(self.config_file)
799835

800836
@unittest.skipIf(sys.version_info[:2] == (3, 4), 'PyYAML does not support Python 3.4')
@@ -820,6 +856,32 @@ def test_env_variable_interpolation(self):
820856
self.assertEqual(self.config.section1.value1(), 'test-value')
821857
self.assertEqual(self.config.section1.value2(), 'test-path/path')
822858

859+
@unittest.skipIf(sys.version_info[:2] == (3, 4), 'PyYAML does not support Python 3.4')
860+
def test_missing_envs(self):
861+
del os.environ['CONFIG_TEST_ENV']
862+
del os.environ['CONFIG_TEST_PATH']
863+
864+
self.config.from_yaml(self.config_file)
865+
866+
self.assertEqual(
867+
self.config(),
868+
{
869+
'section1': {
870+
'value1': '${CONFIG_TEST_ENV}',
871+
'value2': '${CONFIG_TEST_PATH}/path',
872+
},
873+
},
874+
)
875+
self.assertEqual(
876+
self.config.section1(),
877+
{
878+
'value1': '${CONFIG_TEST_ENV}',
879+
'value2': '${CONFIG_TEST_PATH}/path',
880+
},
881+
)
882+
self.assertEqual(self.config.section1.value1(), '${CONFIG_TEST_ENV}')
883+
self.assertEqual(self.config.section1.value2(), '${CONFIG_TEST_PATH}/path')
884+
823885
@unittest.skipIf(sys.version_info[:2] == (3, 4), 'PyYAML does not support Python 3.4')
824886
def test_option_env_variable_interpolation(self):
825887
self.config.option.from_yaml(self.config_file)

0 commit comments

Comments
 (0)