8000 Clean-up tests & remove warnfilter · pythonnet/pythonnet@1f5b5e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1f5b5e0

Browse files
committed
Clean-up tests & remove warnfilter
Ensure they are using the same functions in py2/py3 Ensure py2/py3 compat Misc. cleanup Add _compat The unittest module has been also updated to use the 'default' filter while running tests. DeprecationWarnings are ignored by default https://docs.python.org/3.3/library/warnings.html#updating-code-for-new-versions-of-python https://docs.python.org/3.3/library/warnings.html#default-warning-filters
1 parent cf5035c commit 1f5b5e0

36 files changed

+327
-137
lines changed

src/tests/PyImportTest/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-

src/tests/PyImportTest/test/one.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-

src/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-

src/tests/_compat.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""Python 2.7, 3.3+ compatibility module.
4+
5+
Using Python 3 syntax to encourage upgrade unless otherwise noted.
6+
"""
7+
8+
import operator
9+
import sys
10+
import types
11+
12+
PY2 = sys.version_info[0] == 2
13+
PY3 = sys.version_info[0] == 3
14+
15+
if PY3:
16+
import _thread as thread # Using PY2 name
17+
import pickle
18+
from collections import UserList
19+
20+
indexbytes = operator.getitem
21+
input = input
22+
23+
string_types = str,
24+
binary_type = bytes
25+
text_type = str
26+
27+
DictProxyType = type(object.__dict__)
28+
ClassType = type
29+
30+
# No PY3 equivalents, use PY2 name
31+
long = int
32+
unichr = chr
33+
unicode = str
34+
35+
# from nowhere import Nothing
36+
cmp = lambda a, b: (a > b) - (a < b) # No Py3 equivalent
37+
map = map
38+
range = range
39+
zip = zip
40+
41+
elif PY2:
42+
import thread # Using PY2 name
43+
import cPickle as pickle
44+
from UserList import UserList
45+
46+
indexbytes = lambda buf, i: ord(buf[i])
47+
input = raw_input
48+
49+
string_types = str, unicode
50+
bytes_type = str
51+
text_type = unicode
52+
53+
DictProxyType = types.DictProxyType
54+
ClassType = types.ClassType
55+
56+
# No PY3 equivalents, use PY2 name
57+
long = long
58+
unichr = unichr
59+
unicode = unicode
60+
61+
from itertools import izip, imap
62+
cmp = cmp
63+
map = imap
64+
range = xrange
65+
zip = izip

src/tests/leaktest.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# FIXME: TypeError: 'EventBinding' object is not callable
4+
15
from __future__ import print_function
2-
import System
6+
7+
import clr
38
import gc
49

10+
import System
11+
12+
from _compat import range
13+
514

6-
class LeakTest:
15+
class LeakTest(object):
716
"""A leak-check test for the objects implemented in the managed
817
runtime. For each kind of object tested, memory should reach
918
a particular level after warming up and stay essentially the
@@ -54,7 +63,7 @@ def report(self):
5463
def testModules(self):
5564
self.notify("Running module leak check...")
5665

57-
for i in xrange(self.count):
66+
for i in range(self.count):
5867
if i == 10:
5968
self.start_test()
6069

@@ -73,7 +82,7 @@ def testClasses(self):
7382

7483
self.notify("Running class leak check...")
7584

76-
for i in xrange(self.count):
85+
for i in range(self.count):
7786
if i == 10:
7887
self.start_test()
7988

@@ -86,7 +95,7 @@ def testClasses(self):
8695
del x
8796

8897
# Delegate type
89-
x = StringDelegate(hello)
98+
x = StringDelegate(hello_func)
9099
del x
91100

92101
self.end_test()
@@ -96,7 +105,7 @@ def testEnumerations(self):
96105

97106
self.notify("Running enum leak check...")
98107

99-
for i in xrange(self.count):
108+
for i in range(self.count):
100109
if i == 10:
101110
self.start_test()
102111

@@ -131,7 +140,7 @@ def testEvents(self):
131140

132141
self.notify("Running event leak check...")
133142

134-
for i in xrange(self.count):
143+
for i in range(self.count):
135144
if i == 10:
136145
self.start_test()
137146

@@ -210,13 +219,13 @@ def testDelegates(self):
210219

211220
self.notify("Running delegate leak check...")
212221

213-
for i in xrange(self.count):
222+
for i in range(self.count):
214223
if i == 10:
215224
self.start_test()
216225

217226
# Delegate from function
218227
testob = DelegateTest()
219-
d = StringDelegate(hello)
228+
d = StringDelegate(hello_func)
220229
testob.CallStringDelegate(d)
221230
testob.stringDelegate = d
222231
testob.stringDelegate()
@@ -225,7 +234,7 @@ def testDelegates(self):
225234
del d
226235

227236
# Delegate from instance method
228-
inst = Hello()
237+
inst = HelloClass()
229238
testob = DelegateTest()
230239
d = StringDelegate(inst.hello)
231240
testob.CallStringDelegate(d)
@@ -238,7 +247,7 @@ def testDelegates(self):
238247

239248
# Delegate from static method
240249
testob = DelegateTest()
241-
d = StringDelegate(Hello.s_hello)
250+
d = StringDelegate(HelloClass.s_hello)
242251
testob.CallStringDelegate(d)
243252
testob.stringDelegate = d
244253
testob.stringDelegate()
@@ -248,7 +257,7 @@ def testDelegates(self):
248257

