Skip to content

Commit 590918b

Browse files
committed
Update to latest runTests.py from GoodTests project
1 parent 8e0b2be commit 590918b

File tree

1 file changed

+60
-5
lines changed

1 file changed

+60
-5
lines changed

tests/runTests.py

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,62 @@
1212
# NOTE: Since version 1.2.3, you can also import this (like from a graphical application) and call the "main()" function.
1313
# All of the following globals are the defaults, but can be overridden when calling main() (params have the same name as the globals).
1414

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+
1671
import os
1772

1873
import subprocess
@@ -32,8 +87,8 @@
3287
# This is the test directory that should contain all your tests. This should be a directory in your "tests" folder
3388
MY_TEST_DIRECTORY = 'AdvancedHTMLParserTests'
3489

35-
__version__ = '2.2.0'
36-
__version_tuple__ = (2, 2, 0)
90+
__version__ = '3.0.4'
91+
__version_tuple__ = (3, 0, 4)
3792

3893
def findGoodTests():
3994
'''
@@ -270,15 +325,15 @@ def main(thisDir=None, additionalArgs=[], MY_PACKAGE_MODULE=None, ALLOW_SITE_INS
270325
elif dirName == '':
271326
inCurrentDir = False
272327
try:
273-
imp.find_module(MY_PACKAGE_MODULE)
328+
find_mod(MY_PACKAGE_MODULE)
274329
inCurrentDir = True
275330
except ImportError:
276331
# COMPAT WITH PREVIOUS runTests.py: Try plain module in parent directory
277332
foundIt = False
278333
oldSysPath = sys.path[:]
279334
sys.path = [os.path.realpath(os.getcwd() + os.sep + '..' + os.sep)]
280335
try:
281-
imp.find_module(MY_PACKAGE_MODULE)
336+
find_mod(MY_PACKAGE_MODULE)
282337
foundIt = True
283338
sys.path = oldSysPath
284339
except ImportError as e:

0 commit comments

Comments
 (0)