| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,10 +6,14 @@ | |||
| 6 | 6 | ||
| 7 | 7 | import clr | |
| 8 | 8 | import gc | |
| 9 | + import sys | ||
| 9 | 10 | ||
| 10 | 11 | import System | |
| 11 | 12 | ||
| 12 | 13 | from _compat import range | |
| 14 | + from utils import (CallableHandler, ClassMethodHandler, GenericHandler, | ||
| 15 | + HelloClass, StaticMethodHandler, VarCallableHandler, | ||
| 16 | + VariableArgsHandler, hello_func) | ||
| 13 | 17 | ||
| 14 | 18 | ||
| 15 | 19 | class LeakTest(object): | |
@@ -53,7 +57,6 @@ def run(self): | |||
| 53 | 57 | self.testDelegates() | |
| 54 | 58 | ||
| 55 | 59 | def report(self): | |
| 56 | - import sys, gc | ||
| 57 | 60 | gc.collect() | |
| 58 | 61 | dicttype = type({}) | |
| 59 | 62 | for item in gc.get_objects(): | |
@@ -78,7 +81,6 @@ def testModules(self): | |||
| 78 | 81 | def testClasses(self): | |
| 79 | 82 | from System.Collections import Hashtable | |
| 80 | 83 | from Python.Test import StringDelegate | |
| 81 | - from System import Int32 | ||
| 82 | 84 | ||
| 83 | 85 | self.notify("Running class leak check...") | |
| 84 | 86 | ||
@@ -91,7 +93,7 @@ def testClasses(self): | |||
| 91 | 93 | del x | |
| 92 | 94 | ||
| 93 | 95 | # Value type | |
| 94 | - x = Int32(99) | ||
| 96 | + x = System.Int32(99) | ||
| 95 | 97 | del x | |
| 96 | 98 | ||
| 97 | 99 | # Delegate type | |
@@ -101,7 +103,7 @@ def testClasses(self): | |||
| 101 | 103 | self.end_test() | |
| 102 | 104 | ||
| 103 | 105 | def testEnumerations(self): | |
| 104 | - from Python import Test | ||
| 106 | + import Python.Test as Test | ||
| 105 | 107 | ||
| 106 | 108 | self.notify("Running enum leak check...") | |
| 107 | 109 | ||
@@ -215,7 +217,6 @@ def handler(sender, args, dict=dict): | |||
| 215 | 217 | ||
| 216 | 218 | def testDelegates(self): | |
| 217 | 219 | from Python.Test import DelegateTest, StringDelegate | |
| 218 | - import System | ||
| 219 | 220 | ||
| 220 | 221 | self.notify("Running delegate leak check...") | |
| 221 | 222 | ||
@@ -326,92 +327,6 @@ def testDelegates(self): | |||
| 326 | 327 | self.end_test() | |
| 327 | 328 | ||
| 328 | 329 | ||
| 329 | - class GenericHandler(object): | ||
| 330 | - """A generic handler to test event callbacks.""" | ||
| 331 | - | ||
| 332 | - def __init__(self): | ||
| 333 | - self.value = None | ||
| 334 | - | ||
| 335 | - def handler(self, sender, args): | ||
| 336 | - self.value = args.value | ||
| 337 | - | ||
| 338 | - | ||
| 339 | - class VariableArgsHandler(object): | ||
| 340 | - """A variable args handler to test event callbacks.""" | ||
| 341 | - | ||
| 342 | - def __init__(self): | ||
| 343 | - self.value = None | ||
| 344 | - | ||
| 345 | - def handler(self, *args): | ||
| 346 | - ob, eventargs = args | ||
| 347 | - self.value = eventargs.value | ||
| 348 | - | ||
| 349 | - | ||
| 350 | - class CallableHandler(object): | ||
| 351 | - """A callable handler to test event callbacks.""" | ||
| 352 | - | ||
| 353 | - def __init__(self): | ||
| 354 | - self.value = None | ||
| 355 | - | ||
| 356 | - def __call__(self, sender, args): | ||
| 357 | - self.value = args.value | ||
| 358 | - | ||
| 359 | - | ||
| 360 | - class VarCallableHandler(object): | ||
| 361 | - """A variable args callable handler to test event callbacks.""" | ||
| 362 | - | ||
| 363 | - def __init__(self): | ||
| 364 | - self.value = None | ||
| 365 | - | ||
| 366 | - def __call__(self, *args): | ||
| 367 | - ob, eventargs = args | ||
| 368 | - self.value = eventargs.value | ||
| 369 | - | ||
| 370 | - | ||
| 371 | - class StaticMethodHandler(object): | ||
| 372 | - """A static method handler to test event callbacks.""" | ||
| 373 | - | ||
| 374 | - value = None | ||
| 375 | - | ||
| 376 | - def handler(sender, args): | ||
| 377 | - StaticMethodHandler.value = args.value | ||
| 378 | - | ||
| 379 | - handler = staticmethod(handler) | ||
| 380 | - | ||
| 381 | - | ||
| 382 | - class ClassMethodHandler(object): | ||
| 383 | - """A class method handler to test event callbacks.""" | ||
| 384 | - | ||
| 385 | - value = None | ||
| 386 | - | ||
| 387 | - def handler(cls, sender, args): | ||
| 388 | - cls.value = args.value | ||
| 389 | - | ||
| 390 | - handler = classmethod(handler) | ||
| 391 | - | ||
| 392 | - | ||
| 393 | - class HelloClass(object): | ||
| 394 | - def hello(self): | ||
| 395 | - return "hello" | ||
| 396 | - | ||
| 397 | - def __call__(self): | ||
| 398 | - return "hello" | ||
| 399 | - | ||
| 400 | - def s_hello(): | ||
| 401 | - return "hello" | ||
| 402 | - | ||
| 403 | - s_hello = staticmethod(s_hello) | ||
| 404 | - | ||
| 405 | - def c_hello(cls): | ||
| 406 | - return "hello" | ||
| 407 | - | ||
| 408 | - c_hello = classmethod(c_hello) | ||
| 409 | - | ||
| 410 | - | ||
| 411 | - def hello_func(): | ||
| 412 | - return "hello" | ||
| 413 | - | ||
| 414 | - | ||
| 415 | 330 | if __name__ == '__main__': | |
| 416 | 331 | test = LeakTest() | |
| 417 | 332 | test.run() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,16 @@ | |||
| 8 | 8 | from _compat import DictProxyType, range | |
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | + class ClassicClass: | ||
| 12 | + def kind(self): | ||
| 13 | + return 'classic' | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + class NewStyleClass(object): | ||
| 17 | + def kind(self): | ||
| 18 | + return 'new-style' | ||
| 19 | + | ||
| 20 | + | ||
| 11 | 21 | class ClassTests(unittest.TestCase): | |
| 12 | 22 | """Test CLR class support.""" | |
| 13 | 23 | ||
@@ -273,15 +283,5 @@ def PyCallback(self, self2): | |||
| 273 | 283 | self.assertTrue(testobj.SameReference) | |
| 274 | 284 | ||
| 275 | 285 | ||
| 276 | - class ClassicClass: | ||
| 277 | - def kind(self): | ||
| 278 | - return 'classic' | ||
| 279 | - | ||
| 280 | - | ||
| 281 | - class NewStyleClass(object): | ||
| 282 | - def kind(self): | ||
| 283 | - return 'new-style' | ||
| 284 | - | ||
| 285 | - | ||
| 286 | 286 | def test_suite(): | |
| 287 | 287 | return unittest.makeSuite(ClassTests) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,32 +4,18 @@ | |||
| 4 | 4 | import unittest | |
| 5 | 5 | ||
| 6 | 6 | from _compat import ClassType, PY2, PY3, range | |
| 7 | + from utils import isCLRClass, isCLRModule, isCLRRootModule | ||
| 7 | 8 | ||
| 8 | 9 | ||
| 9 | 10 | class 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.""" | ||
| 26 | 12 | ||
| 27 | 13 | # Tests for old-style CLR-prefixed module naming. | |
| 28 | 14 | ||
| 29 | 15 | def testSimpleImport(self): | |
| 30 | 16 | """Test simple import.""" | |
| 31 | 17 | import CLR | |
| 32 | - self.assertTrue(self.isCLRRootModule(CLR)) | ||
| 18 | + self.assertTrue(isCLRRootModule(CLR)) | ||
| 33 | 19 | self.assertTrue(CLR.__name__ == 'clr') | |
| 34 | 20 | ||
| 35 | 21 | import sys | |
@@ -49,7 +35,7 @@ def testSimpleImport(self): | |||
| 49 | 35 | def testSimpleImportWithAlias(self): | |
| 50 | 36 | """Test simple import with aliasing.""" | |
| 51 | 37 | import CLR as myCLR | |
| 52 | - self.assertTrue(self.isCLRRootModule(myCLR)) | ||
| 38 | + self.assertTrue(isCLRRootModule(myCLR)) | ||
| 53 | 39 | self.assertTrue(myCLR.__name__ == 'clr') | |
| 54 | 40 | ||
| 55 | 41 | import sys as mySys | |
@@ -69,11 +55,11 @@ def testSimpleImportWithAlias(self): | |||
| 69 | 55 | def testDottedNameImport(self): | |
| 70 | 56 | """Test dotted-name import.""" | |
| 71 | 57 | import CLR.System | |
| 72 | - self.assertTrue(self.isCLRModule(CLR.System)) | ||
| 58 | + self.assertTrue(isCLRModule(CLR.System)) | ||
| 73 | 59 | self.assertTrue(CLR.System.__name__ == 'System') | |
| 74 | 60 | ||
| 75 | 61 | import System | |
| 76 | - self.assertTrue(self.isCLRModule(System)) | ||
| 62 | + self.assertTrue(isCLRModule(System)) | ||
| 77 | 63 | self.assertTrue(System.__name__ == 'System') | |
| 78 | 64 | ||
| 79 | 65 | self.assertTrue(System is CLR.System) | |
@@ -85,11 +71,11 @@ def testDottedNameImport(self): | |||
| 85 | 71 | def testDottedNameImportWithAlias(self): | |
| 86 | 72 | """Test dotted-name import with aliasing.""" | |
| 87 | 73 | import CLR.System as myCLRSystem | |
| 88 | - self.assertTrue(self.isCLRModule(myCLRSystem)) | ||
| 74 | + self.assertTrue(isCLRModule(myCLRSystem)) | ||
| 89 | 75 | self.assertTrue(myCLRSystem.__name__ == 'System') | |
| 90 | 76 | ||
| 91 | 77 | import System as mySystem | |
| 92 | - self.assertTrue(self.isCLRModule(mySystem)) | ||
| 78 | + self.assertTrue(isCLRModule(mySystem)) | ||
| 93 | 79 | self.assertTrue(mySystem.__name__ == 'System') | |
| 94 | 80 | ||
| 95 | 81 | self.assertTrue(mySystem is myCLRSystem) | |
@@ -101,7 +87,7 @@ def testDottedNameImportWithAlias(self): | |||
| 101 | 87 | def testSimpleImportFrom(self): | |
| 102 | 88 | """Test simple 'import from'.""" | |
| 103 | 89 | from CLR import System | |
| 104 | - self.assertTrue(self.isCLRModule(System)) | ||
| 90 | + self.assertTrue(isCLRModule(System)) | ||
| 105 | 91 | self.assertTrue(System.__name__ == 'System') | |
| 106 | 92 | ||
| 107 | 93 | from xml import dom | |
@@ -111,7 +97,7 @@ def testSimpleImportFrom(self): | |||
| 111 | 97 | def testSimpleImportFromWithAlias(self): | |
| 112 | 98 | """Test simple 'import from' with aliasing.""" | |
| 113 | 99 | from CLR import System as mySystem | |
| 114 | - self.assertTrue(self.isCLRModule(mySystem)) | ||
| 100 | + self.assertTrue(isCLRModule(mySystem)) | ||
| 115 | 101 | self.assertTrue(mySystem.__name__ == 'System') | |
| 116 | 102 | ||
| 117 | 103 | from xml import dom as myDom | |
@@ -121,11 +107,11 @@ def testSimpleImportFromWithAlias(self): | |||
| 121 | 107 | def testDottedNameImportFrom(self): | |
| 122 | 108 | """Test dotted-name 'import from'.""" | |
| 123 | 109 | from CLR.System import Xml | |
| 124 | - self.assertTrue(self.isCLRModule(Xml)) | ||
| 110 | + self.assertTrue(isCLRModule(Xml)) | ||
| 125 | 111 | self.assertTrue(Xml.__name__ == 'System.Xml') | |
| 126 | 112 | ||
| 127 | 113 | from CLR.System.Xml import XmlDocument | |
| 128 | - self.assertTrue(self.isCLRClass(XmlDocument)) | ||
| 114 | + self.assertTrue(isCLRClass(XmlDocument)) | ||
| 129 | 115 | self.assertTrue(XmlDocument.__name__ == 'XmlDocument') | |
| 130 | 116 | ||
| 131 | 117 | from xml.dom import pulldom | |
@@ -139,11 +125,11 @@ def testDottedNameImportFrom(self): | |||
| 139 | 125 | def testDottedNameImportFromWithAlias(self): | |
| 140 | 126 | """Test dotted-name 'import from' with aliasing.""" | |
| 141 | 127 | from CLR.System import Xml as myXml | |
| 142 | - self.assertTrue(self.isCLRModule(myXml)) | ||
| 128 | + self.assertTrue(isCLRModule(myXml)) | ||
| 143 | 129 | self.assertTrue(myXml.__name__ == 'System.Xml') | |
| 144 | 130 | ||
| 145 | 131 | from CLR.System.Xml import XmlDocument as myXmlDocument | |
| 146 | - self.assertTrue(self.isCLRClass(myXmlDocument)) | ||
| 132 | + self.assertTrue(isCLRClass(myXmlDocument)) | ||
| 147 | 133 | self.assertTrue(myXmlDocument.__name__ == 'XmlDocument') | |
| 148 | 134 | ||
| 149 | 135 | from xml.dom import pulldom as myPulldom | |
@@ -159,12 +145,12 @@ def testFromModuleImportStar(self): | |||
| 159 | 145 | count = len(locals().keys()) | |
| 160 | 146 | m = __import__('CLR.System.Management', globals(), locals(), ['*']) | |
| 161 | 147 | self.assertTrue(m.__name__ == 'System.Management') | |
| 162 | - self.assertTrue(self.isCLRModule(m)) | ||
| 148 | + self.assertTrue(isCLRModule(m)) | ||
| 163 | 149 | self.assertTrue(len(locals().keys()) > count + 1) | |
| 164 | 150 | ||
| 165 | 151 | m2 = __import__('System.Management', globals(), locals(), ['*']) | |
| 166 | 152 | self.assertTrue(m2.__name__ == 'System.Management') | |
| 167 | - self.assertTrue(self.isCLRModule(m2)) | ||
| 153 | + self.assertTrue(isCLRModule(m2)) | ||
| 168 | 154 | self.assertTrue(len(locals().keys()) > count + 1) | |
| 169 | 155 | ||
| 170 | 156 | self.assertTrue(m is m2) | |
@@ -193,7 +179,7 @@ def testImplicitLoadAlreadyValidNamespace(self): | |||
| 193 | 179 | # Python runtime to "do the right thing", allowing types from both | |
| 194 | 180 | # assemblies to be found in the CLR.System module implicitly. | |
| 195 | 181 | import CLR.System | |
| 196 | - self.assertTrue(self.isCLRClass(CLR.System.UriBuilder)) | ||
| 182 | + self.assertTrue(isCLRClass(CLR.System.UriBuilder)) | ||
| 197 | 183 | ||
| 198 | 184 | def testImportNonExistantModule(self): | |
| 199 | 185 | """Test import failure for a non-existant module.""" | |
@@ -211,7 +197,7 @@ def testLookupNoNamespaceType(self): | |||
| 211 | 197 | """Test lookup of types without a qualified namespace.""" | |
| 212 | 198 | import CLR.Python.Test | |
| 213 | 199 | import CLR | |
| 214 | - self.assertTrue(self.isCLRClass(CLR.NoNamespaceType)) | ||
| 200 | + self.assertTrue(isCLRClass(CLR.NoNamespaceType)) | ||
| 215 | 201 | ||
| 216 | 202 | def testModuleLookupRecursion(self): | |
| 217 | 203 | """Test for recursive lookup handling.""" | |
@@ -232,10 +218,10 @@ def testModuleGetAttr(self): | |||
| 232 | 218 | import CLR.System as System | |
| 233 | 219 | ||
| 234 | 220 | int_type = System.Int32 | |
| 235 | - self.assertTrue(self.isCLRClass(int_type)) | ||
| 221 | + self.assertTrue(isCLRClass(int_type)) | ||
| 236 | 222 | ||
| 237 | 223 | module = System.Xml | |
| 238 | - self.assertTrue(self.isCLRModule(module)) | ||
| 224 | + self.assertTrue(isCLRModule(module)) | ||
| 239 | 225 | ||
| 240 | 226 | def test(): | |
| 241 | 227 | spam = System.Spam | |
| Back | FazBrowse Home | New Git URL |
0 commit comments