249258
# Delegate from class method
250259
testob = DelegateTest()
251-
d = StringDelegate(Hello.c_hello)
260+
d = StringDelegate(HelloClass.c_hello)
252261
testob.CallStringDelegate(d)
253262
testob.stringDelegate = d
254263
testob.stringDelegate()
@@ -257,7 +266,7 @@ def testDelegates(self):
257266
del d
258267

259268
# Delegate from callable object
260-
inst = Hello()
269+
inst = HelloClass()
261270
testob = DelegateTest()
262271
d = StringDelegate(inst)
263272
testob.CallStringDelegate(d)
@@ -290,7 +299,7 @@ def testDelegates(self):
290299

291300
# Nested delegates
292301
testob = DelegateTest()
293-
d1 = StringDelegate(hello)
302+
d1 = StringDelegate(hello_func)
294303
d2 = StringDelegate(d1)
295304
testob.CallStringDelegate(d2)
296305
testob.stringDelegate = d2
@@ -302,8 +311,8 @@ def testDelegates(self):
302311

303312
# Multicast delegates
304313
testob = DelegateTest()
305-
d1 = StringDelegate(hello)
306-
d2 = StringDelegate(hello)
314+
d1 = StringDelegate(hello_func)
315+
d2 = StringDelegate(hello_func)
307316
md = System.Delegate.Combine(d1, d2)
308317
testob.CallStringDelegate(md)
309318
testob.stringDelegate = md
@@ -317,7 +326,7 @@ def testDelegates(self):
317326
self.end_test()
318327

319328

320-
class GenericHandler:
329+
class GenericHandler(object):
321330
"""A generic handler to test event callbacks."""
322331

323332
def __init__(self):
@@ -327,7 +336,7 @@ def handler(self, sender, args):
327336
self.value = args.value
328337

329338

330-
class VariableArgsHandler:
339+
class VariableArgsHandler(object):
331340
"""A variable args handler to test event callbacks."""
332341

333342
def __init__(self):
@@ -338,7 +347,7 @@ def handler(self, *args):
338347
self.value = eventargs.value
339348

340349

341-
class CallableHandler:
350+
class CallableHandler(object):
342351
"""A callable handler to test event callbacks."""
343352

344353
def __init__(self):
@@ -348,7 +357,7 @@ def __call__(self, sender, args):
348357
self.value = args.value
349358

350359

351-
class VarCallableHandler:
360+
class VarCallableHandler(object):
352361
"""A variable args callable handler to test event callbacks."""
353362

354363
def __init__(self):
@@ -381,7 +390,7 @@ def handler(cls, sender, args):
381390
handler = classmethod(handler)
382391

383392

384-
class Hello:
393+
class HelloClass(object):
385394
def hello(self):
386395
return "hello"
387396

@@ -399,7 +408,7 @@ def c_hello(cls):
399408
c_hello = classmethod(c_hello)
400409

401410

402-
def hello():
411+
def hello_func():
403412
return "hello"
404413

405414

src/tests/profile.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# FIXME: FAIL: testImplicitAssemblyLoad AssertionError: 0 != 1
4+
15
"""Run all of the unit tests for this package over and over,
2-
in order to provide for better profiling."""
6+
in order to provide for better profiling.
7+
"""
8+
39
from __future__ import print_function
410

11+
import gc
12+
import os
13+
import sys
14+
import time
515

6-
def main():
7-
import sys, os, gc, time
16+
import runtests
17+
from _compat import range
818

19+
20+
def main():
921
dirname = os.path.split(__file__)
1022
sys.path.append(dirname)
11-
import runtests
1223

1324
gc.set_debug(gc.DEBUG_LEAK)
1425

@@ -28,4 +39,3 @@ def main():
2839

2940
if __name__ == '__main__':
3041
main()
31-
sys.exit(0)

src/tests/runtests.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
14
"""Run all of the unit tests for this package."""
25

6+
from __future__ import print_function
7+
38
import os
49
import sys
510
import unittest
6-
import warnfilter
711

8-
warnfilter.addClrWarnfilter()
12+
from _compat import input
913

1014
try:
1115
import System
@@ -14,16 +18,17 @@
1418
import clr
1519

1620
test_modules = (
17-
'test_module', # Passes on its own, but not here if
21+
# Passes on its own, but not here if
1822
# other test modules that import System.Windows.Forms
1923
# run first. They must not do module level import/AddReference()
2024
# of the System.Windows.Forms namespace.
25+
'test_module',
26+
2127
'test_suite',
2228
'test_event',
2329
'test_constructors',
2430
'test_enum',
2531
'test_method',
26-
2732
'test_exceptions',
2833
'test_compat',
2934
'test_generic',
@@ -35,11 +40,18 @@
3540
'test_indexer',
3641
'test_delegate',
3742
'test_array',
38-
'test_thread'
43+
'test_thread',
44+
'test_docstring',
45+
46+
# FIXME: Fails due to unhandled exception
47+
# 'test_engine',
48+
49+
# FIXME: Fails in Linux
50+
# 'test_subclass',
3951
)
4052

4153

42-
def removePyc():
54+
def remove_pyc():
4355
path = os.path.dirname(os.path.abspath(__file__))
4456
for name in test_modules:
4557
pyc = os.path.join(path, "%s.pyc" % name)
@@ -48,7 +60,7 @@ def removePyc():
4860

4961

5062
def main(verbosity=1):
51-
removePyc()
63+
remove_pyc()
5264

5365
suite = unittest.TestSuite()
5466

@@ -62,7 +74,7 @@ def main(verbosity=1):
6274

6375

6476
if __name__ == '__main__':
65-
main(1)
77+
main()
6678
if '--pause' in sys.argv:
6779
print("Press enter to continue")
68-
raw_input()
80+
input()

0 commit comments

Comments
 (0)
0