Skip to content

Commit 56a5019

Browse files
authored
Enable test_stdmodules (#1048)
1 parent f574a7e commit 56a5019

2 files changed

Lines changed: 61 additions & 63 deletions

File tree

Src/IronPythonTest/Cases/IronPythonCasesManifest.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ IsolationLevel=PROCESS # https://github.com/IronLanguages/ironpython3/issues/489
107107
[IronPython.test_stdconsole]
108108
Ignore=true
109109

110-
[IronPython.test_stdmodules]
111-
Ignore=true
112-
113110
[IronPython.test_superconsole]
114111
Ignore=true
115112
Reason=Uses MAUI framework, which was MS internal?

Tests/test_stdmodules.py

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12,68 +12,70 @@
1212
import sys
1313
import unittest
1414

15-
from iptest import IronPythonTestCase, is_cpython, is_netcoreapp, is_posix, run_test, skipUnlessIronPython
15+
from iptest import IronPythonTestCase, is_cli, is_cpython, is_posix, run_test, skipUnlessIronPython
1616

1717
class StdModulesTest(IronPythonTestCase):
1818

1919
def test_cp8678(self):
20-
from itertools import izip
2120
x = iter(range(4))
2221
expected = ([0, 1], [2, 3])
2322
actual = []
24-
25-
for i, j in izip(x, x):
23+
24+
for i, j in zip(x, x):
2625
actual.append([i, j])
2726

2827
self.assertEqual(len(expected), len(actual))
29-
for i in xrange(len(expected)):
28+
for i in range(len(expected)):
3029
self.assertEqual(expected[i], actual[i])
3130

3231
def test_cp10825(self):
33-
import urllib
32+
import urllib.request
3433
from time import sleep
35-
34+
3635
#Give it five chances to connect
3736
temp_url = None
38-
39-
for i in xrange(5):
37+
err = None
38+
39+
for i in range(5):
4040
try:
41-
temp_url = urllib.urlopen("http://www.microsoft.com")
41+
temp_url = urllib.request.urlopen("http://www.microsoft.com")
4242
break
4343
except Exception as e:
44+
err = e
4445
print(".", end="")
4546
sleep(5)
4647
continue
47-
if temp_url==None: raise e
48-
48+
if temp_url is None: raise err
49+
4950
try:
5051
self.assertTrue(temp_url.url.startswith("http://www.microsoft.com"))
5152
finally:
5253
temp_url.close()
5354

5455
def test_cp5566(self):
5556
import base64
56-
self.assertEqual(base64.decodestring('w/=='), '\xc3')
57-
test_str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$%^&*()_+-=[]\{}|;':,.//<>?\""
58-
test_str+= "/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S/T/U/V/W/X/Y/Z/0/1/2/3/4/5/6/7/8/9/~/!/@/#/$/%/^/&/*/(/)/_/+/-/=/[/]/\/{/}/|/;/'/:/,/.///</>/?\""
59-
60-
for str_function in [str, unicode]:
61-
self.assertEqual(base64.decodestring(str_function(test_str)),
62-
'i\xb7\x1dy\xf8!\x8a9%\x9az)\xaa\xbb-\xba\xfc1\xcb0\x01\x081\x05\x18r\t(\xb3\r8\xf4\x11I5\x15Yv\x19\xd3]\xb7\xe3\x9e\xbb\xf3\xdf')
57+
self.assertEqual(base64.decodebytes(b'w/=='), b'\xc3')
58+
59+
test_str = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$%^&*()_+-=[]\{}|;':,.//<>?\""
60+
test_str+= b"/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S/T/U/V/W/X/Y/Z/0/1/2/3/4/5/6/7/8/9/~/!/@/#/$/%/^/&/*/(/)/_/+/-/=/[/]/\/{/}/|/;/'/:/,/.///</>/?\""
61+
self.assertEqual(base64.decodebytes(test_str),
62+
b'i\xb7\x1dy\xf8!\x8a9%\x9az)\xaa\xbb-\xba\xfc1\xcb0\x01\x081\x05\x18r\t(\xb3\r8\xf4\x11I5\x15Yv\x19\xd3]\xb7\xe3\x9e\xbb\xf3\xdf')
6363

6464
def test_cp35507(self):
6565
import base64
66-
self.assertEqual(base64.b64decode('MTIzNP8='), '1234\xff')
67-
self.assertEqual(base64.b64decode(b'MTIzNP8='), '1234\xff')
68-
self.assertEqual(base64.b64encode('1234\xff'), 'MTIzNP8=')
69-
self.assertEqual(base64.b64encode(b'1234\xff'), 'MTIzNP8=')
70-
71-
import cPickle
72-
one = cPickle.dumps(1)
73-
self.assertEqual(1, cPickle.loads("I1\n."))
74-
self.assertEqual(1, cPickle.loads(b"I1\n."))
75-
self.assertEqual(1, cPickle.loads(one))
76-
self.assertEqual(1, cPickle.loads(bytes(one)))
66+
self.assertEqual(base64.b64decode('MTIzNP8='), b'1234\xff')
67+
self.assertEqual(base64.b64decode(b'MTIzNP8='), b'1234\xff')
68+
with self.assertRaises(TypeError):
69+
base64.b64encode('1234\xff')
70+
self.assertEqual(base64.b64encode(b'1234\xff'), b'MTIzNP8=')
71+
72+
import pickle
73+
one = pickle.dumps(1)
74+
with self.assertRaises(TypeError):
75+
pickle.loads("I1\n.")
76+
self.assertEqual(1, pickle.loads(b"I1\n."))
77+
self.assertEqual(1, pickle.loads(one))
78+
self.assertEqual(1, pickle.loads(bytes(one)))
7779

7880
@skipUnlessIronPython()
7981
def test_cp13618(self):
@@ -84,7 +86,7 @@ def test_cp13618(self):
8486
def test_cp12907(self):
8587
#from codeop import compile_command, PyCF_DONT_IMPLY_DEDENT
8688
from os import unlink
87-
89+
8890
f_name = "fake_stdout.txt"
8991
test_list = [
9092
("print(1)",
@@ -103,25 +105,25 @@ def test_cp12907(self):
103105
"exec", ["1\n"]),
104106
]
105107

106-
if is_cpython: #http://ironpython.codeplex.com/workitem/28221
108+
if is_cpython: # https://github.com/IronLanguages/ironpython3/issues/1047
107109
test_list.append(("if 1:\n print(1)", "exec", ["1\n"]))
108-
110+
109111
for test_case, kind, expected in test_list:
110-
112+
111113
c = compile(test_case, "", kind, 0x200, 1)
112114
try:
113115
orig_stdout = sys.stdout
114-
116+
115117
sys.stdout = open(f_name, "w")
116118
exec(c)
117119
sys.stdout.close()
118-
120+
119121
t_file = open(f_name, "r")
120122
lines = t_file.readlines()
121123
t_file.close()
122-
124+
123125
self.assertEqual(lines, expected)
124-
126+
125127
finally:
126128
sys.stdout = orig_stdout
127129
os.unlink(f_name)
@@ -133,24 +135,24 @@ def test_cp12907(self):
133135
("def f(n):\n return n*n\n\nf(3)\n", "single"),
134136
("if 1:\n print(1)", "single"),
135137
]
136-
if not is_cpython: #http://ironpython.codeplex.com/workitem/28221
138+
if not is_cpython: # https://github.com/IronLanguages/ironpython3/issues/1047
137139
bad_test_list.append(("if 1:\n print(1)", "exec"))
138-
140+
139141
for test_case, kind in bad_test_list:
140142
print(test_case, kind)
141143
self.assertRaises(SyntaxError, compile, test_case, "", kind, 0x200, 1)
142144

