Skip to content

Commit

Permalink
🐛 Fix JinjaAdapter when passing environment instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Krupinski committed Feb 9, 2024
1 parent 571513d commit f8c8956
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rybak/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(
else:
if keep_trailing_newline is not None:
self._env = environment.overlay()
self._env.keep_trailing_newline = self._keep_trailing_newline
self._env.keep_trailing_newline = keep_trailing_newline

def render_str(self, template: str, data: TemplateData, loop_over: Optional[LoopOverFn] = None) -> str:
env = self._env.overlay()
Expand Down
34 changes: 34 additions & 0 deletions tests/test_jinja.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
from jinja2 import Environment, FileSystemLoader
from rybak.jinja import JinjaAdapter


def test_jinja_init_keep_newlines():
env = Environment(loader=FileSystemLoader('-path-'))
adapter = JinjaAdapter(env)

assert adapter._env.keep_trailing_newline is True


def test_jinja_init_keep_newlines_false():
env = Environment(loader=FileSystemLoader('-path-'))
adapter = JinjaAdapter(env, keep_trailing_newline=False)

assert adapter._env.keep_trailing_newline is False


def test_jinja_loader():
loader = FileSystemLoader('-path-')
adapter = JinjaAdapter(loader=loader)

assert adapter._env.loader == loader


def test_jinja_env_loader_error():
with pytest.raises(ValueError):
JinjaAdapter(environment=Environment(), loader=FileSystemLoader('-path-'))


def test_jinja_no_env_loader_error():
with pytest.raises(ValueError):
JinjaAdapter()

0 comments on commit f8c8956

Please sign in to comment.