|
12 | 12 | # NOTE: Since version 1.2.3, you can also import this (like from a graphical application) and call the "main()" function. |
13 | 13 | # All of the following globals are the defaults, but can be overridden when calling main() (params have the same name as the globals). |
14 | 14 |
|
15 | | -import imp |
| 15 | +# Assign a local function, "find_mod" to the interface to search |
| 16 | +# PYTHONPATH for importable module |
| 17 | +try: |
| 18 | + # imp.find_module has been deprecated as of python 3.7, so |
| 19 | + # prefer some alternate/newer interfaces first. |
| 20 | + import importlib |
| 21 | + |
| 22 | + try: |
| 23 | + # If we have the newest and therefore least-deprecated |
| 24 | + # way, use it. |
| 25 | + _findModSpec = importlib.util.find_spec |
| 26 | + def find_mod(modName): |
| 27 | + ''' |
| 28 | + find_mod - Find a module by name. |
| 29 | +
|
| 30 | + Similar to import #modName but only finds importable module, |
| 31 | + does not actually import. |
| 32 | +
|
| 33 | + @raises ImportError on failure |
| 34 | + ''' |
| 35 | + modSpec = _findModSpec(modName) |
| 36 | + if not modSpec: |
| 37 | + # imp.find_module raises import error if cannot find, |
| 38 | + # but find_spec just returns None |
| 39 | + # So simulate the ImportError for common interface |
| 40 | + raise ImportError('No module named %s' %(modName, )) |
| 41 | + |
| 42 | + return modSpec |
| 43 | + |
| 44 | + except AttributeError: |
| 45 | + # We have importlib, but don't have importlib.util.find_spec |
| 46 | + |
| 47 | + # We could use importlib.import_module which is present in |
| 48 | + # python 2.7, but that changes behaviour by actually |
| 49 | + # importing (and thus additionally checking syntax/other). |
| 50 | + # |
| 51 | + # So just fall back to the old imp.find_module in this case |
| 52 | + |
| 53 | + try: |
| 54 | + # Clean up namespace |
| 55 | + del importlib |
| 56 | + except: |
| 57 | + pass |
| 58 | + # Fall back to imp.find_module implementation below |
| 59 | + raise ImportError('importlib but no importlib.util') |
| 60 | + #find_mod = lambda modName : importlib.import_module(modName) |
| 61 | + |
| 62 | +except: |
| 63 | + # importlib is not present or has an unknown/dated interface, |
| 64 | + # so fallback to the deprecated but oldest form |
| 65 | + import imp |
| 66 | + |
| 67 | + # Use a lambda to ensure only one arg is passed as that is |
| 68 | + # our standard interface |
| 69 | + find_mod = lambda modName : imp.find_module(modName) |
| 70 | + |
16 | 71 | import os |
17 | 72 |
|
18 | 73 | import subprocess |
|
32 | 87 | # This is the test directory that should contain all your tests. This should be a directory in your "tests" folder |
33 | 88 | MY_TEST_DIRECTORY = 'AdvancedHTMLParserTests' |
34 | 89 |
|
35 | | -__version__ = '2.2.0' |
36 | | -__version_tuple__ = (2, 2, 0) |
| 90 | +__version__ = '3.0.4' |
| 91 | +__version_tuple__ = (3, 0, 4) |
37 | 92 |
|
38 | 93 | def findGoodTests(): |
39 | 94 | ''' |
@@ -270,15 +325,15 @@ def main(thisDir=None, additionalArgs=[], MY_PACKAGE_MODULE=None, ALLOW_SITE_INS |
270 | 325 | elif dirName == '': |
271 | 326 | inCurrentDir = False |
272 | 327 | try: |
273 | | - imp.find_module(MY_PACKAGE_MODULE) |
| 328 | + find_mod(MY_PACKAGE_MODULE) |
274 | 329 | inCurrentDir = True |
275 | 330 | except ImportError: |
276 | 331 | # COMPAT WITH PREVIOUS runTests.py: Try plain module in parent directory |
277 | 332 | foundIt = False |
278 | 333 | oldSysPath = sys.path[:] |
279 | 334 | sys.path = [os.path.realpath(os.getcwd() + os.sep + '..' + os.sep)] |
280 | 335 | try: |
281 | | - imp.find_module(MY_PACKAGE_MODULE) |
| 336 | + find_mod(MY_PACKAGE_MODULE) |
282 | 337 | foundIt = True |
283 | 338 | sys.path = oldSysPath |
284 | 339 | except ImportError as e: |
|
0 commit comments