diff options
author | Mats Wichmann <mats@linux.com> | 2019-03-06 21:00:01 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2019-03-07 20:06:04 (GMT) |
commit | 59622eef74a5a1c698ec71cbf2d48a308c07c1fa (patch) | |
tree | a9e8fe5c8468e25d2adaf9cd43b51523b7e34174 /runtest.py | |
parent | f0f48202c59f8d00f47aaec25986d343e3c72ca4 (diff) | |
download | SCons-59622eef74a5a1c698ec71cbf2d48a308c07c1fa.zip SCons-59622eef74a5a1c698ec71cbf2d48a308c07c1fa.tar.gz SCons-59622eef74a5a1c698ec71cbf2d48a308c07c1fa.tar.bz2 |
Clean up some file opens, regex strings
Most recent Python (3.8 alpha) spews warnings aplenty about two
subjects: unclosed files and strings which look like they have embedded
escapes that Python does not recognize. The latter are usually
regexes, and it provides a reminder that regular expressions should
normally be specified as raw strings, so Python does not attempt to
interpret them. Irritating is that even docstrings are flagged, it's
not obvious what the right answer is for a docstring which contains,
say, a Windows-style path with backslashes.
This converts a bunch of opens that are not closed into context
manager usage and regex patterns into raw strings.
This eliminate about 4000 warnings spewed by Py3.8 (9200 remain).
Signed-off-by: Mats Wichmann <mats@linux.com>
Diffstat (limited to 'runtest.py')
-rwxr-xr-x | runtest.py | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -345,7 +345,7 @@ sp.append(builddir) sp.append(cwd) # -_ws = re.compile('\s') +_ws = re.compile(r'\s') def escape(s): @@ -672,12 +672,10 @@ def find_py(directory): if 'sconstest.skip' in filenames: continue try: - exclude_fp = open(os.path.join(dirpath, ".exclude_tests")) + with open(os.path.join(dirpath, ".exclude_tests")) as f: + excludes = [e.split("#", 1)[0].strip() for e in f.readlines()] except EnvironmentError: excludes = [] - else: - excludes = [ e.split('#', 1)[0].strip() - for e in exclude_fp.readlines() ] for fname in filenames: if fname.endswith(".py") and fname not in excludes: result.append(os.path.join(dirpath, fname)) @@ -685,7 +683,8 @@ def find_py(directory): if testlistfile: - tests = open(testlistfile, 'r').readlines() + with open(testlistfile, 'r') as f: + tests = f.readlines() tests = [x for x in tests if x[0] != '#'] tests = [x[:-1] for x in tests] tests = [x.strip() for x in tests] @@ -747,7 +746,8 @@ runtest.py: No tests were found. sys.exit(1) if excludelistfile: - excludetests = open(excludelistfile, 'r').readlines() + with open(excludelistfile, 'r') as f: + excludetests = f.readlines() excludetests = [x for x in excludetests if x[0] != '#'] excludetests = [x[:-1] for x in excludetests] excludetests = [x.strip() for x in excludetests] @@ -928,6 +928,12 @@ if options.xml: if options.xml != '-': f.close() +if options.output: + if isinstance(sys.stdout, Tee): + sys.stdout.file.close() + if isinstance(sys.stderr, Tee): + sys.stderr.file.close() + if len(fail): sys.exit(1) elif len(no_result): |