Skip to content

Commit d642268

Browse files
committed
Use unittest.skip(...)
1 parent 907a633 commit d642268

File tree

4 files changed

+89
-60
lines changed

4 files changed

+89
-60
lines changed

src/tests/runtests.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
'test_thread',
4848
'test_docstring',
4949

50-
# FIXME: Fails due to unhandled exception
51-
# 'test_engine',
50+
# FIXME: Has tests that are being skipped.
51+
'test_engine',
5252

53-
# FIXME: Fails in Linux
54-
# 'test_subclass',
53+
# FIXME: Has tests that are being skipped.
54+
'test_subclass',
5555
)
5656

5757

src/tests/test_engine.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
# FIXME: This test module fails due to unhandled exceptions
32

43
import sys
54
import unittest
@@ -20,12 +19,14 @@ def test_multiple_calls_to_initialize(self):
2019
except BaseException:
2120
self.fail("Initialize() raise an exception.")
2221

22+
@unittest.skip(reason="FIXME: test crashes")
2323
def test_import_module(self):
2424
"""Test module import."""
2525
m = PythonEngine.ImportModule("sys")
2626
n = m.GetAttr("__name__")
2727
self.assertTrue(n.AsManagedObject(System.String) == "sys")
2828

29+
@unittest.skip(reason="FIXME: test freezes")
2930
def test_run_string(self):
3031
"""Test the RunString method."""
3132
PythonEngine.AcquireLock()

src/tests/test_exceptions.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -306,23 +306,22 @@ def test_pickling_exceptions(self):
306306

307307
self.assertEqual(exc.args, loaded.args)
308308

309+
@unittest.skipIf(PY2, "__cause__ isn't implemented in PY2")
309310
def test_chained_exceptions(self):
310-
# __cause__ is py3 only
311-
if PY3:
312-
from Python.Test import ExceptionTest
313-
314-
try:
315-
ExceptionTest.ThrowChainedExceptions()
316-
except Exception as exc:
317-
msgs = ("Outer exception",
318-
"Inner exception",
319-
"Innermost exception",)
320-
for msg in msgs:
321-
self.assertEqual(exc.Message, msg)
322-
self.assertEqual(exc.__cause__, exc.InnerException)
323-
exc = exc.__cause__
324-
else:
325-
self.fail("Test should raise an exception")
311+
from Python.Test import ExceptionTest
312+
313+
with self.assertRaises(Exception) as cm:
314+
ExceptionTest.ThrowChainedExceptions()
315+
316+
exc = cm.exception
317+
318+
msgs = ("Outer exception",
319+
"Inner exception",
320+
"Innermost exception",)
321+
for msg in msgs:
322+
self.assertEqual(exc.Message, msg)
323+
self.assertEqual(exc.__cause__, exc.InnerException)
324+
exc = exc.__cause__
326325

327326

328327
def test_suite():

src/tests/test_subclass.py

+68-39
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# -*- coding: utf-8 -*-
2-
# FIXME: This test module fails on Linux
2+
# FIXME: This test module randomly passes/fails even if all tests are skipped.
3+
# Something fishy is going on with the Test fixtures. Behavior seen on CI on
4+
# both Linux and Windows
5+
# TODO: Remove delay of class creations. Adding SetUp/TearDown may help
36

47
import unittest
58

@@ -11,64 +14,80 @@
1114
from _compat import range
1215

1316

14-
class InterfaceTestClass(IInterfaceTest):
15-
"""class that implements the test interface"""
16-
__namespace__ = "Python.Test"
17+
def interface_test_class_fixture():
18+
"""Delay creation of class until test starts."""
1719

18-
def foo(self):
19-
return "InterfaceTestClass"
20+
class InterfaceTestClass(IInterfaceTest):
21+
"""class that implements the test interface"""
22+
__namespace__ = "Python.Test"
2023

21-
def bar(self, x, i):
22-
return "/".join([x] * i)
24+
def foo(self):
25+
return "InterfaceTestClass"
2326

27+
def bar(self, x, i):
28+
return "/".join([x] * i)
2429

25-
class DerivedClass(SubClassTest):
26-
"""class that derives from a class deriving from IInterfaceTest"""
27-
__namespace__ = "Python.Test"
30+
return InterfaceTestClass
2831

29-
def foo(self):
30-
return "DerivedClass"
3132

32-
def base_foo(self):
33-
return SubClassTest.foo(self)
33+
def derived_class_fixture():
34+
"""Delay creation of class until test starts."""
3435

35-
def super_foo(self):
36-
return super(DerivedClass, self).foo()
36+
class DerivedClass(SubClassTest):
37+
"""class that derives from a class deriving from IInterfaceTest"""
38+
__namespace__ = "Python.Test"
3739

38-
def bar(self, x, i):
39-
return "_".join([x] * i)
40+
def foo(self):
41+
return "DerivedClass"
4042

41-
def return_list(self):
42-
l = List[str]()
43-
l.Add("A")
44-
l.Add("B")
45-
l.Add("C")
46-
return l
43+
def base_foo(self):
44+
return SubClassTest.foo(self)
4745

46+
def super_foo(self):
47+
return super(DerivedClass, self).foo()
4848

