Skip to content

Commit 09afe33

Browse files
committed
Fix tests for multiline prints
1 parent fe95bbd commit 09afe33

4 files changed

Lines changed: 65 additions & 34 deletions

File tree

mathics/builtin/assignment.py

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -864,36 +864,51 @@ class Information(PrefixOperator):
864864
#> a = 2;
865865
#> Information[a]
866866
| a = 2
867-
#> f[x_] := x ^ 2
868-
#> g[f] ^:= 2
867+
.
868+
= Null
869+
870+
#> f[x_] := x ^ 2;
871+
#> g[f] ^:= 2;
869872
#> f::usage = "f[x] returns the square of x";
870873
#> Information[f]
871874
| f[x] returns the square of x
875+
.
876+
. f[x_] = x ^ 2
877+
.
878+
. g[f] ^= 2
879+
.
880+
= Null
881+
872882
873883
#> ? Table
874-
| 'Table[expr, {i, n}]'
875-
| evaluates expr with i ranging from 1 to n, returning
876-
| a list of the results.
877-
| 'Table[expr, {i, start, stop, step}]'
878-
| evaluates expr with i ranging from start to stop,
879-
| incrementing by step.
880-
| 'Table[expr, {i, {e1, e2, ..., ei}}]'
881-
| evaluates expr with i taking on the values e1, e2,
882-
| ..., ei.
884+
|
885+
. 'Table[expr, {i, n}]'
886+
. evaluates expr with i ranging from 1 to n, returning
887+
. a list of the results.
888+
. 'Table[expr, {i, start, stop, step}]'
889+
. evaluates expr with i ranging from start to stop,
890+
. incrementing by step.
891+
. 'Table[expr, {i, {e1, e2, ..., ei}}]'
892+
. evaluates expr with i taking on the values e1, e2,
893+
. ..., ei.
894+
.
895+
= Null
883896
884897
#> Information[Table]
885-
| 'Table[expr, {i, n}]'
886-
| evaluates expr with i ranging from 1 to n, returning
887-
| a list of the results.
888-
| 'Table[expr, {i, start, stop, step}]'
889-
| evaluates expr with i ranging from start to stop,
890-
| incrementing by step.
891-
| 'Table[expr, {i, {e1, e2, ..., ei}}]'
892-
| evaluates expr with i taking on the values e1, e2,
893-
| ..., ei.
894-
|
895-
| Attributes[Table] = {HoldAll, Protected}
896-
|
898+
|
899+
. 'Table[expr, {i, n}]'
900+
. evaluates expr with i ranging from 1 to n, returning
901+
. a list of the results.
902+
. 'Table[expr, {i, start, stop, step}]'
903+
. evaluates expr with i ranging from start to stop,
904+
. incrementing by step.
905+
. 'Table[expr, {i, {e1, e2, ..., ei}}]'
906+
. evaluates expr with i taking on the values e1, e2,
907+
. ..., ei.
908+
.
909+
. Attributes[Table] = {HoldAll, Protected}
910+
.
911+
= Null
897912
"""
898913

899914
operator = "??"
@@ -904,7 +919,7 @@ class Information(PrefixOperator):
904919

905920
def format_definition(self, symbol, evaluation, options, grid=True):
906921
'StandardForm,TraditionalForm,OutputForm: Information[symbol_, OptionsPattern[Information]]'
907-
ret = Symbol("Null")
922+
ret = Symbol('Null')
908923
lines = []
909924
if isinstance(symbol, String):
910925
evaluation.print_out(symbol)

mathics/builtin/inout.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,9 @@ class Print(Builtin):
18971897
| μ
18981898
#> Print["μ"]
18991899
| μ
1900+
#> Print["-Hola\\n-Qué tal?"]
1901+
| -Hola
1902+
. -Qué tal?
19001903
"""
19011904

19021905
def apply(self, expr, evaluation):

mathics/doc/doc.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,6 @@ class DocTest(object):
11431143
`|` Prints output.
11441144
"""
11451145
def __init__(self, index, testcase):
1146-
11471146
def strip_sentinal(line):
11481147
"""Remove END_LINE_SENTINAL from the end of a line if it appears.
11491148
@@ -1192,20 +1191,21 @@ def strip_sentinal(line):
11921191
if self.result is not None:
11931192
self.result += text
11941193
elif self.outs:
1195-
self.outs[-1] += text
1194+
self.outs[-1].text += text
11961195
continue
1197-
1196+
11981197
match = TESTCASE_OUT_RE.match(line)
11991198
symbol, text = match.group(1), match.group(2)
12001199
text = text.strip()
12011200
if symbol == '=':
12021201
self.result = text
1203-
elif text:
1204-
if symbol == ':':
1205-
out = Message('', '', text)
1206-
elif symbol == '|':
1207-
out = Print(text)
1208-
self.outs.append(out)
1202+
elif symbol == ':':
1203+
out = Message('', '', text)
1204+
self.outs.append(out)
1205+
elif symbol == '|':
1206+
out = Print(text)
1207+
self.outs.append(out)
1208+
12091209

12101210
def __str__(self):
12111211
return self.test

mathics/test.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,19 @@ def fail(why):
9090
info = sys.exc_info()
9191
sys.excepthook(*info)
9292
return False
93-
93+
if False:
94+
print("out=-----------------")
95+
for rr in out:
96+
for line in rr.text.splitlines():
97+
print(" <",line,">")
98+
print("wanted_out=-------------------")
99+
for rr in wanted_out:
100+
for line in rr.text.splitlines():
101+
print(" <",line,">")
102+
print("---------------------------------")
103+
94104
if not compare(result, wanted):
105+
print("result =!=wanted")
95106
fail_msg = "Result: %s\nWanted: %s" % (result, wanted)
96107
if out:
97108
fail_msg += "\nAdditional output:\n"
@@ -102,6 +113,8 @@ def fail(why):
102113
output_ok = False
103114
else:
104115
for got, wanted in zip(out, wanted_out):
116+
if False:
117+
print("got=<",got,"> wanted=<",wanted,">")
105118
if not got == wanted:
106119
output_ok = False
107120
break

0 commit comments

Comments
 (0)