44import unittest
55
66from _compat import ClassType , PY2 , PY3 , range
7+ from utils import isCLRClass , isCLRModule , isCLRRootModule
78
89
910class CompatibilityTests (unittest .TestCase ):
10- """
11- Backward-compatibility tests for deprecated features.
12- """
13-
14- def isCLRModule (self , object ):
15- return type (object ).__name__ == 'ModuleObject'
16-
17- def isCLRRootModule (self , object ):
18- if PY3 :
19- # in Python 3 the clr module is a normal python module
20- return object .__name__ == "clr"
21- elif PY2 :
22- return type (object ).__name__ == 'CLRModule'
23-
24- def isCLRClass (self , object ):
25- return type (object ).__name__ == 'CLR Metatype' # for now
11+ """Backward-compatibility tests for deprecated features."""
2612
2713 # Tests for old-style CLR-prefixed module naming.
2814
2915 def testSimpleImport (self ):
3016 """Test simple import."""
3117 import CLR
32- self .assertTrue (self . isCLRRootModule (CLR ))
18+ self .assertTrue (isCLRRootModule (CLR ))
3319 self .assertTrue (CLR .__name__ == 'clr' )
3420
3521 import sys
@@ -49,7 +35,7 @@ def testSimpleImport(self):
4935 def testSimpleImportWithAlias (self ):
5036 """Test simple import with aliasing."""
5137 import CLR as myCLR
52- self .assertTrue (self . isCLRRootModule (myCLR ))
38+ self .assertTrue (isCLRRootModule (myCLR ))
5339 self .assertTrue (myCLR .__name__ == 'clr' )
5440
5541 import sys as mySys
@@ -69,11 +55,11 @@ def testSimpleImportWithAlias(self):
6955 def testDottedNameImport (self ):
7056 """Test dotted-name import."""
7157 import CLR .System
72- self .assertTrue (self . isCLRModule (CLR .System ))
58+ self .assertTrue (isCLRModule (CLR .System ))
7359 self .assertTrue (CLR .System .__name__ == 'System' )
7460
7561 import System
76- self .assertTrue (self . isCLRModule (System ))
62+ self .assertTrue (isCLRModule (System ))
7763 self .assertTrue (System .__name__ == 'System' )
7864
7965 self .assertTrue (System is CLR .System )
@@ -85,11 +71,11 @@ def testDottedNameImport(self):
8571 def testDottedNameImportWithAlias (self ):
8672 """Test dotted-name import with aliasing."""
8773 import CLR .System as myCLRSystem
88- self .assertTrue (self . isCLRModule (myCLRSystem ))
74+ self .assertTrue (isCLRModule (myCLRSystem ))
8975 self .assertTrue (myCLRSystem .__name__ == 'System' )
9076
9177 import System as mySystem
92- self .assertTrue (self . isCLRModule (mySystem ))
78+ self .assertTrue (isCLRModule (mySystem ))
9379 self .assertTrue (mySystem .__name__ == 'System' )
9480
9581 self .assertTrue (mySystem is myCLRSystem )
@@ -101,7 +87,7 @@ def testDottedNameImportWithAlias(self):
10187 def testSimpleImportFrom (self ):
10288 """Test simple 'import from'."""
10389 from CLR import System
104- self .assertTrue (self . isCLRModule (System ))
90+ self .assertTrue (isCLRModule (System ))
10591 self .assertTrue (System .__name__ == 'System' )
10692
10793 from xml import dom
@@ -111,7 +97,7 @@ def testSimpleImportFrom(self):
11197 def testSimpleImportFromWithAlias (self ):
11298 """Test simple 'import from' with aliasing."""
11399 from CLR import System as mySystem
114- self .assertTrue (self . isCLRModule (mySystem ))
100+ self .assertTrue (isCLRModule (mySystem ))
115101 self .assertTrue (mySystem .__name__ == 'System' )
116102
117103 from xml import dom as myDom
@@ -121,11 +107,11 @@ def testSimpleImportFromWithAlias(self):
121107 def testDottedNameImportFrom (self ):
122108 """Test dotted-name 'import from'."""
123109 from CLR .System import Xml
124- self .assertTrue (self . isCLRModule (Xml ))
110+ self .assertTrue (isCLRModule (Xml ))
125111 self .assertTrue (Xml .__name__ == 'System.Xml' )
126112
127113 from CLR .System .Xml import XmlDocument
128- self .assertTrue (self . isCLRClass (XmlDocument ))
114+ self .assertTrue (isCLRClass (XmlDocument ))
129115 self .assertTrue (XmlDocument .__name__ == 'XmlDocument' )
130116
131117 from xml .dom import pulldom
@@ -139,11 +125,11 @@ def testDottedNameImportFrom(self):
139125 def testDottedNameImportFromWithAlias (self ):
140126 """Test dotted-name 'import from' with aliasing."""
141127 from CLR .System import Xml as myXml
142- self .assertTrue (self . isCLRModule (myXml ))
128+ self .assertTrue (isCLRModule (myXml ))
143129 self .assertTrue (myXml .__name__ == 'System.Xml' )
144130
145131 from CLR .System .Xml import XmlDocument as myXmlDocument
146- self .assertTrue (self . isCLRClass (myXmlDocument ))
132+ self .assertTrue (isCLRClass (myXmlDocument ))
147133 self .assertTrue (myXmlDocument .__name__ == 'XmlDocument' )
148134
149135 from xml .dom import pulldom as myPulldom
@@ -159,12 +145,12 @@ def testFromModuleImportStar(self):
159145 count = len (locals ().keys ())
160146 m = __import__ ('CLR.System.Management' , globals (), locals (), ['*' ])
161147 self .assertTrue (m .__name__ == 'System.Management' )
162- self .assertTrue (self . isCLRModule (m ))
148+ self .assertTrue (isCLRModule (m ))
163149 self .assertTrue (len (locals ().keys ()) > count + 1 )
164150
165151 m2 = __import__ ('System.Management' , globals (), locals (), ['*' ])
166152 self .assertTrue (m2 .__name__ == 'System.Management' )
167- self .assertTrue (self . isCLRModule (m2 ))
153+ self .assertTrue (isCLRModule (m2 ))
168154 self .assertTrue (len (locals ().keys ()) > count + 1 )
169155
170156 self .assertTrue (m is m2 )
@@ -193,7 +179,7 @@ def testImplicitLoadAlreadyValidNamespace(self):
193179 # Python runtime to "do the right thing", allowing types from both
194180 # assemblies to be found in the CLR.System module implicitly.
195181 import CLR .System
196- self .assertTrue (self . isCLRClass (CLR .System .UriBuilder ))
182+ self .assertTrue (isCLRClass (CLR .System .UriBuilder ))
197183
198184 def testImportNonExistantModule (self ):
199185 """Test import failure for a non-existant module."""
@@ -211,7 +197,7 @@ def testLookupNoNamespaceType(self):
211197 """Test lookup of types without a qualified namespace."""
212198 import CLR .Python .Test
213199 import CLR
214- self .assertTrue (self . isCLRClass (CLR .NoNamespaceType ))
200+ self .assertTrue (isCLRClass (CLR .NoNamespaceType ))
215201
216202 def testModuleLookupRecursion (self ):
217203 """Test for recursive lookup handling."""
@@ -232,10 +218,10 @@ def testModuleGetAttr(self):
232218 import CLR .System as System
233219
234220 int_type = System .Int32
235- self .assertTrue (self . isCLRClass (int_type ))
221+ self .assertTrue (isCLRClass (int_type ))
236222
237223 module = System .Xml
238- self .assertTrue (self . isCLRModule (module ))
224+ self .assertTrue (isCLRModule (module ))
239225
240226 def test ():
241227 spam = System .Spam
0 commit comments