Skip to content

Commit

Permalink
Go over pytest to make it align with WMA
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Sep 24, 2024
1 parent 801bd94 commit e9610d0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
5 changes: 4 additions & 1 deletion mathics/builtin/files_io/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ class InputStream(Builtin):
= String
"""

messages = {
"intpm": "Positive machine-sized integer expected at position 2 of `1`",
}
summary_text = "an input stream"


Expand Down Expand Up @@ -821,7 +824,7 @@ def eval(self, channel, types, evaluation: Evaluation, options: dict):
elif name == SymbolFailed:
return SymbolFailed

return eval_Read(name, n, types, stream, evaluation)
return eval_Read(name, n, types, stream, evaluation, options)

def eval_nostream(self, arg1, arg2, evaluation):
"Read[arg1_, arg2_]"
Expand Down
4 changes: 4 additions & 0 deletions mathics/eval/files_io/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ def read_name_and_stream_from_channel(channel, evaluation: Evaluation) -> tuple:

name, n = strm.elements

if n.value < 0:
evaluation.message("InputStream", "intpm", strm)
return None, None, None

stream = stream_manager.lookup_stream(n.get_int_value())
if stream is None:
evaluation.message("Read", "openx", strm)
Expand Down
20 changes: 13 additions & 7 deletions test/builtin/files_io/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ def test_close():
## Correctly formed InputString but not open
(
"Read[InputStream[String, -1], {Word, Number}]",
("InputStream[String, -1] is not open.",),
(
"Positive machine-sized integer expected at position 2 "
"of InputStream[String, -1]",
),
"Read[InputStream[String, -1], {Word, Number}]",
"",
),
Expand Down Expand Up @@ -266,12 +269,15 @@ def test_close():
"",
),
("Close[stream];", None, "Null", ""),
(
"Quiet[Read[stream, {Real}]]//{#1[[0]],#1[[1]][[0]],#1[[1]][[1]],#1[[2]]}&",
None,
"{Read, InputStream, String, {Real}}",
"",
),
# Rocky: I don't know what this is supposed to check, but WMA reports:
# Part::partd: Part specification of streapm[[1]] is longer than depth of object.
# and partd testing should be done somewhere else.
# (
# "Quiet[Read[stream, {Real}]]//{#1[[0]],#1[[1]][[0]],#1[[1]][[1]],#1[[2]]}&",
# None,
# "{Read, InputStream, String, {Real}}",
# "",
# ),
(
r'stream = StringToStream["\"abc123\""];ReadList[stream, "Invalid"]//{#1[[0]],#1[[2]]}&',
("Invalid is not a valid format specification.",),
Expand Down

0 comments on commit e9610d0

Please sign in to comment.