Skip to content

Commit 6e4e776

Browse files
committed
Add tests for partial yaml interpolation
1 parent 585c717 commit 6e4e776

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

tests/unit/providers/test_configuration_py2_py3.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -781,17 +781,20 @@ def setUp(self):
781781
self.config = providers.Configuration(name='config')
782782

783783
os.environ['CONFIG_TEST_ENV'] = 'test-value'
784+
os.environ['CONFIG_TEST_PATH'] = 'test-path'
784785

785786
_, self.config_file = tempfile.mkstemp()
786787
with open(self.config_file, 'w') as config_file:
787788
config_file.write(
788789
'section1:\n'
789790
' value1: ${CONFIG_TEST_ENV}\n'
791+
' value2: ${CONFIG_TEST_PATH}/path\n'
790792
)
791793

792794
def tearDown(self):
793795
del self.config
794796
del os.environ['CONFIG_TEST_ENV']
797+
del os.environ['CONFIG_TEST_PATH']
795798
os.unlink(self.config_file)
796799

797800
@unittest.skipIf(sys.version_info[:2] == (3, 4), 'PyYAML does not support Python 3.4')
@@ -803,11 +806,19 @@ def test_env_variable_interpolation(self):
803806
{
804807
'section1': {
805808
'value1': 'test-value',
809+
'value2': 'test-path/path',
806810
},
807811
},
808812
)
809-
self.assertEqual(self.config.section1(), {'value1': 'test-value'})
813+
self.assertEqual(
814+
self.config.section1(),
815+
{
816+
'value1': 'test-value',
817+
'value2': 'test-path/path',
818+
},
819+
)
810820
self.assertEqual(self.config.section1.value1(), 'test-value')
821+
self.assertEqual(self.config.section1.value2(), 'test-path/path')
811822

812823
@unittest.skipIf(sys.version_info[:2] == (3, 4), 'PyYAML does not support Python 3.4')
813824
def test_option_env_variable_interpolation(self):
@@ -818,41 +829,47 @@ def test_option_env_variable_interpolation(self):
818829
{
819830
'section1': {
820831
'value1': 'test-value',
832+
'value2': 'test-path/path',
821833
},
822834
},
823835
)
824-
self.assertEqual(self.config.option.section1(), {'value1': 'test-value'})
836+
self.assertEqual(
837+
self.config.option.section1(),
838+
{
839+
'value1': 'test-value',
840+
'value2': 'test-path/path',
841+
},
842+
)
825843
self.assertEqual(self.config.option.section1.value1(), 'test-value')
844+
self.assertEqual(self.config.option.section1.value2(), 'test-path/path')
826845

827846
@unittest.skipIf(sys.version_info[:2] == (3, 4), 'PyYAML does not support Python 3.4')
828847
def test_env_variable_interpolation_custom_loader(self):
829848
self.config.from_yaml(self.config_file, loader=yaml.UnsafeLoader)
830849

831850
self.assertEqual(
832-
self.config(),
851+
self.config.section1(),
833852
{
834-
'section1': {
835-
'value1': 'test-value',
836-
},
853+
'value1': 'test-value',
854+
'value2': 'test-path/path',
837855
},
838856
)
839-
self.assertEqual(self.config.section1(), {'value1': 'test-value'})
840857
self.assertEqual(self.config.section1.value1(), 'test-value')
858+
self.assertEqual(self.config.section1.value2(), 'test-path/path')
841859

842860
@unittest.skipIf(sys.version_info[:2] == (3, 4), 'PyYAML does not support Python 3.4')
843861
def test_option_env_variable_interpolation_custom_loader(self):
844862
self.config.option.from_yaml(self.config_file, loader=yaml.UnsafeLoader)
845863

846864
self.assertEqual(
847-
self.config.option(),
865+
self.config.option.section1(),
848866
{
849-
'section1': {
850-
'value1': 'test-value',
851-
},
867+
'value1': 'test-value',
868+
'value2': 'test-path/path',
852869
},
853870
)
854-
self.assertEqual(self.config.option.section1(), {'value1': 'test-value'})
855871
self.assertEqual(self.config.option.section1.value1(), 'test-value')
872+
self.assertEqual(self.config.option.section1.value2(), 'test-path/path')
856873

857874

858875
class ConfigFromPydanticTests(unittest.TestCase):

0 commit comments

Comments
 (0)