예제 #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):
             Configure.open(tf.name)
     finally:
         os.unlink(tf.name)
예제 #2
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):
             Configure.open(tf.name)
     finally:
         os.unlink(tf.name)
예제 #3
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 = Configure.open(tf.name)
             self.assertEqual(c['z'], 'myapikey')
         finally:
             os.unlink(tf.name)
예제 #4
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 = Configure.open(tf.name)
             self.assertIsNone(c['z'])
         finally:
             os.unlink(tf.name)
예제 #5
0
 def test_read_from_file_env_val_multi_embedded_success(self):
     with patch.dict('os.environ', {'USER': '******', 'IS_SUPER': 'normal'}, clear=True):
         tf = self.tempfile()
         print('{"greeting": "Hello, $IS_SUPER $USER"}', file=tf)
         tf.close()
         try:
             c = Configure.open(tf.name)
             self.assertEqual(c['greeting'], 'Hello, normal dave')
         finally:
             os.unlink(tf.name)
예제 #6
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 = Configure.open(tf.name)
             self.assertIsNone(c['z'])
         finally:
             os.unlink(tf.name)
예제 #7
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 = Configure.open(tf.name)
             self.assertEqual(c['z'], 'myapikey')
         finally:
             os.unlink(tf.name)
예제 #8
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 = Configure.open(tf.name)
             self.assertIsNone(c['z'])
         finally:
             os.unlink(tf.name)
예제 #9
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 = Configure.open(tf.name)
             self.assertEqual(c['greeting'], 'Hello, dave')
         finally:
             os.unlink(tf.name)
예제 #10
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 = Configure.open(tf.name)
             self.assertIsNone(c['z'])
         finally:
             os.unlink(tf.name)
예제 #11
0
 def test_base_varname_override(self):
     with patch('PyOpenWorm.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 = Configure.open(tf.name)
                 self.assertEqual(c['z'], 'cars/car')
             finally:
                 os.unlink(tf.name)
예제 #12
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 = Configure.open(tf.name)
             self.assertEqual(c['z'], dname + '/car')
         finally:
             os.unlink(tf.name)