Esempio n. 1
0
    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')
Esempio n. 2
0
 def test_text_missing_parser(self):
     with ShouldRaise(ParseError("No parser found for 'lolwut'")):
         Config.from_text("{'foo': 'bar'}", 'lolwut')
Esempio n. 3
0
 def test_text_callable_parser(self):
     config = Config.from_text("{'foo': 'bar'}", python_literal)
     compare(config.data, expected={'foo': 'bar'})
Esempio n. 4
0
 def test_bytes_string_parser(self):
     config = Config.from_text(b'{"foo": "bar"}', 'json')
     compare(config.data, expected={'foo': 'bar'})
Esempio n. 5
0
 def test_text_missing_parser(self):
     with ShouldRaise(ParseError("No parser found for 'lolwut'")):
         Config.from_text("{'foo': 'bar'}", 'lolwut')
Esempio n. 6
0
 def test_text_callable_parser(self):
     config = Config.from_text("{'foo': 'bar'}", python_literal)
     compare(config.data, expected={'foo': 'bar'})
Esempio n. 7
0
 def test_bytes_string_parser(self):
     config = Config.from_text(b'{"foo": "bar"}', 'json')
     compare(config.data, expected={'foo': 'bar'})