Skip to content

Commit 507eb33

Browse files
authored
Enable test_cliclass (#1053)
* Enable test_cliclass * Disable failing test on mono * fix test on Mono
1 parent 79e61cb commit 507eb33

2 files changed

Lines changed: 46 additions & 54 deletions

File tree

Src/IronPythonTest/Cases/IronPythonCasesManifest.ini

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ Reason=Exception on adding DocTestSuite
1212
Ignore=true
1313

1414
[IronPython.test_cliclass]
15-
RunCondition=NOT $(IS_POSIX)
16-
Reason=Causes an abort on mono, needs debug
17-
Ignore=true
15+
IsolationLevel=PROCESS # TODO: figure out - wpf fails to load otherwise
1816

1917
[IronPython.test_clrload]
2018
IsolationLevel=PROCESS # requires System.Drawing assembly to be unloaded

Tests/test_cliclass.py

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import sys
66
import unittest
7-
from iptest import IronPythonTestCase, is_cli, is_debug, is_netcoreapp, is_posix, run_test, skipUnlessIronPython
7+
from iptest import IronPythonTestCase, is_cli, is_debug, is_mono, is_netcoreapp, is_netcoreapp21, is_posix, run_test, skipUnlessIronPython
88

99
if is_cli:
1010
import clr
@@ -13,6 +13,13 @@
1313
@skipUnlessIronPython()
1414
class CliClassTestCase(IronPythonTestCase):
1515

16+
def assertNotWarns(self, warning, callable, *args, **kwds):
17+
import warnings
18+
with warnings.catch_warnings(record=True) as warning_list:
19+
warnings.simplefilter('always')
20+
result = callable(*args, **kwds)
21+
self.assertFalse(any(item.category == warning for item in warning_list))
22+
1623
def setUp(self):
1724
super(CliClassTestCase, self).setUp()
1825

@@ -106,14 +113,11 @@ class MyDerivedExceptionComparer(MyExceptionComparer): pass
106113
MyDerivedExceptionComparer.__bases__ = (System.Exception, System.Collections.IComparer)
107114
MyDerivedExceptionComparer.__bases__ = (MyExceptionComparer,)
108115

109-
class OldType:
110-
def OldTypeMethod(self): return "OldTypeMethod"
111116
class NewType:
112117
def NewTypeMethod(self): return "NewTypeMethod"
113-
class MyOtherExceptionComparer(System.Exception, System.Collections.IComparer, OldType, NewType):
118+
class MyOtherExceptionComparer(System.Exception, System.Collections.IComparer, NewType):
114119
def Compare(self, x, y): return 0
115120
MyExceptionComparer.__bases__ = MyOtherExceptionComparer.__bases__
116-
self.assertEqual(e.OldTypeMethod(), "OldTypeMethod")
117121
self.assertEqual(e.NewTypeMethod(), "NewTypeMethod")
118122
self.assertTrue(isinstance(e, System.Exception))
119123
self.assertTrue(isinstance(e, System.Collections.IComparer))
@@ -134,7 +138,7 @@ def test_open_generic(self):
134138
class Foo(System.Collections.Generic.IEnumerable): pass
135139
except TypeError:
136140
(exc_type, exc_value, exc_traceback) = sys.exc_info()
137-
self.assertTrue(exc_value.message.__contains__("cannot inhert from open generic instantiation"))
141+
self.assertTrue(str(exc_value).__contains__("cannot inhert from open generic instantiation"))
138142

139143
def test_interface_slots(self):
140144

@@ -185,17 +189,11 @@ def CheckDictionary(C):
185189
C.newTypeAttr = 1
186190
self.assertEqual(hasattr(C, 'newTypeAttr'), True)
187191

188-
class OldClass: pass
189-
190-
if isinstance(C, type(OldClass)):
191-
C.__dict__ = dict(C.__dict__)
192-
self.assertEqual(hasattr(C, 'newTypeAttr'), True)
193-
else:
194-
try:
195-
C.__dict__ = {}
196-
self.fail("Unreachable code reached")
197-
except AttributeError:
198-
pass
192+
try:
193+
C.__dict__ = {}
194+
self.fail("Unreachable code reached")
195+
except AttributeError:
196+
pass
199197

200198
# replace an instance dictionary (containing non-string keys) w/ a new one.
201199
a.newInstanceAttr = 1
@@ -207,14 +205,9 @@ class OldClass: pass
207205
self.assertEqual(hasattr(a, 'abc'), True)
208206
self.assertEqual(getattr(a, 'abc'), 'xyz')
209207

210-
211-
class OldClass:
212-
def __init__(self): pass
213-
214208
class NewClass(object):
215209
def __init__(self): pass
216210

217-
CheckDictionary(OldClass)
218211
CheckDictionary(NewClass)
219212

220213
def test_generic_TypeGroup(self):
@@ -423,7 +416,7 @@ class foo: pass
423416
self.assertTrue(test.TestProperties(a, [], ['bar']))
424417

425418
x = test.GetClassName(a)
426-
self.assertEqual(x, 'classobj')
419+
self.assertEqual(x, 'IronPython.Runtime.Types.PythonType')
427420

428421
x = test.CallCanConvertToForInt(a)
429422
self.assertEqual(x, False)
@@ -444,7 +437,7 @@ class foo: pass
444437
self.assertEqual(x.Count, 0)
445438

446439
x = test.GetProperties(a)
447-
self.assertTrue(x.Count > 0)
440+
self.assertTrue(x.Count == 0)
448441

449442
# Ensure GetProperties checks the attribute dictionary
450443
a = foo()
@@ -657,7 +650,7 @@ def test_nondefault_indexers(self):
657650

658651
try:
659652
name = os.path.join(self.temporary_dir, 'vbproptest%f.dll' % (r.random()))
660-
x = self.run_vbc('/target:library vbproptest1.vb "/out:%s"' % name)
653+
x = self.run_vbc('/target:library %s "/out:%s"' % (fname, name))
661654
self.assertEqual(x, 0)
662655

663656
clr.AddReferenceToFileAndPath(name)
@@ -738,7 +731,7 @@ def test_nondefault_indexers_overloaded(self):
738731

739732
try:
740733
name = os.path.join(self.temporary_dir, 'vbproptest%f.dll' % (r.random()))
741-
self.assertEqual(self.run_vbc('/target:library vbproptest1.vb /out:"%s"' % name), 0)
734+
self.assertEqual(self.run_vbc('/target:library %s /out:"%s"' % (fname, name)), 0)
742735

743736
clr.AddReferenceToFileAndPath(name)
744737
import VbPropertyTest, VbPropertyTest2
@@ -825,7 +818,7 @@ class foo(object): pass
825818
def test_nonzero(self):
826819
from System import Single, Byte, SByte, Int16, UInt16, Int64, UInt64
827820
for t in [Single, Byte, SByte, Int16, UInt16, Int64, UInt64]:
828-
self.assertTrue(hasattr(t, '__nonzero__'))
821+
self.assertTrue(hasattr(t, '__bool__'))
829822
if t(0): self.fail("Unreachable code reached")
830823
if not t(1): self.fail("Unreachable code reached")
831824

@@ -1061,17 +1054,18 @@ def test_ctor_keyword_args_newslot(self):
10611054

10621055
def test_enum_truth(self):
10631056
# zero enums are false, non-zero enums are true
1064-
self.assertTrue(not System.StringSplitOptions.None)
1057+
StringSplitOptionsNone = getattr(System.StringSplitOptions, "None")
1058+
self.assertTrue(not StringSplitOptionsNone)
10651059
self.assertTrue(System.StringSplitOptions.RemoveEmptyEntries)
1066-
self.assertEqual(System.StringSplitOptions.None.__nonzero__(), False)
1067-
self.assertEqual(System.StringSplitOptions.RemoveEmptyEntries.__nonzero__(), True)
1060+
self.assertEqual(StringSplitOptionsNone.__bool__(), False)
1061+
self.assertEqual(System.StringSplitOptions.RemoveEmptyEntries.__bool__(), True)
10681062

10691063
def test_enum_repr(self):
10701064
clr.AddReference('IronPython')
10711065
from IronPython.Runtime import ModuleOptions
1072-
self.assertEqual(repr(ModuleOptions.WithStatement), 'IronPython.Runtime.ModuleOptions.WithStatement')
1073-
self.assertEqual(repr(ModuleOptions.WithStatement | ModuleOptions.TrueDivision),
1074-
'<enum IronPython.Runtime.ModuleOptions: TrueDivision, WithStatement>')
1066+
self.assertEqual(repr(ModuleOptions.ShowClsMethods), 'IronPython.Runtime.ModuleOptions.ShowClsMethods')
1067+
self.assertEqual(repr(ModuleOptions.ShowClsMethods | ModuleOptions.Optimized),
1068+
'<enum IronPython.Runtime.ModuleOptions: ShowClsMethods, Optimized>')
10751069

10761070
def test_bad_inheritance(self):
10771071
"""verify a bad inheritance reports the type name you're inheriting from"""
@@ -1083,7 +1077,7 @@ class x(System.Version): pass
10831077
self.assertRaisesPartialMessage(TypeError, 'System.Single', f)
10841078
self.assertRaisesPartialMessage(TypeError, 'System.Version', g)
10851079

1086-
@unittest.skipIf(is_netcoreapp, "TODO: figure out")
1080+
@unittest.skipIf(is_netcoreapp21, "TODO: figure out")
10871081
def test_disposable(self):
10881082
"""classes implementing IDisposable should automatically support the with statement"""
10891083
from IronPythonTest import DisposableTest
@@ -1238,7 +1232,7 @@ def __init__(self):
12381232
self.assertEqual(newVal, value)
12391233
except RuntimeError as e:
12401234
# we hit one of our recursive structures...
1241-
self.assertEqual(e.message, "maximum recursion depth exceeded in cmp")
1235+
self.assertEqual(str(e), "maximum recursion depth exceeded in cmp")
12421236
self.assertTrue(type(newVal) is list or type(newVal) is dict)
12431237

12441238
# passing an unknown format raises...
@@ -1277,12 +1271,10 @@ def __init__(self):
12771271

12781272
try:
12791273
exec(" print 1")
1280-
except Exception as tempX:
1281-
pass
1274+
except Exception as err:
1275+
tempX = err
12821276
newX = pickle.loads(pickle.dumps(tempX))
1283-
for attr in ['args', 'filename', 'text', 'lineno', 'msg', 'offset', 'print_file_and_line',
1284-
'message',
1285-
]:
1277+
for attr in ['args', 'filename', 'text', 'lineno', 'msg', 'offset', 'print_file_and_line']:
12861278
self.assertEqual(eval("newX.%s" % attr),
12871279
eval("tempX.%s" % attr))
12881280

@@ -1330,8 +1322,9 @@ def test_add_str_char(self):
13301322
self.assertEqual(System.Char.Parse('a') + 'bc', 'abc')
13311323

13321324
def test_import_star_enum(self):
1333-
from System.AttributeTargets import *
1334-
self.assertTrue('ReturnValue' in dir())
1325+
d = {}
1326+
exec("from System.AttributeTargets import *", d, d)
1327+
self.assertTrue('ReturnValue' in d)
13351328

13361329
def test_cp11971(self):
13371330
import os
@@ -1411,7 +1404,10 @@ def test_clr_dir(self):
14111404
self.assertTrue('IndexOf' in clr.DirClr('abc'))
14121405

14131406
def test_array_contains(self):
1414-
self.assertRaises(KeyError, lambda : System.Array[str].__dict__['__contains__'])
1407+
if is_mono: # for whatever reason this is defined on Mono
1408+
System.Array[str].__dict__['__contains__']
1409+
else:
1410+
self.assertRaises(KeyError, lambda : System.Array[str].__dict__['__contains__'])
14151411

14161412
def test_a_override_patching(self):
14171413
from IronPythonTest import TestHelpers
@@ -1453,7 +1449,6 @@ def test_dir(self):
14531449
# make sure you can do dir on everything in System which
14541450
# includes special types like ArgIterator and Func
14551451
for attr in dir(System):
1456-
if is_netcoreapp and attr in ["ArgIterator", "ReadOnlySpan"]: continue # TODO: https://github.com/IronLanguages/dlr/issues/74
14571452
dir(getattr(System, attr))
14581453

14591454
if is_netcoreapp:
@@ -1479,9 +1474,10 @@ def test_valuetype_iter(self):
14791474
d["a"] = "foo"
14801475
d["b"] = "bar"
14811476
it = iter(d)
1482-
self.assertEqual(it.next().Key, 'a')
1483-
self.assertEqual(it.next().Key, 'b')
1477+
self.assertEqual(it.__next__().Key, 'a')
1478+
self.assertEqual(it.__next__().Key, 'b')
14841479

1480+
@unittest.skipIf(is_mono, "Causes an abort on mono, needs debug")
14851481
def test_abstract_class_no_interface_implself(self):
14861482
# this can't be defined in C# or VB, it's a class which is
14871483
# abstract and therefore doesn't implement the interface method
@@ -1566,7 +1562,7 @@ def test_abstract_class_no_interface_implself(self):
15661562
try:
15671563
self.run_ilasm("/dll " + testilcode)
15681564

1569-
clr.AddReferenceToFileAndPath(os.path.join(self.temporary_dir, 'testilcode.dll'))
1565+
clr.AddReferenceToFileAndPath(os.path.join(self.temporary_dir, 'testilcode_%d.dll' % os.getpid()))
15701566
import AbstractILTest
15711567

15721568
class x(AbstractILTest):
@@ -1655,9 +1651,7 @@ def test_scope_getvariable(self):
16551651

16561652
def test_weird_compare(self):
16571653
from IronPythonTest import WithCompare
1658-
a, b = WithCompare(), WithCompare()
1659-
self.assertEqual(cmp(a, b), cmp(id(a), id(b)))
1660-
self.assertTrue('__cmp__' not in WithCompare.__dict__)
1654+
self.assertTrue('__cmp__' not in WithCompare.__dict__) # TODO: revisit this once we decide how to map CompareTo to Python
16611655

16621656
def test_convert_int64_to_float(self):
16631657
self.assertEqual(float(System.Int64(42)), 42.0)
@@ -1905,7 +1899,7 @@ def __init__(self, cat, id, qtyOnHand ):
19051899
class TheTestCase(IronPythonTestCase):
19061900
def test_extension_method(self):
19071901
products = [Product(prod[0], prod[1], prod[2]) for prod in
1908-
('DrillRod', 'DR123', 45), ('Flange', 'F423', 12), ('Gizmo', 'G9872', 214), ('Sprocket', 'S534', 42)]
1902+
(('DrillRod', 'DR123', 45), ('Flange', 'F423', 12), ('Gizmo', 'G9872', 214), ('Sprocket', 'S534', 42))]
19091903
19101904
pd = products.Where(lambda prod: prod.Q < 40).Select(lambda prod: (prod.Cat, prod.ID) )
19111905
self.assertEqual(''.join(str(prod) for prod in pd), "('Flange', 'F423')")

0 commit comments

Comments
 (0)