diff options
author | David Lord <davidism@gmail.com> | 2021-11-09 12:28:39 -0800 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2021-11-09 12:28:39 -0800 |
commit | a42b291bf2a3ac69f978ee88418ca6d0c7879d1e (patch) | |
tree | 48c88330202b9d845161ec463d673c93ab2e54dd /tests | |
parent | b2bc7be67fb2d376b349b1769ba493cee6cedf1d (diff) | |
parent | 2a48dd898d72f1a119ee923996e70aa43da04ea4 (diff) | |
download | jinja2-a42b291bf2a3ac69f978ee88418ca6d0c7879d1e.tar.gz |
Merge branch '3.0.x'
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_inheritance.py | 4 | ||||
-rw-r--r-- | tests/test_loader.py | 22 | ||||
-rw-r--r-- | tests/test_nativetypes.py | 6 | ||||
-rw-r--r-- | tests/test_nodes.py | 3 |
4 files changed, 33 insertions, 2 deletions
diff --git a/tests/test_inheritance.py b/tests/test_inheritance.py index 5221839..0c20d4d 100644 --- a/tests/test_inheritance.py +++ b/tests/test_inheritance.py @@ -37,7 +37,7 @@ WORKINGTEMPLATE = """\ {% block block1 %} {% if false %} {% block block2 %} - this should workd + this should work {% endblock %} {% endif %} {% endblock %} @@ -49,7 +49,7 @@ DOUBLEEXTENDS = """\ {% block block1 %} {% if false %} {% block block2 %} - this should workd + this should work {% endblock %} {% endif %} {% endblock %} diff --git a/tests/test_loader.py b/tests/test_loader.py index 1533d02..b300c8f 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -314,6 +314,28 @@ def test_package_dir_list(package_dir_loader): @pytest.fixture() +def package_file_loader(monkeypatch): + monkeypatch.syspath_prepend(Path(__file__).parent / "res") + return PackageLoader("__init__") + + +@pytest.mark.parametrize( + ("template", "expect"), [("foo/test.html", "FOO"), ("test.html", "BAR")] +) +def test_package_file_source(package_file_loader, template, expect): + source, name, up_to_date = package_file_loader.get_source(None, template) + assert source.rstrip() == expect + assert name.endswith(os.path.join(*split_template_path(template))) + assert up_to_date() + + +def test_package_file_list(package_file_loader): + templates = package_file_loader.list_templates() + assert "foo/test.html" in templates + assert "test.html" in templates + + +@pytest.fixture() def package_zip_loader(monkeypatch): package_zip = (Path(__file__) / ".." / "res" / "package.zip").resolve() monkeypatch.syspath_prepend(package_zip) diff --git a/tests/test_nativetypes.py b/tests/test_nativetypes.py index 2258181..9bae938 100644 --- a/tests/test_nativetypes.py +++ b/tests/test_nativetypes.py @@ -147,3 +147,9 @@ def test_no_intermediate_eval(env): def test_spontaneous_env(): t = NativeTemplate("{{ true }}") assert isinstance(t.environment, NativeEnvironment) + + +def test_leading_spaces(env): + t = env.from_string(" {{ True }}") + result = t.render() + assert result == " True" diff --git a/tests/test_nodes.py b/tests/test_nodes.py new file mode 100644 index 0000000..e910998 --- /dev/null +++ b/tests/test_nodes.py @@ -0,0 +1,3 @@ +def test_template_hash(env): + template = env.parse("hash test") + hash(template) |