44
55import Python .Test as Test
66import System
7- from Python .Test import ClassTest
8- from System .Collections import Hashtable
97
10- from _compat import DictProxyType
8+ from _compat import DictProxyType , range
119
1210
1311class ClassTests (unittest .TestCase ):
@@ -25,13 +23,17 @@ def testBasicValueType(self):
2523
2624 def testClassStandardAttrs (self ):
2725 """Test standard class attributes."""
26+ from Python .Test import ClassTest
27+
2828 self .assertTrue (ClassTest .__name__ == 'ClassTest' )
2929 self .assertTrue (ClassTest .__module__ == 'Python.Test' )
3030 self .assertTrue (type (ClassTest .__dict__ ) == DictProxyType )
3131 self .assertTrue (len (ClassTest .__doc__ ) > 0 )
3232
3333 def testClassDocstrings (self ):
3434 """Test standard class docstring generation"""
35+ from Python .Test import ClassTest
36+
3537 value = 'Void .ctor()'
3638 self .assertTrue (ClassTest .__doc__ == value )
3739
@@ -47,7 +49,6 @@ def testClassDefaultRepr(self):
4749
4850 def testNonPublicClass (self ):
4951 """Test that non-public classes are inaccessible."""
50- from Python import Test
5152
5253 def test ():
5354 from Python .Test import InternalClass
@@ -61,6 +62,7 @@ def test():
6162
6263 def testBasicSubclass (self ):
6364 """Test basic subclass of a managed class."""
65+ from System .Collections import Hashtable
6466
6567 class MyTable (Hashtable ):
6668 def howMany (self ):
@@ -141,26 +143,31 @@ def testStructConstruction(self):
141143
142144 def testIEnumerableIteration (self ):
143145 """Test iteration over objects supporting IEnumerable."""
144- list = Test .ClassTest .GetArrayList ()
146+ from Python .Test import ClassTest
147+
148+ list = ClassTest .GetArrayList ()
145149
146150 for item in list :
147151 self .assertTrue ((item > - 1 ) and (item < 10 ))
148152
149- dict = Test . ClassTest .GetHashtable ()
153+ dict = ClassTest .GetHashtable ()
150154
151155 for item in dict :
152156 cname = item .__class__ .__name__
153157 self .assertTrue (cname .endswith ('DictionaryEntry' ))
154158
155159 def testIEnumeratorIteration (self ):
156160 """Test iteration over objects supporting IEnumerator."""
157- chars = Test .ClassTest .GetEnumerator ()
161+ from Python .Test import ClassTest
162+
163+ chars = ClassTest .GetEnumerator ()
158164
159165 for item in chars :
160166 self .assertTrue (item in 'test string' )
161167
162168 def testOverrideGetItem (self ):
163169 """Test managed subclass overriding __getitem__."""
170+ from System .Collections import Hashtable
164171
165172 class MyTable (Hashtable ):
166173 def __getitem__ (self , key ):
@@ -180,6 +187,7 @@ def __getitem__(self, key):
180187
181188 def testOverrideSetItem (self ):
182189 """Test managed subclass overriding __setitem__."""
190+ from System .Collections import Hashtable
183191
184192 class MyTable (Hashtable ):
185193 def __setitem__ (self , key , value ):
@@ -198,10 +206,9 @@ def __setitem__(self, key, value):
198206 self .assertTrue (table .Count == 3 )
199207
200208 def testAddAndRemoveClassAttribute (self ):
201-
202209 from System import TimeSpan
203210
204- for i in range (100 ):
211+ for _ in range (100 ):
205212 TimeSpan .new_method = lambda self : self .TotalMinutes
206213 ts = TimeSpan .FromHours (1 )
207214 self .assertTrue (ts .new_method () == 60 )
@@ -210,6 +217,7 @@ def testAddAndRemoveClassAttribute(self):
210217
211218 def testComparisons (self ):
212219 from System import DateTimeOffset
220+ from Python .Test import ClassTest
213221
214222 d1 = DateTimeOffset .Parse ("2016-11-14" )
215223 d2 = DateTimeOffset .Parse ("2016-11-15" )
@@ -247,12 +255,14 @@ def testComparisons(self):
247255 self .assertRaises (TypeError , lambda : c1 < c2 )
248256
249257 def testSelfCallback (self ):
250- """ Test calling back and forth between this and a c# baseclass."""
258+ """Test calling back and forth between this and a c# baseclass."""
259+
251260 class CallbackUser (Test .SelfCallbackTest ):
252261 def DoCallback (self ):
253262 self .PyCallbackWasCalled = False
254263 self .SameReference = False
255264 return self .Callback (self )
265+
256266 def PyCallback (self , self2 ):
257267 self .PyCallbackWasCalled = True
258268 self .SameReference = self == self2
@@ -262,6 +272,7 @@ def PyCallback(self, self2):
262272 self .assertTrue (testobj .PyCallbackWasCalled )
263273 self .assertTrue (testobj .SameReference )
264274
275+
265276class ClassicClass :
266277 def kind (self ):
267278 return 'classic'
0 commit comments