def test_templated(self): self.dir.write('etc/myapp.yml', ''' {% set base = dict(one=1)%} base_template: {{ base.one }} base_env: {{ MYVAR }} file_template: bad file_env: bad ''') self.dir.write('app.yml', ''' {% set local=2 %} file_template: {{ local }} file_env: {{ MYVAR }} ''') with Replace('os.environ.MYVAR', 'hello', strict=False) as r: env = Environment(loader=FileSystemLoader(self.dir.path)) config = None context = dict(os.environ) for path in 'etc/myapp.yml', 'app.yml': text = env.get_template(path).render(context) layer = Config.from_text(text) if config is None: config = layer else: config.merge(layer) compare(config.base_template, expected=1) compare(config.base_env, expected='hello') compare(config.file_template, expected=2) compare(config.file_env, expected='hello')
def test_text_missing_parser(self): with ShouldRaise(ParseError("No parser found for 'lolwut'")): Config.from_text("{'foo': 'bar'}", 'lolwut')
def test_text_callable_parser(self): config = Config.from_text("{'foo': 'bar'}", python_literal) compare(config.data, expected={'foo': 'bar'})
def test_bytes_string_parser(self): config = Config.from_text(b'{"foo": "bar"}', 'json') compare(config.data, expected={'foo': 'bar'})