Skip to content

Clean-up Tests #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Next Next commit
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
  • Loading branch information
vmuriart committed Jan 31, 2017
commit 0ea7455b9af0e5bbc16e646c5506945fd333f5b4
1 change: 1 addition & 0 deletions src/tests/PyImportTest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
1 change: 1 addition & 0 deletions src/tests/PyImportTest/test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
1 change: 1 addition & 0 deletions src/tests/PyImportTest/test/one.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
1 change: 1 addition & 0 deletions src/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
65 changes: 65 additions & 0 deletions src/tests/_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-

"""Python 2.7, 3.3+ compatibility module.

Using Python 3 syntax to encourage upgrade unless otherwise noted.
"""

import operator
import sys
import types

PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3

if PY3:
import _thread as thread # Using PY2 name
import pickle
from collections import UserList

indexbytes = operator.getitem
input = input

string_types = str,
binary_type = bytes
text_type = str

DictProxyType = type(object.__dict__)
ClassType = type

# No PY3 equivalents, use PY2 name
long = int
unichr = chr
unicode = str

# from nowhere import Nothing
cmp = lambda a, b: (a > b) - (a < b) # No Py3 equivalent
map = map
range = range
zip = zip

elif PY2:
import thread # Using PY2 name
import cPickle as pickle
from UserList import UserList

indexbytes = lambda buf, i: ord(buf[i])
input = raw_input

string_types = str, unicode
bytes_type = str
text_type = unicode

DictProxyType = types.DictProxyType
ClassType = types.ClassType

# No PY3 equivalents, use PY2 name
long = long
unichr = unichr
unicode = unicode

from itertools import izip, imap
cmp = cmp
map = imap
range = xrange
zip = izip
53 changes: 31 additions & 22 deletions src/tests/leaktest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# FIXME: TypeError: 'EventBinding' object is not callable

from __future__ import print_function
import System

import clr
import gc

import System

from _compat import range


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

for i in xrange(self.count):
for i in range(self.count):
if i == 10:
self.start_test()

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

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

for i in xrange(self.count):
for i in range(self.count):
if i == 10:
self.start_test()

Expand All @@ -86,7 +95,7 @@ def testClasses(self):
del x

# Delegate type
x = StringDelegate(hello)
x = StringDelegate(hello_func)
del x

self.end_test()
Expand All @@ -96,7 +105,7 @@ def testEnumerations(self):

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

for i in xrange(self.count):
for i in range(self.count):
if i == 10:
self.start_test()

Expand Down Expand Up @@ -131,7 +140,7 @@ def testEvents(self):

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

for i in xrange(self.count):
for i in range(self.count):
if i == 10:
self.start_test()

Expand Down Expand Up @@ -210,13 +219,13 @@ def testDelegates(self):

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

for i in xrange(self.count):
for i in range(self.count):
if i == 10:
self.start_test()

# Delegate from function
testob = DelegateTest()
d = StringDelegate(hello)
d = StringDelegate(hello_func)
testob.CallStringDelegate(d)
testob.stringDelegate = d
testob.stringDelegate()
Expand All @@ -225,7 +234,7 @@ def testDelegates(self):
del d

# Delegate from instance method
inst = Hello()
inst = HelloClass()
testob = DelegateTest()
d = StringDelegate(inst.hello)
testob.CallStringDelegate(d)
Expand All @@ -238,7 +247,7 @@ def testDelegates(self):

# Delegate from static method
testob = DelegateTest()
d = StringDelegate(Hello.s_hello)
d = StringDelegate(HelloClass.s_hello)
testob.CallStringDelegate(d)
testob.stringDelegate = d
testob.stringDelegate()
Expand All @@ -248,7 +257,7 @@ def testDelegates(self):

# Delegate from class method
testob = DelegateTest()
d = StringDelegate(Hello.c_hello)
d = StringDelegate(HelloClass.c_hello)
testob.CallStringDelegate(d)
testob.stringDelegate = d
testob.stringDelegate()
Expand All @@ -257,7 +266,7 @@ def testDelegates(self):
del d

