44
55import sys
66import unittest
7- from iptest import IronPythonTestCase , is_cli , is_debug , is_mono , is_net70 , is_net80 , is_net100 , is_netcoreapp , is_netcoreapp21 , is_posix , is_arm64 , big , run_test , skipUnlessIronPython
7+ from iptest import IronPythonTestCase , is_cli , is_debug , is_mono , is_net70 , is_net80 , is_net100 , is_netcoreapp , is_posix , is_arm64 , big , run_test , skipUnlessIronPython
8+ from iptest .ipunittest import load_ironpython_test
89
910if is_cli :
1011 import clr
1112 import System
1213
14+ load_ironpython_test ()
15+
1316@skipUnlessIronPython ()
1417class CliClassTestCase (IronPythonTestCase ):
1518
@@ -20,11 +23,6 @@ def assertNotWarns(self, warning, callable, *args, **kwds):
2023 result = callable (* args , ** kwds )
2124 self .assertFalse (any (item .category == warning for item in warning_list ))
2225
23- def setUp (self ):
24- super (CliClassTestCase , self ).setUp ()
25-
26- self .load_iron_python_test ()
27-
2826 def test_inheritance (self ):
2927 import System
3028 class MyList (System .Collections .Generic .List [int ]):
@@ -1087,7 +1085,6 @@ class x(System.Version): pass
10871085 self .assertRaisesPartialMessage (TypeError , 'System.Single' , f )
10881086 self .assertRaisesPartialMessage (TypeError , 'System.Version' , g )
10891087
1090- @unittest .skipIf (is_netcoreapp21 , "TODO: figure out" )
10911088 def test_disposable (self ):
10921089 """classes implementing IDisposable should automatically support the with statement"""
10931090 from IronPythonTest import DisposableTest
@@ -1890,44 +1887,45 @@ class MyXamlRootObject(XamlTestObject):
18901887 finally :
18911888 os .unlink (fname )
18921889
1893- @unittest .skipIf (is_netcoreapp21 , "TODO: figure out" )
1894- def test_extension_methods (self ):
1895- import clr , os
1896- if is_netcoreapp :
1897- clr .AddReference ('System.Linq' )
1898- else :
1899- clr .AddReference ('System.Core' )
1890+ def get_extension_method_test_cases ():
1891+ import os
19001892
19011893 test_cases = [
19021894"""
19031895# add reference via type
1904- import clr
1905- from System.Linq import Enumerable
1896+ @skipUnlessIronPython()
19061897class TheTestCase(IronPythonTestCase):
19071898 def test_reference_via_type(self):
1899+ import clr
1900+ from System.Linq import Enumerable
1901+
19081902 self.assertNotIn('Where', dir([]))
19091903 clr.ImportExtensions(Enumerable)
19101904 self.assertIn('Where', dir([]))
19111905 self.assertEqual(list([2,3,4].Where(lambda x: x == 2)), [2])
19121906""" ,
19131907"""
19141908# add reference via namespace
1915- import clr
1916- import System
1909+ @skipUnlessIronPython()
19171910class TheTestCase(IronPythonTestCase):
19181911 def test_reference_via_namespace(self):
1912+ import clr
1913+ import System
1914+
19191915 self.assertNotIn('Where', dir([]))
19201916 clr.ImportExtensions(System.Linq)
19211917 self.assertIn('Where', dir([]))
19221918 self.assertEqual(list([2,3,4].Where(lambda x: x == 2)), [2])
19231919""" ,
19241920"""
19251921# add reference via namespace, add new namespace w/ more specific type
1926- import clr
1927- import System
1928- from IronPythonTest.ExtensionMethodTest import LinqCollision
1922+ @skipUnlessIronPython()
19291923class TheTestCase(IronPythonTestCase):
19301924 def test_namespace_reference(self):
1925+ import clr
1926+ import System
1927+ from IronPythonTest.ExtensionMethodTest import LinqCollision
1928+
19311929 self.assertNotIn('Where', dir([]))
19321930 clr.ImportExtensions(System.Linq)
19331931 self.assertIn('Where', dir([]))
@@ -1937,7 +1935,6 @@ def test_namespace_reference(self):
19371935""" ,
19381936
19391937"""
1940- import clr
19411938class UserType(object): pass
19421939class UserTypeWithValue(object):
19431940 def __init__(self):
@@ -1949,13 +1946,15 @@ class UserTypeWithSlotsWithValue(object):
19491946 def __init__(self):
19501947 self.BaseClass = 100
19511948
1949+ @skipUnlessIronPython()
19521950class TheTestCase(IronPythonTestCase):
19531951 def test_user_type(self):
1952+ import clr
1953+
19541954 self.assertRaises(AttributeError, lambda : UserType().BaseClass)
19551955 self.assertRaises(AttributeError, lambda : UserTypeWithSlots().BaseClass)
19561956 self.assertEqual(UserTypeWithValue().BaseClass, 200)
19571957
1958- import clr
19591958 from IronPythonTest.ExtensionMethodTest import ClassRelationship
19601959 clr.ImportExtensions(ClassRelationship)
19611960
@@ -1978,13 +1977,14 @@ def test_user_type(self):
19781977 self.assertEqual(UserTypeWithValue().BaseClass, 200)
19791978""" ,
19801979"""
1981- import clr
1982- import System
1983- from IronPythonTest.ExtensionMethodTest import ClassRelationship
1984- clr.ImportExtensions(ClassRelationship)
1985-
1980+ @skipUnlessIronPython()
19861981class TheTestCase(IronPythonTestCase):
19871982 def test_class_relationship(self):
1983+ import clr
1984+ import System
1985+ from IronPythonTest.ExtensionMethodTest import ClassRelationship
1986+ clr.ImportExtensions(ClassRelationship)
1987+
19881988 self.assertEqual([].Interface(), 23)
19891989 self.assertEqual([].GenericInterface(), 23)
19901990 self.assertEqual([].GenericInterfaceAndMethod(), 23)
@@ -1998,21 +1998,22 @@ def test_class_relationship(self):
19981998 self.assertEqual(object().GenericMethod(), 23)
19991999""" ,
20002000"""
2001- import clr
2002- import System
2003- from System import Linq
2004-
2005- clr.ImportExtensions(Linq)
2006-
20072001class Product(object):
20082002 def __init__(self, cat, id, qtyOnHand ):
20092003 self.Cat = cat
20102004 self.ID = id
20112005 self.QtyOnHand = qtyOnHand
20122006 self.Q = self.QtyOnHand
20132007
2008+ @skipUnlessIronPython()
20142009class TheTestCase(IronPythonTestCase):
20152010 def test_extension_method(self):
2011+ import clr
2012+ import System
2013+ from System import Linq
2014+
2015+ clr.ImportExtensions(Linq)
2016+
20162017 products = [Product(prod[0], prod[1], prod[2]) for prod in
20172018 (('DrillRod', 'DR123', 45), ('Flange', 'F423', 12), ('Gizmo', 'G9872', 214), ('Sprocket', 'S534', 42))]
20182019
@@ -2058,20 +2059,22 @@ def test_extension_method(self):
20582059 try :
20592060 old_path = [x for x in sys .path ]
20602061 sys .path .append ('.' )
2061- with open (fname , 'w+ ' ) as f :
2062+ with open (fname , 'w' ) as f :
20622063 f .write ('''
2063- from test import support
2064- from iptest import IronPythonTestCase
2064+ from iptest import IronPythonTestCase, skipUnlessIronPython
20652065''' )
20662066 f .write (test_case )
2067- f .write ('''
2068-
2069- support.run_unittest(TheTestCase)''' )
20702067
20712068 __import__ (temp_module )
2069+ yield sys .modules [temp_module ].TheTestCase
20722070 del sys .modules [temp_module ]
20732071 finally :
20742072 os .unlink (fname )
20752073 sys .path = [x for x in old_path ]
20762074
2075+ def load_tests (loader , tests , pattern ):
2076+ for test_case in get_extension_method_test_cases ():
2077+ tests .addTests (loader .loadTestsFromTestCase (test_case ))
2078+ return tests
2079+
20772080run_test (__name__ )
0 commit comments