Пример #1
0
 def test_json(self):
     with tempfile.NamedTemporaryFile(suffix='.json') as temp:
         temp.write(JSON_CONFIG)
         temp.seek(0)
         viper.set_config_path(temp.name)
         viper.read_config()
         assert viper.get('hello.name') == 'foo'
Пример #2
0
 def test_remote_config(self, mock_get):
     mock_get.return_value = mock.Mock(text=json.dumps([TEST_DATA]),
                                       headers={'X-Consul-Index': 0},
                                       status_code=200)
     viper.set_config_type('yml')
     viper.set_remote_provider('consul', '127.0.0.1', 8500, 'hello')
     viper.read_remote_config()
     self.assertEqual('foo', viper.get('hello.name'))
Пример #3
0
import tempfile
import viper

yaml_example = b'''
hello:
  name: foo
'''


class Hello:
    name = ''


class Config:
    hello = Hello


if __name__ == '__main__':
    with tempfile.NamedTemporaryFile(suffix='.yaml') as temp:
        temp.write(yaml_example)
        temp.seek(0)
        viper.set_config_path(temp.name)
        viper.read_config()
        assert viper.get('hello.name') == 'foo'

        conf = Config()
        viper.unmarshal(conf)
        assert conf.hello.name == 'foo'
Пример #4
0
 def hello():
     return 'Hello {}!'.format(viper.get('name'))
Пример #5
0
def hello():
    return "Hello %s!" % viper.get('name')