def test_defaults(self): self.assertEquals( envtpl._render('{{ FOO | default("abc") }}', None, {}, jinja2.StrictUndefined), 'abc') self.assertEquals( envtpl._render('{{ FOO | default("abc") }}', None, {'FOO': 'def'}, jinja2.StrictUndefined), 'def')
def test_environment_prefix(self): source = ''' {% for key, value in environment('X_') %}{{ key }} = {{ value }} {% endfor %} ''' expected = ''' foo = bar ''' self.assertEquals(envtpl._render(source, None, {'X_foo': 'bar', 'baz': 'X_qux'}, jinja2.StrictUndefined), expected)
def test_quoted(self): source = ''' foo = {{ FOO | default(123) }} bar = "{{ BAR | default("abc") }}" ''' expected = ''' foo = 456 bar = "abc" ''' self.assertEquals(envtpl._render(source, None, {'FOO': 456}, jinja2.StrictUndefined), expected)
def test_quoted(self): source = ''' foo = {{ FOO | default(123) }} bar = "{{ BAR | default("abc") }}" ''' expected = ''' foo = 456 bar = "abc" ''' self.assertEquals( envtpl._render(source, None, {'FOO': 456}, jinja2.StrictUndefined), expected)
def test_environment_prefix(self): source = ''' {% for key, value in environment('X_') %}{{ key }} = {{ value }} {% endfor %} ''' expected = ''' foo = bar ''' self.assertEquals( envtpl._render(source, None, { 'X_foo': 'bar', 'baz': 'X_qux' }, jinja2.StrictUndefined), expected)
def test_if_block(self): source = ''' {% if BAZ is defined %} foo = 123 {% else %} foo = 456 {% endif %} bar = "abc"''' expected = ''' foo = 456 bar = "abc"''' self.assertEquals(envtpl._render(source, None, {}, jinja2.StrictUndefined), expected)
def test_env(self): source = ''' {{ env('FOO') }} {{ env('MY_' + FOO) }} ''' expected = ''' bar baz ''' self.assertEquals( envtpl._render(source, None, { 'FOO': 'bar', 'MY_bar': 'baz' }, jinja2.StrictUndefined), expected)
def test_if_block(self): source = ''' {% if BAZ is defined %} foo = 123 {% else %} foo = 456 {% endif %} bar = "abc"''' expected = ''' foo = 456 bar = "abc"''' self.assertEquals( envtpl._render(source, None, {}, jinja2.StrictUndefined), expected)
def test_dont_die_on_missing(self): self.assertEquals( envtpl._render('{{ FOO }}', None, {}, jinja2.Undefined), '')
def test_empty(self): self.assertEquals(envtpl._render('', None, {}, jinja2.StrictUndefined), '')
def test_defaults(self): self.assertEquals(envtpl._render('{{ FOO | default("abc") }}', None, {}, jinja2.StrictUndefined), 'abc') self.assertEquals(envtpl._render('{{ FOO | default("abc") }}', None, {'FOO': 'def'}, jinja2.StrictUndefined), 'def')
def test_dont_die_on_missing(self): self.assertEquals(envtpl._render('{{ FOO }}', None, {}, jinja2.Undefined), '')