Skip to content

Commit c320553

Browse files
committed
improving test
1 parent 6f84850 commit c320553

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

test/test_custom_boxconstruct.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from mathics.core.expression import (Symbol, Atom, String, Expression)
66
from mathics.builtin.base import BoxConstruct, AtomBuiltin, Predefined
7+
from mathics.builtin.graphics import GRAPHICS_OPTIONS
78

89
class CustomBoxConstruct(BoxConstruct):
910
def __init__(self, evaluation):
@@ -36,6 +37,39 @@ def apply_to_boxes(self, evaluation):
3637
'System`MakeBoxes[System`CustomAtom, StandardForm|TraditionalForm|OutputForm|InputForm]'
3738
return CustomBoxConstruct(evaluation=evaluation)
3839

40+
41+
class CustomGraphicsBox(BoxConstruct):
42+
"""
43+
44+
"""
45+
options = GRAPHICS_OPTIONS
46+
attributes = ("HoldAll", "ReadProtected")
47+
48+
49+
def apply_box(self, elems, evaluation, options):
50+
"""System`MakeBoxes[System`Graphics[elems_, System`OptionsPattern[System`Graphics]],
51+
System`StandardForm|System`TraditionalForm|System`OutputForm]"""
52+
instance = CustomGraphicsBox(*(elems._leaves), evaluation=evaluation)
53+
return instance
54+
55+
def boxes_to_text(self, leaves=None, **options):
56+
if leaves:
57+
self._leaves = leaves
58+
return "--custom graphics--: I should plot " + self._leaves.__str__() +" items"
59+
60+
def boxes_to_tex(self, leaves=None, **options):
61+
return "--custom graphics--: I should plot " + self._leaves.__str__() +" items"
62+
63+
def boxes_to_xml(self, leaves=None, **options):
64+
return "--custom graphics--: I should plot " + self._leaves.__str__() +" items"
65+
66+
def boxes_to_svg(self, evaluation):
67+
return "--custom graphics--: I should plot " + self._leaves.__str__() +" items"
68+
69+
70+
71+
72+
3973
def test_custom_boxconstruct():
4074
defs = session.evaluation.definitions
4175
instance_custom_atom = CustomAtom(expression=False)
@@ -44,3 +78,12 @@ def test_custom_boxconstruct():
4478
formatted = session.format_result().boxes_to_xml()
4579
assert formatted == "CustomBoxConstruct<<[1, 2, 3]>>"
4680

81+
82+
83+
def test_custom_graphicsbox_constructor():
84+
defs = session.evaluation.definitions
85+
instance_customgb_atom = CustomGraphicsBox(expression=False, evaluation=session.evaluation)
86+
instance_customgb_atom.contribute(defs, is_pymodule=True)
87+
expr = session.evaluate("MakeBoxes[Graphics[{Circle[{0,0},1]}], OutputForm]")
88+
formatted = session.format_result().boxes_to_xml()
89+
assert formatted == "--custom graphics--: I should plot (<Expression: System`Circle[System`List[0, 0], 1]>,) items"

0 commit comments

Comments
 (0)