Skip to content

Commit 460136d

Browse files
authored
Test cleanup (#1400)
* Test cleanup * Add missing import * Re-add skipIf is_mono
1 parent 84f2352 commit 460136d

47 files changed

Lines changed: 596 additions & 650 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Src/IronPython/Runtime/PythonContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ internal bool TryLoadAssemblyFromFileWithPath(string path, out Assembly res) {
11921192
}
11931193

11941194
internal Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) {
1195-
if (args.RequestingAssembly != null && !_loadedAssemblies.Contains(args.RequestingAssembly)) {
1195+
if (args.RequestingAssembly != null && !(args.RequestingAssembly == typeof(PythonContext).Assembly || _loadedAssemblies.Contains(args.RequestingAssembly))) {
11961196
return null;
11971197
}
11981198

Tests/modules/io_related/test_codecs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,11 +2050,11 @@ def handler1(ex):
20502050
return ("", ex.end + 1)
20512051

20522052
codecs.register_error("test_unicode_error1", handler1)
2053-
if is_cpython:
2054-
res = "+++\xac\u1234\u20ac\u8000---".encode("ptcp154", "test_unicode_error1")
2055-
self.assertEqual(res, b"+++\xac--")
2056-
else:
2053+
if is_cli:
20572054
with self.assertRaises(NotImplementedError):
20582055
res = "+++\xac\u1234\u20ac\u8000---".encode("ptcp154", "test_unicode_error1")
2056+
else:
2057+
res = "+++\xac\u1234\u20ac\u8000---".encode("ptcp154", "test_unicode_error1")
2058+
self.assertEqual(res, b"+++\xac--")
20592059

20602060
run_test(__name__)

Tests/modules/io_related/test_copyreg.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,35 @@ class CopyRegTest(unittest.TestCase):
2222
def test_constructor_neg(self):
2323
'https://github.com/IronLanguages/main/issues/443'
2424
class KOld: pass
25-
25+
2626
self.assertRaises(TypeError, copyreg.constructor, KOld)
2727

28-
28+
2929
def test_constructor(self):
3030
#the argument can be callable
3131
copyreg.constructor(testclass)
32-
32+
3333
#the argument can not be callable
3434
self.assertRaises(TypeError,copyreg.constructor,0)
3535
self.assertRaises(TypeError,copyreg.constructor,"Hello")
3636
self.assertRaises(TypeError,copyreg.constructor,True)
3737

3838

3939
def test__newobj__(self):
40-
40+
4141
#the second argument is omitted
4242
result = None
4343
result = copyreg.__newobj__(object)
4444
self.assertTrue(result != None,
4545
"The method __newobj__ did not return an object")
46-
46+
4747
#the second argument is an int object
4848
result = None
4949
a = 1
5050
result = copyreg.__newobj__(int,a)
5151
self.assertTrue(result != None,
5252
"The method __newobj__ did not return an object")
53-
53+
5454
#the method accept multiple arguments
5555
reseult = None
5656
class customtype(object):
@@ -121,27 +121,27 @@ def test_extension_registry(self):
121121
code = result[key]
122122
self.assertTrue(code == 123,
123123
"The _extension_registry attribute did not return the correct value")
124-
124+
125125
copyreg.add_extension('1','2',999)
126126
result = copyreg._extension_registry
127127
code = result[('1','2')]
128128
self.assertTrue(code == 999,
129129
"The _extension_registry attribute did not return the correct value")
130-
130+
131131
#general test, try to set the attribute then to get it
132132
myvalue = 3885
133133
copyreg._extension_registry["key"] = myvalue
134134
result = copyreg._extension_registry["key"]
135135
self.assertTrue(result == myvalue,
136136
"The set or the get of the attribute failed")
137-
137+
138138
def test_inverted_registry(self):
139139
copyreg.add_extension('obj1','obj2',64)
140140
#get
141141
result = copyreg._inverted_registry[64]
142142
self.assertTrue(result == ('obj1','obj2'),
143143
"The _inverted_registry attribute did not return the correct value")
144-
144+
145145
#set
146146
value = ('newmodule','newobj')
147147
copyreg._inverted_registry[10001] = value
@@ -158,7 +158,7 @@ def test_extension_cache(self):
158158
result = copyreg._extension_cache['cache1']
159159
self.assertTrue(result == value,
160160
"The get and set of the attribute failed")
161-
161+
162162
value = rand.getrandbits(16)
163163
copyreg._extension_cache['cache2'] = value
164164
result = copyreg._extension_cache['cache2']
@@ -171,18 +171,18 @@ def test_extension_cache(self):
171171
result = copyreg._extension_cache['cache1']
172172
self.assertTrue(result == value2,
173173
"The get and set of the attribute failed")
174-
174+
175175
if 'cache1' not in copyreg._extension_cache or 'cache2' not in copyreg._extension_cache:
176176
Fail("Set of the attribute failed")
177-
177+
178178
copyreg.clear_extension_cache()
179179
if 'cache1' in copyreg._extension_cache or 'cache2' in copyreg._extension_cache:
180180
Fail("The method clear_extension_cache did not work correctly ")
181181

182182
def test_reconstructor(self):
183183
reconstructor_copy = copyreg._reconstructor
184184
try:
185-
obj = copyreg._reconstructor(object, object, None)
185+
obj = copyreg._reconstructor(object, object, None)
186186
self.assertTrue(type(obj) is object)
187187

188188
#set,get, the value is a random int
@@ -192,82 +192,81 @@ def test_reconstructor(self):
192192
result = copyreg._reconstructor
193193
self.assertTrue(result == value,
194194
"set or get of the attribute failed!")
195-
195+
196196
#the value is a string
197197
value2 = "value2"
198198
copyreg._reconstructor = value2
199199
result = copyreg._reconstructor
200200
self.assertTrue(result == value2,
201201
"set or get of the attribute failed!")
202-
202+
203203
#the value is a custom type object
204204
value3 = testclass()
205205
copyreg._reconstructor = value3
206206
result = copyreg._reconstructor
207207
self.assertTrue(result == value3,
208208
"set or get of the attribute failed!")
209-
finally:
209+
finally:
210210
copyreg._reconstructor = reconstructor_copy
211-
211+
212212

213213
def test_pickle(self):
214214
def testfun():
215215
return testclass()
216-
216+
217217
# type is a custom type
218218
copyreg.pickle(type(testclass), testfun)
219-
219+
220220
#type is a system type
221221
systype = type(random.Random())
222222
copyreg.pickle(systype,random.Random.random)
223-
223+
224224
#function is not callable
225225
func = "hello"
226226
self.assertRaises(TypeError,copyreg.pickle,testclass,func)
227227
func = 1
228228
self.assertRaises(TypeError,copyreg.pickle,testclass,func)
229229
func = random.Random()
230230
self.assertRaises(TypeError,copyreg.pickle,testclass,func)
231-
231+
232232
def test_dispatch_table(self):
233233
result = copyreg.dispatch_table
234234
#CodePlex Work Item 8522
235235
#self.assertEqual(5,len(result))
236-
236+
237237
temp = {
238238
"abc":"abc123",
239239
"def":"def123",
240240
"ghi":"ghi123"
241241
}
242242
copyreg.dispatch_table = temp
243243
self.assertEqual(temp,copyreg.dispatch_table)
244-
244+
245245
temp = {
246246
1:"abc123",
247247
2:"def123",
248248
3:"ghi123"
249249
}
250250
copyreg.dispatch_table = temp
251251
self.assertEqual(temp,copyreg.dispatch_table)
252-
252+
253253
temp = {
254254
1:123,
255255
8:789,
256256
16:45465
257257
}
258258
copyreg.dispatch_table = temp
259259
self.assertEqual(temp,copyreg.dispatch_table)
260-
260+
261261
#set dispathc_table as empty
262262
temp ={}
263263
copyreg.dispatch_table = temp
264264
self.assertEqual(temp,copyreg.dispatch_table)
265265

266266
def test_pickle_complex(self):
267267
#http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21908
268-
#if not is_cli:
269268
self.assertEqual(copyreg.pickle_complex(1), (complex, (1, 0)))
270-
269+
271270
#negative tests
272271
self.assertRaises(AttributeError,copyreg.pickle_complex,"myargu")
273272
obj2 = myCustom2()

Tests/modules/network_related/test__socket.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,28 +186,38 @@ def test_getprotobyname(self):
186186
'''Tests _socket.getprotobyname'''
187187
#IP and CPython
188188
proto_map = {
189-
"icmp": _socket.IPPROTO_ICMP,
190-
"ip": _socket.IPPROTO_IP,
191-
"tcp": _socket.IPPROTO_TCP,
192-
"udp": _socket.IPPROTO_UDP,
189+
"icmp": _socket.IPPROTO_ICMP,
190+
"ip": _socket.IPPROTO_IP,
191+
"tcp": _socket.IPPROTO_TCP,
192+
"udp": _socket.IPPROTO_UDP,
193193
}
194194

195-
#supported only by IP
196-
if is_cli:
197-
proto_map.update(
198-
{"dstopts": _socket.IPPROTO_DSTOPTS,
195+
if is_cli or sys.version_info >= (3,8):
196+
proto_map.update({
197+
"ipv6": _socket.IPPROTO_IPV6,
198+
"esp": _socket.IPPROTO_ESP,
199+
"pup": _socket.IPPROTO_PUP, #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21918
200+
"ggp": _socket.IPPROTO_GGP, #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21918
201+
})
202+
203+
proto_map_cli_only = {
204+
"dstopts": _socket.IPPROTO_DSTOPTS,
199205
"none": _socket.IPPROTO_NONE,
200206
"raw": _socket.IPPROTO_RAW,
201207
"ipv4": _socket.IPPROTO_IPV4,
202-
"ipv6": _socket.IPPROTO_IPV6,
203-
"esp": _socket.IPPROTO_ESP,
204208
"fragment": _socket.IPPROTO_FRAGMENT,
205209
"nd": _socket.IPPROTO_ND,
206210
"icmpv6": _socket.IPPROTO_ICMPV6,
207211
"routing": _socket.IPPROTO_ROUTING,
208-
"pup": _socket.IPPROTO_PUP, #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21918
209-
"ggp": _socket.IPPROTO_GGP, #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21918
210-
})
212+
}
213+
214+
for proto_name, good_val in proto_map_cli_only.items():
215+
if is_cli:
216+
temp_val = _socket.getprotobyname(proto_name)
217+
self.assertEqual(temp_val, good_val)
218+
else:
219+
with self.assertRaises(OSError):
220+
_socket.getprotobyname(proto_name)
211221

212222
for proto_name, good_val in proto_map.items():
213223
temp_val = _socket.getprotobyname(proto_name)

Tests/modules/network_related/test__ssl.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ def test___doc__(self):
9494
for documentation."""
9595
self.assertEqual(_ssl.__doc__, expected_doc)
9696

97-
def test__test_decode_cert(self):
98-
if is_cli and hasattr(_ssl, "decode_cert"):
99-
self.fail("Please add a test for _ssl.decode_cert")
100-
print('TODO: no implementation to test yet.')
101-
10297
def test_SSLType_ssl(self):
10398
'''
10499
Should be essentially the same as _ssl.sslwrap. It's not though and will

Tests/modules/system_related/test_nt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def test_putenv(self):
356356
self.assertRaises(TypeError, nt.putenv, 1, "xyz")
357357
self.assertRaises(TypeError, nt.putenv, "ABC", 1)
358358

359-
@unittest.skipUnless(is_cli, "CPython has no nt.unsetenv function")
359+
@unittest.skipUnless(is_cli or sys.version_info >= (3,9), "CPython has no nt.unsetenv function")
360360
def test_unsetenv(self):
361361
#simple sanity check
362362
nt.putenv("ipy_test_env_var", "xyz")
@@ -470,7 +470,7 @@ def test_spawnv(self):
470470
ping_cmd = os.path.join(os.environ["windir"], "system32", "ping")
471471
nt.spawnv(nt.P_WAIT, ping_cmd , ["ping"])
472472
nt.spawnv(nt.P_WAIT, ping_cmd , ["ping","127.0.0.1","-n","1"])
473-
473+
474474
@unittest.skipUnless(sys.platform == "win32", 'windir is Windows specific')
475475
def test_spawnve(self):
476476
ping_cmd = os.path.join(os.environ["windir"], "system32", "ping")
@@ -946,7 +946,7 @@ def test_popen_cp34837(self):
946946
p = subprocess.Popen("whoami", env=os.environ)
947947
self.assertTrue(p!=None)
948948
p.wait()
949-
949+
950950
def test_fsync(self):
951951
fsync_file_name = 'text_fsync.txt'
952952
fd = nt.open(fsync_file_name, nt.O_WRONLY | nt.O_CREAT)

Tests/modules/system_related/test_signal.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
'''
1010

1111
import signal
12-
import unittest
12+
import sys
1313

1414
from iptest import IronPythonTestCase, is_cli, run_test
1515

@@ -53,27 +53,29 @@ def test_module_constants(self):
5353
self.assertEqual(signal.SIG_IGN, 1)
5454

5555
def test_doc(self):
56-
self.assertTrue("get the signal action for a given signal" in signal.__doc__)
56+
if sys.version_info >= (3,5):
57+
self.assertIsNone(signal.__doc__)
58+
else:
59+
self.assertTrue("get the signal action for a given signal" in signal.__doc__)
5760
self.assertTrue("The default handler for SIGINT installed by Python" in signal.default_int_handler.__doc__)
5861
self.assertTrue("Return the current action for the given signal" in signal.getsignal.__doc__)
5962
self.assertTrue("Set the action for the given signal" in signal.signal.__doc__)
6063

61-
@unittest.skipUnless(is_cli, 'http://bugs.python.org/issue9324')
6264
def test_signal_signal_neg(self):
6365
def a(b, c):
6466
pass
6567

66-
WEIRD_WORKING_CASES = [6]
68+
WEIRD_WORKING_CASES = [6] if is_cli else []
6769
NO_SUCH_DIR = [21]
6870

6971
for x in range(1, 23):
7072
if x in SUPPORTED_SIGNALS: continue
7173
if x in WEIRD_WORKING_CASES: continue
72-
self.assertRaises(RuntimeError,
74+
self.assertRaises(RuntimeError if is_cli else ValueError,
7375
signal.signal, x, a)
7476

7577
for x in [-2, -1, 0, 23, 24, 25]:
76-
self.assertRaisesMessage(ValueError, "signal number out of range",
78+
self.assertRaisesMessage(ValueError, "signal number out of range" if is_cli else "invalid signal value",
7779
signal.signal, x, a)
7880

7981
def bad_sig0(): pass
@@ -86,9 +88,10 @@ def bad_sig3(a,b,c): pass
8688
self.assertRaisesMessage(TypeError, "signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object",
8789
signal.signal, y, x)
8890

89-
@unittest.skipUnless(is_cli, 'http://bugs.python.org/issue9324')
9091
def test_signal_signal(self):
91-
WORKING_CASES = SUPPORTED_SIGNALS + [6]
92+
WORKING_CASES = SUPPORTED_SIGNALS
93+
if is_cli:
94+
WORKING_CASES += [6]
9295
WEIRD_CASES = {
9396
6: None,
9497
2: signal.default_int_handler}

0 commit comments

Comments
 (0)