Files
micropython/tests/basics/string_tstring_constructor1.py
Koudai Aono bdef10a92b tests: Add full feature and coverage tests for PEP 750 template strings.
Includes corresponding .exp files because this feature is only available in
Python 3.14+.

Tests for `!a` conversion specifier and space after `!` are not included
because they are not supported by MicroPython.

Signed-off-by: Koudai Aono <koxudaxi@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2026-03-09 23:47:33 +11:00

25 lines
756 B
Python

# NOTE: Error messages are shortened in MicroPython to avoid stack overflow
# during ROM compression on constrained platforms (Windows x86, ASan).
# CPython 3.14 message: "Template.__new__ *args need to be of type 'str' or 'Interpolation', got int"
# MicroPython message: "Template.__new__ args must be str or Interpolation, got 'int'"
from string.templatelib import Template
print("=== Constructor error messages ===")
try:
Template(strings=("test",))
except TypeError as e:
print(f"Keyword args: {e}")
try:
Template("hello", 42, "world")
except TypeError as e:
print(f"Invalid type: {e}")
try:
Template("a", 42, "b")
except TypeError as e:
print(f"Invalid type in varargs: {e}")
print("\nConstructor error tests completed!")