Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test mixing of contentless and contentful components #6

Merged
merged 1 commit into from
Feb 22, 2023

Conversation

jodal
Copy link
Contributor

@jodal jodal commented Feb 20, 2023

This is basically a bug report in the form of a PR with a failing test.

The new test case shows that all combinations of contentless and contentful components works as expected, except when using a contentless component before a contentful component, e.g.:

<Icon />
<Title>Hi</Title>

This fails with:

=================================================== FAILURES ===================================================
_ test_render_mix_of_contentful_and_contentless_components[<Icon /><Title>Hi</Title>-<i class="icon"></i><h1>Hi</h1>] _

catalog = <jinjax.catalog.Catalog object at 0x7f68a8d1a3a0>
folder = PosixPath('/tmp/pytest-of-jodal/pytest-26/test_render_mix_of_contentful_3/components')
source = '<Icon /><Title>Hi</Title>', expected = '<i class="icon"></i><h1>Hi</h1>'

    @pytest.mark.parametrize(
        "source, expected",
        [
            ("<Title>Hi</Title><Title>Hi</Title>", '<h1>Hi</h1><h1>Hi</h1>'),
            ("<Icon /><Icon />", '<i class="icon"></i><i class="icon"></i>'),
            ("<Title>Hi</Title><Icon />", '<h1>Hi</h1><i class="icon"></i>'),
            ("<Icon /><Title>Hi</Title>", '<i class="icon"></i><h1>Hi</h1>'),
        ],
    )
    def test_render_mix_of_contentful_and_contentless_components(catalog, folder, source, expected):
        (folder / "Icon.jinja").write_text('<i class="icon"></i>')
        (folder / "Title.jinja").write_text("<h1>{{ content }}</h1>")
        (folder / "Page.jinja").write_text(source)
    
>       html = catalog.render("Page")

tests/test_render.py:55: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/jinjax/catalog.py:123: in render
    tmpl = self.jinja_env.get_template(tmpl_name)
.venv/lib/python3.9/site-packages/jinja2/environment.py:1010: in get_template
    return self._load_template(name, globals)
.venv/lib/python3.9/site-packages/jinja2/environment.py:969: in _load_template
    template = self.loader.load(self, name, self.make_globals(globals))
.venv/lib/python3.9/site-packages/jinja2/loaders.py:138: in load
    code = environment.compile(source, name, filename)
.venv/lib/python3.9/site-packages/jinja2/environment.py:768: in compile
    self.handle_exception(source=source_hint)
.venv/lib/python3.9/site-packages/jinja2/environment.py:936: in handle_exception
    raise rewrite_traceback_stack(source=source)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   jinja2.exceptions.TemplateSyntaxError: Unclosed component <Title>

/tmp/pytest-of-jodal/pytest-26/test_render_mix_of_contentful_3/components/Page.jinja:2: TemplateSyntaxError

This test shows that all combinations works as expected, except when
using an contentless component before a contentful component, e.g.:

```
<Icon />
<Title>Hi</Title>
```
@jpsca
Copy link
Owner

jpsca commented Feb 22, 2023

That's ... weird. I'm investigating it right now

@jpsca jpsca merged commit 6911b88 into jpsca:main Feb 22, 2023
@jpsca
Copy link
Owner

jpsca commented Feb 22, 2023

Fixed in the latest release: https://github.com/jpsca/jinjax/releases/tag/0.21
Thanks for the bug report

@jodal jodal deleted the mix-contentless-and-contentful-components branch September 19, 2023 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants