Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 90 additions & 4 deletions test/builtin/test_makeboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,89 @@ def skip_or_fail(x):
skip_or_fail = pytest.mark.xfail


@pytest.mark.parametrize(
("str_expr", "str_expected", "fail_msg"),
[
("MakeBoxes[x]", '"x"', "StandardForm"),
(
"MakeBoxes[InputForm[x]]",
'InterpretationBox[StyleBox["x", ShowStringCharacters -> True, NumberMarks -> True], InputForm[x], Editable -> True, AutoDelete -> True]',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WMA has x, instead of InputForm[x] and there are no quotes around "x" in StyleBox["x"]. What gives?

"InputForm, expression",
),
(
"MakeBoxes[OutputForm[x]]",
'InterpretationBox[PaneBox[""x""], OutputForm[x], Editable -> False]',

@rocky rocky Dec 31, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I see a duplicate set of quotes. I am wondering about the merits of having exhaustive tests that are wrong, versus having limited tests that are right with tests that are skipped that need to be worked on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to get useful references from WMA. This is exactly what I get when I evaluate MakeBoxes[OutputForm[x]]//InputForm in the WMA CLI.

@rocky rocky Dec 31, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I see is:

InterpretationBox[PaneBox["\"x\"", BaselinePosition -> Baseline], x,  Editable -> False]

Note the extra backslashes. This is slightly different.

"OutputForm, expression",
),
(
"MakeBoxes[FullForm[x]]",
'TagBox[StyleBox["x", ShowSpecialCharacters -> False, ShowStringCharacters -> True, NumberMarks -> True], FullForm]',
"MakeBoxes expression FullForm",
),
(
"MakeBoxes[TeXForm[x]]",
'InterpretationBox[""x"", TeXForm[x], Editable -> True, AutoDelete -> True]',
"TeXForm, expression",
),
# Basic Expressions
("MakeBoxes[F[x]]", 'RowBox[{"F", "[", "x", "]"}]', "StandardForm"),
(
"MakeBoxes[InputForm[F[x]]]",
'InterpretationBox[StyleBox["F[x]", ShowStringCharacters -> True, NumberMarks -> True], InputForm[F[x]], Editable -> True, AutoDelete -> True]',
"InputForm, expression",
),
(
"MakeBoxes[OutputForm[F[x]]]",
'InterpretationBox[PaneBox[""F[x]""], OutputForm[F[x]], Editable -> False]',
"OutputForm, expression",
),
(
"MakeBoxes[FullForm[F[x]]]",
'TagBox[StyleBox[RowBox[{"F", "[", "x", "]"}], ShowSpecialCharacters -> False, ShowStringCharacters -> True, NumberMarks -> True], FullForm]',
"MakeBoxes expression FullForm",
),
(
"MakeBoxes[TeXForm[F[x]]]",
'InterpretationBox[""F(x)"", TeXForm[F[x]], Editable -> True, AutoDelete -> True]',
"TeXForm, expression",
),
# Arithmetic
("MakeBoxes[a-b]", 'RowBox[{"a", "-", "b"}]', "difference, StandardForm"),
(
"MakeBoxes[a-b//InputForm]",
'InterpretationBox[StyleBox["a - b", ShowStringCharacters -> True, NumberMarks -> True], InputForm[a - b], Editable -> True, AutoDelete -> True]',
"difference, InputForm",
),
(
"MakeBoxes[a-b//OutputForm]",
'InterpretationBox[PaneBox[""a - b""], OutputForm[a - b], Editable -> False]',
"difference, OutputForm",
),
(
"MakeBoxes[a-b//FullForm]",
'TagBox[StyleBox[RowBox[{"Plus", "[", RowBox[{"a", ",", RowBox[{"Times", "[", RowBox[{RowBox[{"-", "1"}], ",", "b"}], "]"}]}], "]"}], ShowSpecialCharacters -> False, ShowStringCharacters -> True, NumberMarks -> True], FullForm]',
"Difference, FullForm",
),
(
"MakeBoxes[a-b//TeXForm]",
' InterpretationBox[""a-b"", TeXForm[a-b], Editable -> True, AutoDelete -> True]',
"Difference, TeXForm",
),
],
)
@skip_or_fail
def test_makeboxes_basic_forms(str_expr, str_expected, fail_msg, msgs):
check_evaluation(
str_expr,
str_expected,
to_string_expr=True,
to_string_expected=True,
hold_expected=True,
failure_message=fail_msg,
expected_messages=msgs,
)


@pytest.mark.parametrize(
("str_expr", "str_expected", "fail_msg", "msgs"),
[
Expand Down Expand Up @@ -83,15 +166,19 @@ def test_makeboxes_real(str_expr, str_expected, msg):
("str_expr", "str_expected", "msg"),
[
(r"MakeBoxes[1.4`]", r"1.4`", "StandardForm always shows a precision mark."),
(r"MakeBoxes[OutputForm[1.4]]", r"1.4", "OutputForm, no mark for MachineReal"),
(
r"MakeBoxes[OutputForm[1.4]]",
r'InterpretationBox[PaneBox["1.4"], 1.4, Editable -> False]',
"MachineReal, OutputForm",
),
(
r"MakeBoxes[3.142`3]",
r"3.142`3",
"StandardForm with PrecisionReal shows all the stored digits, and precision",
"StandadForm with PrecisionReal shows all the stored digits, and precision.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a regression here.

),
(
r"MakeBoxes[OutputForm[3.142`3]]",
r"3.14",
r'InterpretationBox[PaneBox["3.14"], 3.14, Editable -> False]',
"OutputForm trims digits up to precision.",
),
(r"MakeBoxes[1.5`20]", r"1.5`20.", None),
Expand All @@ -101,7 +188,6 @@ def test_makeboxes_real(str_expr, str_expected, msg):
(r"MakeBoxes[34.*^3]", r"34000.`", None),
(r"MakeBoxes[0`]", r"0.`", None),
(r"MakeBoxes[0``30]", r"0.``30.", None),
(r"MakeBoxes[0.`]", r"0.`", None),
(r"MakeBoxes[0.`3]", r"0.`", None),
(r"MakeBoxes[0.``30]", r"0.``30.", None),
(r"MakeBoxes[-14]", r"RowBox[{-, 14}]", None),
Expand Down
Loading