Skip to content

Commit

Permalink
update future import test
Browse files Browse the repository at this point in the history
Fixed test suite to not rely upon ancient "future division" statement to
test the :paramref:`.Template.future_imports` feature.   The test is
replaced with one that tests only the rendering, not the ultimate effect.

Also updates ancient documentation that also refers to this now defunct
future statement

Fixes: #408
Change-Id: I3e7d5bceb31fb141e2ea513d099be267dda1abe2
  • Loading branch information
zzzeek committed Feb 4, 2025
1 parent 798abe4 commit 188d543
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 7 additions & 0 deletions doc/build/unreleased/408.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. change::
:tags: bug, tests
:tickets: 408

Fixed test suite to not rely upon ancient "future division" statement to
test the :paramref:`.Template.future_imports` feature. The test is
replaced with one that tests only the rendering, not the ultimate effect.
6 changes: 1 addition & 5 deletions mako/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ class Template:
:param future_imports: String list of names to import from `__future__`.
These will be concatenated into a comma-separated string and inserted
into the beginning of the template, e.g. ``futures_imports=['FOO',
'BAR']`` results in ``from __future__ import FOO, BAR``. If you're
interested in using features like the new division operator, you must
use future_imports to convey that to the renderer, as otherwise the
import will not appear as the first executed statement in the generated
code and will therefore not have the desired effect.
'BAR']`` results in ``from __future__ import FOO, BAR``.
:param include_error_handler: An error handler that runs when this template
is included within another one via the ``<%include>`` tag, and raises an
Expand Down
4 changes: 2 additions & 2 deletions test/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -1775,8 +1775,8 @@ def test_via_lookup(self):

class FuturesTest(TemplateTest):
def test_future_import(self):
t = Template("${ x / y }", future_imports=["division"])
assert result_lines(t.render(x=12, y=5)) == ["2.4"]
t = Template("foobar", future_imports=["annotations"])
assert t.code.startswith("from __future__ import annotations")


class EscapeTest(TemplateTest):
Expand Down

0 comments on commit 188d543

Please sign in to comment.