Skip to content

Commit

Permalink
chore: add jinja test
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Sep 23, 2023
1 parent 37f863e commit 849d74c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mknodes/jinja/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, *, undefined: str = "silent", load_templates: bool = False):
super().__init__(undefined=behavior, loader=loader, trim_blocks=True)
self.filters.update(jinjahelpers.ENVIRONMENT_FILTERS)
self.globals.update(jinjahelpers.ENVIRONMENT_GLOBALS)
self.rendered_nodes: set[mk.MkNode] = set()
self.rendered_nodes: list[mk.MkNode] = list()

def collect_reqs(self, ctx, **kwargs):
pass
Expand Down Expand Up @@ -153,7 +153,7 @@ def set_mknodes_filters(self, parent: mk.MkNode | None = None):

def wrapped(ctx, *args, fn=fn, **kwargs):
node = fn(*args, **kwargs)
self.rendered_nodes.add(node)
self.rendered_nodes.append(node)
return node

new = functools.partial(wrapped, fn=fn)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_jinja.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import annotations

import mknodes


def test_if_mknodes_parent_is_set(project):
page = mknodes.MkPage()
project._root += page
page.env.render_string(r"{{ 'test' | MkHeader }}")
assert page.env.rendered_nodes[-1].parent == page

0 comments on commit 849d74c

Please sign in to comment.