@@ -591,17 +591,20 @@ def setUp(self):
591
591
self .config = providers .Configuration (name = 'config' )
592
592
593
593
os .environ ['CONFIG_TEST_ENV' ] = 'test-value'
594
+ os .environ ['CONFIG_TEST_PATH' ] = 'test-path'
594
595
595
596
_ , self .config_file = tempfile .mkstemp ()
596
597
with open (self .config_file , 'w' ) as config_file :
597
598
config_file .write (
598
599
'[section1]\n '
599
600
'value1=${CONFIG_TEST_ENV}\n '
601
+ 'value2=${CONFIG_TEST_PATH}/path\n '
600
602
)
601
603
602
604
def tearDown (self ):
603
605
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 )
605
608
os .unlink (self .config_file )
606
609
607
610
def test_env_variable_interpolation (self ):
@@ -612,11 +615,44 @@ def test_env_variable_interpolation(self):
612
615
{
613
616
'section1' : {
614
617
'value1' : 'test-value' ,
618
+ 'value2' : 'test-path/path' ,
615
619
},
616
620
},
617
621
)
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
+ )
619
629
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' )
620
656
621
657
622
658
class ConfigFromYamlTests (unittest .TestCase ):
@@ -793,8 +829,8 @@ def setUp(self):
793
829
794
830
def tearDown (self ):
795
831
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 )
798
834
os .unlink (self .config_file )
799
835
800
836
@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):
820
856
self .assertEqual (self .config .section1 .value1 (), 'test-value' )
821
857
self .assertEqual (self .config .section1 .value2 (), 'test-path/path' )
822
858
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
+
823
885
@unittest .skipIf (sys .version_info [:2 ] == (3 , 4 ), 'PyYAML does not support Python 3.4' )
824
886
def test_option_env_variable_interpolation (self ):
825
887
self .config .option .from_yaml (self .config_file )
0 commit comments