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'
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'))
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'
def hello(): return 'Hello {}!'.format(viper.get('name'))
def hello(): return "Hello %s!" % viper.get('name')