Closed Bug 1948372 Opened 10 days ago Closed 6 days ago

[wpt-sync] Sync PR 50724 - Make generated canvas test parameters importable as Jinja templates

Categories

(Core :: Graphics: Canvas2D, task, P4)

task

Tracking

()

RESOLVED FIXED
137 Branch
Tracking Status
firefox137 --- fixed

People

(Reporter: wpt-sync, Unassigned)

References

()

Details

(Whiteboard: [wptsync downstream])

Sync web-platform-tests PR 50724 into mozilla-central (this bug is closed when the sync is complete).

PR: https://github.com/web-platform-tests/wpt/pull/50724
Details from upstream follow.

Jean-Philippe Gravel <jpgravel@chromium.org> wrote:

Make generated canvas test parameters importable as Jinja templates

In the Canvas WPT test generator, the test body can have Jinja tags
referring to other test parameters. For instance:
code: |
@assert pixel 50,25 == {{ expected_color }};
expected_color: 'rgba(0, 255, 0, {{ alpha }})'
alpha: 1.0

Here, the expected_color parameter is first rendered, expanding the
{{ alpha }} tag. This result is then inserted into the code
template. This is useful to reuse values in multiple places. It however
doesn't allow reusing Jinja macros. Indeed, if expected_color
contained a {% macro ... %} tag, that tag would get lost as the
expected_color gets rendered (the macro itself is not part of the
rendering result).

To be able to reuse macros, we would need to use an {% import ... %}
tag. This CL makes this possible by registering the test parameters as
templates loadable by the Jinja environment. Thus, the following
becomes possible:

macros: |
{% macro calculate_color(...) %}
...
{% endmacro %}
code: |
{% import 'macros' as m %}
@assert pixel 50,25 == {{ m.calculate_color(...) }};
expected: |
{% import 'macros' as m %}
size 100 50
cr.set_source_rgba({{ m.calculate_color(...) }})

Bug: 40207206
Change-Id: Idff8495efffbcde1840256b5ac5bded1d7e6de55
Reviewed-on: https://chromium-review.googlesource.com/6204442
WPT-Export-Revision: c0c810564fa7336f19edf7d4825e310f6dee5676

Component: web-platform-tests → Graphics: Canvas2D
Product: Testing → Core
Pushed by wptsync@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/a4f94736d293 [wpt PR 50724] - Make generated canvas test parameters importable as Jinja templates, a=testonly
Test result changes from PR not available.
Status: NEW → RESOLVED
Closed: 6 days ago
Resolution: --- → FIXED
Target Milestone: --- → 137 Branch
You need to log in before you can comment on or make changes to this bug.