Skip to content

Commit 0f28d2e

Browse files
authored
Add test for text fontsize in SVG circuit diagrams (#8161)
Address mutation check in cl/935515593
1 parent dc296ed commit 0f28d2e

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

cirq-core/cirq/contrib/svg/svg_test.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
import re
6+
57
import IPython.display
68
import numpy as np
79
import pytest
@@ -24,9 +26,16 @@ def test_svg() -> None:
2426
cirq.MatrixGate(np.eye(2)).on(a),
2527
)
2628
)
27-
assert '?' in svg_text
2829
assert '<svg' in svg_text
2930
assert '</svg>' in svg_text
31+
# check text rendering fontsize
32+
# single letter X gate rendered at 18px
33+
assert re.search(r'<text[^>]*\bfont-size="18px[^>]*>X</text>', svg_text)
34+
# multi-letter PhasedXPowGate rendered at 14px
35+
phx_literal = re.escape("PhX(0.456)^0.123")
36+
assert re.search(rf'<text[^>]*\bfont-size="14px[^>]*>{phx_literal}</text>', svg_text)
37+
# MatrixGate replaced with "?" rendered at 18px
38+
assert re.search(r'<text[^>]*\bfont-size="18px[^>]*>[?]</text>', svg_text)
3039

3140

3241
def test_svg_noise() -> None:

0 commit comments

Comments
 (0)