49-
class DerivedEventTest(IInterfaceTest):
50-
"""class that implements IInterfaceTest.TestEvent"""
51-
__namespace__ = "Python.Test"
49+
def bar(self, x, i):
50+
return "_".join([x] * i)
5251

53-
def __init__(self):
54-
self.event_handlers = []
52+
def return_list(self):
53+
l = List[str]()
54+
l.Add("A")
55+
l.Add("B")
56+
l.Add("C")
57+
return l
5558

56-
# event handling
57-
def add_TestEvent(self, handler):
58-
self.event_handlers.append(handler)
59+
return DerivedClass
5960

60-
def remove_TestEvent(self, handler):
61-
self.event_handlers.remove(handler)
6261

63-
def OnTestEvent(self, value):
64-
args = EventArgsTest(value)
65-
for handler in self.event_handlers:
66-
handler(self, args)
62+
def derived_event_test_class_fixture():
63+
"""Delay creation of class until test starts."""
64+
65+
class DerivedEventTest(IInterfaceTest):
66+
"""class that implements IInterfaceTest.TestEvent"""
67+
__namespace__ = "Python.Test"
68+
69+
def __init__(self):
70+
self.event_handlers = []
71+
72+
# event handling
73+
def add_TestEvent(self, handler):
74+
self.event_handlers.append(handler)
75+
76+
def remove_TestEvent(self, handler):
77+
self.event_handlers.remove(handler)
78+
79+
def OnTestEvent(self, value):
80+
args = EventArgsTest(value)
81+
for handler in self.event_handlers:
82+
handler(self, args)
83+
84+
return DerivedEventTest
6785

6886

6987
class SubClassTests(unittest.TestCase):
7088
"""Test sub-classing managed types"""
7189

90+
@unittest.skip(reason="FIXME: test randomly pass/fails")
7291
def test_base_class(self):
7392
"""Test base class managed type"""
7493
ob = SubClassTest()
@@ -80,8 +99,10 @@ def test_base_class(self):
8099
self.assertEqual(list(ob.return_list()), ["a", "b", "c"])
81100
self.assertEqual(list(SubClassTest.test_list(ob)), ["a", "b", "c"])
82101

102+
@unittest.skip(reason="FIXME: test randomly pass/fails")
83103
def test_interface(self):
84104
"""Test python classes can derive from C# interfaces"""
105+
InterfaceTestClass = interface_test_class_fixture()
85106
ob = InterfaceTestClass()
86107
self.assertEqual(ob.foo(), "InterfaceTestClass")
87108
self.assertEqual(FunctionsTest.test_foo(ob), "InterfaceTestClass")
@@ -91,8 +112,10 @@ def test_interface(self):
91112
x = FunctionsTest.pass_through(ob)
92113
self.assertEqual(id(x), id(ob))
93114

115+
@unittest.skip(reason="FIXME: test randomly pass/fails")
94116
def test_derived_class(self):
95117
"""Test python class derived from managed type"""
118+
DerivedClass = derived_class_fixture()
96119
ob = DerivedClass()
97120
self.assertEqual(ob.foo(), "DerivedClass")
98121
self.assertEqual(ob.base_foo(), "foo")
@@ -107,8 +130,10 @@ def test_derived_class(self):
107130
x = FunctionsTest.pass_through(ob)
108131
self.assertEqual(id(x), id(ob))
109132

133+
@unittest.skip(reason="FIXME: test randomly pass/fails")
110134
def test_create_instance(self):
111135
"""Test derived instances can be created from managed code"""
136+
DerivedClass = derived_class_fixture()
112137
ob = FunctionsTest.create_instance(DerivedClass)
113138
self.assertEqual(ob.foo(), "DerivedClass")
114139
self.assertEqual(FunctionsTest.test_foo(ob), "DerivedClass")
@@ -119,6 +144,7 @@ def test_create_instance(self):
119144
x = FunctionsTest.pass_through(ob)
120145
self.assertEqual(id(x), id(ob))
121146

147+
InterfaceTestClass = interface_test_class_fixture()
122148
ob2 = FunctionsTest.create_instance(InterfaceTestClass)
123149
self.assertEqual(ob2.foo(), "InterfaceTestClass")
124150
self.assertEqual(FunctionsTest.test_foo(ob2), "InterfaceTestClass")
@@ -128,6 +154,7 @@ def test_create_instance(self):
128154
y = FunctionsTest.pass_through(ob2)
129155
self.assertEqual(id(y), id(ob2))
130156

157+
@unittest.skip(reason="FIXME: test randomly pass/fails")
131158
def test_events(self):
132159
class EventHandler(object):
133160
def handler(self, x, args):
@@ -140,10 +167,12 @@ def handler(self, x, args):
140167
self.assertEqual(FunctionsTest.test_event(x, 1), 1)
141168
self.assertEqual(event_handler.value, 1)
142169

170+
InterfaceTestClass = interface_test_class_fixture()
143171
i = InterfaceTestClass()
144172
with self.assertRaises(System.NotImplementedException):
145173
FunctionsTest.test_event(i, 2)
146174

175+
DerivedEventTest = derived_event_test_class_fixture()
147176
d = DerivedEventTest()
148177
d.add_TestEvent(event_handler.handler)
149178
self.assertEqual(FunctionsTest.test_event(d, 3), 3)

0 commit comments

Comments
 (0)