Skip to content

Commit c3bd7e9

Browse files
authored
Merge pull request #1181 from mathics/fixesimportexportstring
This PR fixes some bugs introduced in M$Windows-compatible tests and makes mathics compatible with IWolfram (I hope).
2 parents 13cda03 + b5167c5 commit c3bd7e9

5 files changed

Lines changed: 1232 additions & 383 deletions

File tree

mathics/builtin/files.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3705,7 +3705,7 @@ class Compress(Builtin):
37053705
37063706
"""
37073707

3708-
attributes = "Protected"
3708+
attributes = ("Protected",)
37093709

37103710
options = {
37113711
"Method": "{}",
@@ -3720,9 +3720,9 @@ def apply(self, expr, evaluation, options):
37203720
string = string.encode("utf-8")
37213721

37223722
# TODO Implement other Methods
3723+
# Shouldn't be this a ByteArray?
37233724
result = zlib.compress(string)
3724-
result = base64.encodebytes(result).decode("utf8")
3725-
3725+
result = base64.b64encode(result).decode("utf8")
37263726
return String(result)
37273727

37283728

@@ -3744,12 +3744,12 @@ class Uncompress(Builtin):
37443744
= x ^ 2 + y Sin[x] + 10 Log[15]
37453745
"""
37463746

3747-
attributes = "Protected"
3747+
attributes = ("Protected",)
37483748

37493749
def apply(self, string, evaluation):
37503750
"Uncompress[string_String]"
3751-
string = string.get_string_value().encode("utf-8")
3752-
string = base64.decodebytes(string)
3751+
string = string.get_string_value() #.encode("utf-8")
3752+
string = base64.b64decode(string)
37533753
tmp = zlib.decompress(string)
37543754
tmp = tmp.decode("utf-8")
37553755
return evaluation.parse(tmp)

mathics/builtin/importexport.py

Lines changed: 1215 additions & 370 deletions
Large diffs are not rendered by default.

test/helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ def check_evaluation(str_expr: str, str_expected: str, message=""):
1010
"""Helper function to test that a WL expression against
1111
its results"""
1212
result = session.evaluate(str_expr)
13+
print("result=",result)
1314
expected = session.evaluate(str_expected)
14-
15+
print("expected=",expected)
1516
print(time.asctime())
1617
print(message)
1718
if message:

test/test_files.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ def _evaluate(str_expression):
2323
def test_non_win32_compress():
2424
for str_expr, str_expected, message in (
2525
(
26-
'Compress["―"]',
27-
"= eJxTetQwVQkABwMCPA=="
26+
r'Compress["―"]',
27+
'"eJxTetQwVQkABwMCPA=="',
28+
""
2829
),
29-
("Uncompress[eJxTUlACAADLAGU=%]",
30-
"―"
30+
(r'Uncompress["eJxTetQwVQkABwMCPA=="]',
31+
r'"―"',
32+
""
3133
),
3234
):
3335
check_evaluation(str_expr, str_expected, message)

test/test_inout.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
def test_non_win32_print():
1111
for str_expr, str_expected, message in (
1212
(
13-
'Print["\\[Mu]"]',
14-
"μ"
13+
'Print["\\[Mu]"]',
14+
"System`Null",
15+
"μ"
1516
),
1617
):
1718
check_evaluation(str_expr, str_expected, message)

0 commit comments

Comments
 (0)