# Delegate from callable object
inst = Hello()
inst = HelloClass()
testob = DelegateTest()
d = StringDelegate(inst)
testob.CallStringDelegate(d)
Expand Down Expand Up @@ -290,7 +299,7 @@ def testDelegates(self):

# Nested delegates
testob = DelegateTest()
d1 = StringDelegate(hello)
d1 = StringDelegate(hello_func)
d2 = StringDelegate(d1)
testob.CallStringDelegate(d2)
testob.stringDelegate = d2
Expand All @@ -302,8 +311,8 @@ def testDelegates(self):

# Multicast delegates
testob = DelegateTest()
d1 = StringDelegate(hello)
d2 = StringDelegate(hello)
d1 = StringDelegate(hello_func)
d2 = StringDelegate(hello_func)
md = System.Delegate.Combine(d1, d2)
testob.CallStringDelegate(md)
testob.stringDelegate = md
Expand All @@ -317,7 +326,7 @@ def testDelegates(self):
self.end_test()


class GenericHandler:
class GenericHandler(object):
"""A generic handler to test event callbacks."""

def __init__(self):
Expand All @@ -327,7 +336,7 @@ def handler(self, sender, args):
self.value = args.value


class VariableArgsHandler:
class VariableArgsHandler(object):
"""A variable args handler to test event callbacks."""

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


class CallableHandler:
class CallableHandler(object):
"""A callable handler to test event callbacks."""

def __init__(self):
Expand All @@ -348,7 +357,7 @@ def __call__(self, sender, args):
self.value = args.value


class VarCallableHandler:
class VarCallableHandler(object):
"""A variable args callable handler to test event callbacks."""

def __init__(self):
Expand Down Expand Up @@ -381,7 +390,7 @@ def handler(cls, sender, args):
handler = classmethod(handler)


class Hello:
class HelloClass(object):
def hello(self):
return "hello"

Expand All @@ -399,7 +408,7 @@ def c_hello(cls):
c_hello = classmethod(c_hello)


def hello():
def hello_func():
return "hello"


Expand Down
20 changes: 15 additions & 5 deletions src/tests/profile.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# FIXME: FAIL: testImplicitAssemblyLoad AssertionError: 0 != 1

"""Run all of the unit tests for this package over and over,
in order to provide for better profiling."""
in order to provide for better profiling.
"""

from __future__ import print_function

import gc
import os
import sys
import time

def main():
import sys, os, gc, time
import runtests
from _compat import range


def main():
dirname = os.path.split(__file__)
sys.path.append(dirname)
import runtests

gc.set_debug(gc.DEBUG_LEAK)

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

if __name__ == '__main__':
main()
sys.exit(0)
30 changes: 21 additions & 9 deletions src/tests/runtests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Run all of the unit tests for this package."""

from __future__ import print_function

import os
import sys
import unittest
import warnfilter

warnfilter.addClrWarnfilter()
from _compat import input

try:
import System
Expand All @@ -14,16 +18,17 @@
import clr

test_modules = (
'test_module', # Passes on its own, but not here if
# Passes on its own, but not here if
# other test modules that import System.Windows.Forms
# run first. They must not do module level import/AddReference()
# of the System.Windows.Forms namespace.
'test_module',

'test_suite',
'test_event',
'test_constructors',
'test_enum',
'test_method',

'test_exceptions',
'test_compat',
'test_generic',
Expand All @@ -35,11 +40,18 @@
'test_indexer',
'test_delegate',
'test_array',
'test_thread'
'test_thread',
'test_docstring',

# FIXME: Fails due to unhandled exception
# 'test_engine',

# FIXME: Fails in Linux
# 'test_subclass',
)


def removePyc():
def remove_pyc():
path = os.path.dirname(os.path.abspath(__file__))
for name in test_modules:
pyc = os.path.join(path, "%s.pyc" % name)
Expand All @@ -48,7 +60,7 @@ def removePyc():


def main(verbosity=1):
removePyc()
remove_pyc()

suite = unittest.TestSuite()

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


if __name__ == '__main__':
main(1)
main()
if '--pause' in sys.argv:
print("Press enter to continue")
raw_input()
input()
Loading