Skip to content
Merged
Changes from 2 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
109 changes: 104 additions & 5 deletions test/builtin/test_makeboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,95 @@
DEBUGMAKEBOXES = int(os.environ.get("DEBUGMAKEBOXES", "0")) == 1

if DEBUGMAKEBOXES:
skip_or_fail = pytest.mark.xfail

def skip_or_fail(x):
return x

else:
skip_or_fail = pytest.mark.skip
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(
Expand Down Expand Up @@ -79,16 +165,29 @@ def test_makeboxes_real(str_expr, str_expected, msg):
@pytest.mark.parametrize(
("str_expr", "str_expected", "msg"),
[
(r"MakeBoxes[1.4]", r"1.4`", None),
(r"MakeBoxes[1.4`]", r"1.4`", None),
(r"MakeBoxes[1.4`]", r"1.4`", "StandardForm always shows a prec mark."),

@rocky rocky Dec 30, 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.

Suggested change
(r"MakeBoxes[1.4`]", r"1.4`", "StandardForm always shows a prec mark."),
(r"MakeBoxes[1.4`]", r"1.4`", "StandardForm always shows a precision mark."),

(
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",
"StandadForm with Prec real shows all the stored digits, and prec",

@rocky rocky Dec 30, 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.

Suggested change
"StandadForm with Prec real shows all the stored digits, and prec",
"StandardForm with real precision shows all the stored digits, and precision",

),
(
r"MakeBoxes[OutputForm[3.142`3]]",
r'InterpretationBox[PaneBox["3.14"], 3.14, Editable -> False]',
"OutputForm trims digits up to prec.",

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.

Suggested change
"OutputForm trims digits up to prec.",
"OutputForm trims digits up to 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.

The abbreviation "prec" can confuse me to mean precedence or preceding. While I see this as a parameter name in some WMA documentation, outside of that I am not seeing this in common use as a shorthand for precision.

),
(r"MakeBoxes[1.5`20]", r"1.5`20.", None),
(r"MakeBoxes[1.4`20]", r"1.4`20.", None),
(r"MakeBoxes[1.5``20]", r"1.5`20.1760912591", None),
(r"MakeBoxes[-1.4]", r"RowBox[{-, 1.4`}]", None),
(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