コード例 #1
0
 def test_read_from_file_env_val_fail_name_2(self):
     tf = self.tempfile()
     print('{"z": "$1StillNoGood"}', file=tf)
     tf.close()
     try:
         with self.assertRaises(ValueError):
             Configuration.open(tf.name)
     finally:
         os.unlink(tf.name)
コード例 #2
0
 def test_read_from_file_env_val_success(self):
     with patch.dict('os.environ', {'ENV_VAR': 'myapikey'}):
         tf = self.tempfile()
         print('{"z": "$ENV_VAR"}', file=tf)
         tf.close()
         try:
             c = Configuration.open(tf.name)
             self.assertEqual(c['z'], 'myapikey')
         finally:
             os.unlink(tf.name)
コード例 #3
0
 def test_read_from_file_env_val_multi_empty(self):
     with patch.dict('os.environ', (), clear=True):
         tf = self.tempfile()
         print('{"z": "$V1$V2"}', file=tf)
         tf.close()
         try:
             c = Configuration.open(tf.name)
             self.assertIsNone(c['z'])
         finally:
             os.unlink(tf.name)
コード例 #4
0
 def test_read_from_file_env_val_embedded_success(self):
     with patch.dict('os.environ', {'USER': '******'}, clear=True):
         tf = self.tempfile()
         print('{"greeting": "Hello, $USER"}', file=tf)
         tf.close()
         try:
             c = Configuration.open(tf.name)
             self.assertEqual(c['greeting'], 'Hello, dave')
         finally:
             os.unlink(tf.name)
コード例 #5
0
 def test_read_from_file_env_val_empty_string(self):
     with patch.dict('os.environ', {'ENV_VAR': ''}):
         tf = self.tempfile()
         print('{"z": "$ENV_VAR"}', file=tf)
         tf.close()
         try:
             c = Configuration.open(tf.name)
             self.assertIsNone(c['z'])
         finally:
             os.unlink(tf.name)
コード例 #6
0
 def test_base_varname_override(self):
     with patch('owmeta_core.configure.resource_filename') as rf:
         with patch.dict('os.environ', {'BASE': 'cars'}, clear=True):
             rf.return_value = 'moosh'
             tf = self.tempfile()
             print('{"z": "$BASE/car"}', file=tf)
             tf.close()
             try:
                 c = Configuration.open(tf.name)
                 self.assertEqual(c['z'], 'cars/car')
             finally:
                 os.unlink(tf.name)
コード例 #7
0
 def test_here_varname(self):
     '''
     By default, $HERE refers to the directory the config file sits in, or to the
     current working directory
     '''
     with patch.dict('os.environ', (), clear=True):
         tf = self.tempfile()
         dname = os.path.dirname(tf.name)
         print('{"z": "$HERE/car"}', file=tf)
         tf.close()
         try:
             c = Configuration.open(tf.name)
             self.assertEqual(c['z'], dname + '/car')
         finally:
             os.unlink(tf.name)