143145
def test_cp12009(self):
144146
import os
145147
import shutil
146-
148+
147149
dir1 = "temp_test_stdmodules_dir"
148150
dir2 = dir1 + "2"
149-
151+
150152
os.mkdir(dir1)
151153
f = open(os.path.join(dir1, "stuff.txt"), "w")
152154
f.close()
153-
155+
154156
try:
155157
shutil.copytree(dir1, dir2)
156158
self.assertTrue("stuff.txt" in os.listdir(dir2))
@@ -159,25 +161,24 @@ def test_cp12009(self):
159161
os.unlink(os.path.join(t_dir, "stuff.txt"))
160162
os.rmdir(t_dir)
161163

162-
@unittest.skipIf(is_netcoreapp and is_posix, 'TODO: figure out')
163164
def test_cp17040(self):
164-
ec = os.system("%s -tt -c \"import os\"" %
165-
(sys.executable))
165+
import subprocess
166+
ec = subprocess.call([sys.executable, "-tt", "-c", "import os"])
166167
self.assertEqual(ec, 0)
167168

168169
@skipUnlessIronPython()
169170
def test_cp13401(self):
170171
import System
171172
import copy
172-
173+
173174
#A few special cases
174175
StringSplitOptions_None = getattr(System.StringSplitOptions, "None")
175176
self.assertEqual(System.Char.MinValue, copy.copy(System.Char.MinValue))
176177
self.assertTrue(System.Char.MinValue != copy.copy(System.Char.MaxValue))
177178
self.assertEqual(StringSplitOptions_None, copy.copy(StringSplitOptions_None))
178179
self.assertEqual(System.StringSplitOptions.RemoveEmptyEntries, copy.copy(System.StringSplitOptions.RemoveEmptyEntries))
179180
self.assertTrue(StringSplitOptions_None != copy.copy(System.StringSplitOptions.RemoveEmptyEntries))
180-
181+
181182
#Normal cases
182183
test_dict = { System.Byte : [System.Byte.MinValue, System.Byte.MinValue+1, System.Byte.MaxValue, System.Byte.MaxValue-1],
183184
System.Char : [],
@@ -187,12 +188,12 @@ def test_cp13401(self):
187188
System.Int64 : [System.Int64.MinValue, System.Int64.MinValue+1, System.Int64.MaxValue, System.Int64.MaxValue-1],
188189
System.Double : [0.00, 3.14],
189190
}
190-
191+
191192
for key in test_dict.keys():
192193
temp_type = key
193-
self.assertTrue(hasattr(temp_type, "__reduce_ex__"),
194+
self.assertTrue(hasattr(temp_type, "__reduce_ex__"),
194195
"%s has no attribute '%s'" % (str(temp_type), "__reduce_ex__"))
195-
196+
196197
for temp_value in test_dict[key]:
197198
x = temp_type(temp_value)
198199
x_copy = copy.copy(x)
@@ -202,33 +203,32 @@ def test_cp13401(self):
202203
def test_cp7008(self):
203204
import os
204205
import sys
205-
206+
206207
self.assertTrue(os.path.isfile(sys.executable))
207208
self.assertTrue(not os.path.isfile('"' + sys.executable + '"'))
208-
209+
209210
@skipUnlessIronPython()
210211
def test_get_set_locale(self):
211212
import locale
212213
locale.setlocale(locale.LC_ALL, 'en-US')
213214
loc = locale.getlocale(locale.LC_ALL)
214215
self.assertEqual(loc, ('en_US','ISO8859-1'))
215-
216+
216217
locale.setlocale(locale.LC_ALL, 'C')
217218
loc = locale.getlocale(locale.LC_ALL)
218219
self.assertEqual(loc, (None,None))
219220

220-
self.assertTrue(locale.setlocale(locale.LC_ALL, '') != None)
221+
self.assertTrue(locale.setlocale(locale.LC_ALL, '') is not None)
221222
if not is_posix: # TODO: figure this out
222-
self.assertTrue(locale.getlocale() != None)
223+
self.assertTrue(locale.getlocale() is not None)
223224

224225
def test_cp17819(self):
225226
import xml.sax
226227
self.assertEqual(xml.sax._false, 0)
227228

228-
#@unittest.skipIf(is_cli, 'CPython')
229229
def test_cp20162(self):
230230
import collections
231-
self.assertRaisesMessage(TypeError, "deque() takes at most 2 arguments (3 given)",
231+
self.assertRaisesMessage(TypeError, "__init__() takes at most 2 arguments (3 given)" if is_cli else "deque() takes at most 2 arguments (3 given)",
232232
collections.deque, 'abc', 2, 2)
233233

234234
def test_cp20603(self):
@@ -248,13 +248,14 @@ def test_cp21929(self):
248248

249249
def test_cp34188(self):
250250
import locale
251+
import functools
251252
locale.setlocale(locale.LC_COLLATE,"de_CH")
252-
self.assertTrue(sorted([u'a', u'z', u'�'], cmp=locale.strcoll) == sorted([u'a', u'z', u'�'], key=locale.strxfrm))
253+
self.assertTrue(sorted([u'a', u'z', u'�'], key=functools.cmp_to_key(locale.strcoll)) == sorted([u'a', u'z', u'�'], key=locale.strxfrm))
253254

254255
def test_gh1144(self):
255256
from collections import deque
256257
a = deque(maxlen=0)
257258
a.append("a")
258259
self.assertEqual(len(a), 0)
259260

260-
run_test(__name__)
261+
run_test(__name__)

0 commit comments

Comments
 (0)