summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/AS/as-live.py3
-rw-r--r--test/AS/fixture/myas.py18
-rw-r--r--test/AS/fixture/myas_args.py23
-rw-r--r--test/Actions/actions.py7
-rw-r--r--test/Actions/append.py17
-rw-r--r--test/Actions/exitstatfunc.py4
-rw-r--r--test/Actions/function.py2
-rw-r--r--test/Actions/pre-post-fixture/work2/SConstruct3
-rw-r--r--test/Actions/pre-post-fixture/work3/SConstruct3
-rw-r--r--test/Actions/pre-post-fixture/work4/build.py8
-rw-r--r--test/Actions/timestamp.py3
-rw-r--r--test/Actions/unicode-signature-fixture/SConstruct3
-rw-r--r--test/Alias/Alias.py3
-rw-r--r--test/Alias/Depends.py3
-rw-r--r--test/Alias/action.py14
-rw-r--r--test/Alias/scanner.py8
-rw-r--r--test/Alias/srcdir.py26
-rw-r--r--test/AlwaysBuild.py3
-rw-r--r--test/Batch/Boolean.py3
-rw-r--r--test/Batch/CHANGED_SOURCES.py3
-rw-r--r--test/Batch/SOURCES.py3
-rw-r--r--test/Batch/action-changed.py7
-rw-r--r--test/Batch/callable.py3
-rw-r--r--test/Batch/removed.py3
-rw-r--r--test/Batch/up_to_date.py3
-rw-r--r--test/Builder-factories.py15
-rw-r--r--test/Builder/errors.py13
-rw-r--r--test/Builder/multi/different-actions.py7
-rw-r--r--test/Builder/multi/different-environments.py9
-rw-r--r--test/Builder/multi/different-multi.py7
-rw-r--r--test/Builder/multi/different-order.py7
-rw-r--r--test/Builder/multi/different-overrides.py7
-rw-r--r--test/Builder/multi/different-target-lists.py7
-rw-r--r--test/Builder/multi/error.py7
-rw-r--r--test/Builder/multi/lone-target-list.py7
-rw-r--r--test/Builder/multi/multi.py7
-rw-r--r--test/Builder/multi/same-actions.py7
-rw-r--r--test/Builder/multi/same-overrides.py11
-rw-r--r--test/Builder/multi/same-targets.py7
-rw-r--r--test/Builder/non-multi.py7
-rw-r--r--test/Builder/same-actions-diff-envs.py4
-rw-r--r--test/Builder/same-actions-diff-overrides.py4
-rw-r--r--test/Builder/srcdir.py8
-rw-r--r--test/Builder/wrapper.py7
-rw-r--r--test/CFILESUFFIX.py3
-rw-r--r--test/CPPFLAGS.py34
-rw-r--r--test/CPPSUFFIXES.py17
-rw-r--r--test/CXX/CXXFILESUFFIX.py3
-rw-r--r--test/Chmod.py8
-rw-r--r--test/Clean/Option.py6
-rw-r--r--test/Clean/basic.py6
-rw-r--r--test/Clean/function.py6
-rw-r--r--test/Climb/U-Default-no-target.py4
-rw-r--r--test/Climb/explicit-parent--D.py8
-rw-r--r--test/Climb/explicit-parent--U.py8
-rw-r--r--test/Climb/explicit-parent-u.py8
-rw-r--r--test/Climb/option--D.py6
-rw-r--r--test/Climb/option--U.py6
-rw-r--r--test/Climb/option-u.py8
-rw-r--r--test/Command.py26
-rw-r--r--test/CommandGenerator.py6
-rw-r--r--test/Configure/Builder-call.py3
-rw-r--r--test/Configure/VariantDir.py19
-rw-r--r--test/Configure/custom-tests.py2
-rw-r--r--test/Copy-Action.py8
-rw-r--r--test/D/AllAtOnce/Common/common.py4
-rw-r--r--test/D/CoreScanner/Common/common.py4
-rw-r--r--test/D/HSTeoh/Common/arLibIssue.py4
-rw-r--r--test/D/HSTeoh/Common/libCompileOptions.py4
-rw-r--r--test/D/HSTeoh/Common/linkingProblem.py4
-rw-r--r--test/D/HSTeoh/Common/singleStringCannotBeMultipleOptions.py4
-rw-r--r--test/D/HelloWorld/CompileAndLinkOneStep/Common/common.py4
-rw-r--r--test/D/HelloWorld/CompileThenLinkTwoSteps/Common/common.py4
-rw-r--r--test/D/Issues/2939_Ariovistus/Common/correctLinkOptions.py4
-rw-r--r--test/D/Issues/2940_Ariovistus/Common/correctLinkOptions.py4
-rw-r--r--test/D/Issues/2994/Common/D_changed_DFLAGS_not_rebuilding.py4
-rw-r--r--test/D/SharedObjects/Common/common.py4
-rw-r--r--test/DSUFFIXES.py17
-rw-r--r--test/Decider/switch-rebuild.py3
-rw-r--r--test/Default.py6
-rw-r--r--test/Delete.py16
-rw-r--r--test/Depends/Depends.py8
-rw-r--r--test/Depends/spurious-rebuilds.py3
-rw-r--r--test/Deprecated/BuildDir.py7
-rw-r--r--test/Deprecated/SConscript-build_dir.py8
-rw-r--r--test/Deprecated/SourceCode/SourceCode.py8
-rw-r--r--test/Deprecated/SourceSignatures/basic.py3
-rw-r--r--test/Deprecated/SourceSignatures/env.py3
-rw-r--r--test/Deprecated/SourceSignatures/implicit-cache.py3
-rw-r--r--test/Deprecated/SourceSignatures/no-csigs.py3
-rw-r--r--test/Deprecated/SourceSignatures/switch-rebuild.py3
-rw-r--r--test/Deprecated/TargetSignatures/content.py8
-rw-r--r--test/Deprecated/debug-nomemoizer.py3
-rw-r--r--test/ENV.py6
-rw-r--r--test/ESCAPE.py8
-rw-r--r--test/Errors/AttributeError.py4
-rw-r--r--test/Errors/Exception.py5
-rw-r--r--test/Errors/SyntaxError.py2
-rw-r--r--test/Errors/TypeError.py2
-rw-r--r--test/Errors/UserError.py2
-rw-r--r--test/Execute.py3
-rw-r--r--test/Exit.py16
-rw-r--r--test/FindFile.py12
-rw-r--r--test/Flatten.py8
-rw-r--r--test/Fortran/FORTRANMODDIR.py6
-rw-r--r--test/Fortran/FORTRANSUFFIXES.py17
-rw-r--r--test/Fortran/USE-MODULE.py6
-rw-r--r--test/Fortran/link-with-cxx.py23
-rw-r--r--test/Fortran/module-subdir.py24
-rw-r--r--test/GetBuildFailures/option-k.py3
-rw-r--r--test/GetBuildFailures/parallel.py3
-rw-r--r--test/GetBuildFailures/serial.py6
-rw-r--r--test/Glob/Repository.py8
-rw-r--r--test/Glob/VariantDir.py16
-rw-r--r--test/Glob/basic.py8
-rw-r--r--test/Glob/exclude.py8
-rw-r--r--test/Glob/source.py8
-rw-r--r--test/Glob/strings.py8
-rw-r--r--test/Glob/subdir.py8
-rw-r--r--test/Glob/subst.py8
-rw-r--r--test/HeaderGen.py12
-rw-r--r--test/IDL/MIDLCOM.py16
-rw-r--r--test/Ignore.py11
-rw-r--r--test/Install/Install.py34
-rw-r--r--test/Install/wrap-by-attribute.py8
-rw-r--r--test/Interactive/configure.py11
-rw-r--r--test/LEX/LEX.py3
-rw-r--r--test/LEX/LEXFLAGS.py3
-rw-r--r--test/LINK/LINKFLAGS.py3
-rw-r--r--test/LINK/SHLINKFLAGS.py3
-rw-r--r--test/M4/M4COM.py10
-rw-r--r--test/M4/M4COMSTR.py10
-rw-r--r--test/MSVC/batch.py14
-rw-r--r--test/MSVS/vs-10.0-scc-files.py2
-rw-r--r--test/MSVS/vs-10.0-scc-legacy-files.py4
-rw-r--r--test/MSVS/vs-11.0-scc-files.py2
-rw-r--r--test/MSVS/vs-11.0-scc-legacy-files.py4
-rw-r--r--test/MSVS/vs-14.0-scc-files.py2
-rw-r--r--test/MSVS/vs-14.0-scc-legacy-files.py4
-rw-r--r--test/MSVS/vs-14.1-scc-files.py2
-rw-r--r--test/MSVS/vs-14.1-scc-legacy-files.py4
-rw-r--r--test/MSVS/vs-7.0-scc-files.py4
-rw-r--r--test/MSVS/vs-7.0-scc-legacy-files.py2
-rw-r--r--test/MSVS/vs-7.1-scc-legacy-files.py2
-rw-r--r--test/MSVS/vs-8.0-scc-legacy-files.py2
-rw-r--r--test/MSVS/vs-9.0-scc-legacy-files.py2
-rw-r--r--test/Mkdir.py24
-rw-r--r--test/Move.py8
-rw-r--r--test/NoClean.py15
-rw-r--r--test/ParseDepends.py6
-rw-r--r--test/QT/qt_warnings.py4
-rw-r--r--test/Repository/Default.py3
-rw-r--r--test/Repository/LIBPATH.py15
-rw-r--r--test/Repository/Local.py4
-rw-r--r--test/Repository/SConscript.py18
-rw-r--r--test/Repository/VariantDir.py8
-rw-r--r--test/Repository/option-c.py4
-rw-r--r--test/Repository/option-f.py8
-rw-r--r--test/Repository/option-n.py3
-rw-r--r--test/Repository/targets.py8
-rw-r--r--test/Requires/basic.py11
-rw-r--r--test/Requires/eval-order.py7
-rw-r--r--test/Rpcgen/RPCGEN.py13
-rw-r--r--test/Rpcgen/RPCGENCLIENTFLAGS.py13
-rw-r--r--test/Rpcgen/RPCGENFLAGS.py13
-rw-r--r--test/Rpcgen/RPCGENHEADERFLAGS.py13
-rw-r--r--test/Rpcgen/RPCGENSERVICEFLAGS.py13
-rw-r--r--test/Rpcgen/RPCGENXDRFLAGS.py13
-rw-r--r--test/SConscript/SConscript.py2
-rw-r--r--test/SConscript/SConscriptChdir.py24
-rw-r--r--test/SConsignFile/default.py6
-rw-r--r--test/SConsignFile/explicit-file.py6
-rw-r--r--test/SConsignFile/use-dbhash.py6
-rw-r--r--test/SConsignFile/use-dbm.py6
-rw-r--r--test/SConsignFile/use-dumbdbm.py6
-rw-r--r--test/SConsignFile/use-gdbm.py6
-rw-r--r--test/SHELL.py8
-rw-r--r--test/SPAWN.py8
-rw-r--r--test/Scanner/FindPathDirs.py8
-rw-r--r--test/Scanner/Scanner.py11
-rw-r--r--test/Scanner/dictionary.py8
-rw-r--r--test/Scanner/empty-implicit.py3
-rw-r--r--test/Scanner/exception.py11
-rw-r--r--test/Scanner/generated.py18
-rw-r--r--test/Scanner/multi-env.py7
-rw-r--r--test/Scanner/no-Dir-node.py10
-rw-r--r--test/Scanner/source_scanner-dict.py30
-rw-r--r--test/Scanner/unicode.py7
-rw-r--r--test/SideEffect/directory.py3
-rw-r--r--test/SideEffect/parallel.py3
-rw-r--r--test/Subst/null-sources-attr.py8
-rw-r--r--test/TAR/TAR.py12
-rw-r--r--test/TAR/TARFLAGS.py14
-rw-r--r--test/TARGET-dir.py7
-rw-r--r--test/TEX/LATEX.py21
-rw-r--r--test/TEX/LATEX2.py2
-rw-r--r--test/TEX/LATEXCOM.py2
-rw-r--r--test/TEX/LATEXCOMSTR.py2
-rw-r--r--test/TEX/LATEXFLAGS.py11
-rw-r--r--test/TEX/PDFLATEX.py21
-rw-r--r--test/TEX/PDFLATEXCOM.py2
-rw-r--r--test/TEX/PDFLATEXCOMSTR.py3
-rw-r--r--test/TEX/PDFLATEXFLAGS.py11
-rw-r--r--test/TEX/PDFTEX.py21
-rw-r--r--test/TEX/PDFTEXCOM.py2
-rw-r--r--test/TEX/PDFTEXCOMSTR.py3
-rw-r--r--test/TEX/PDFTEXFLAGS.py11
-rw-r--r--test/TEX/PDF_single_source.py4
-rw-r--r--test/TEX/TEX.py21
-rw-r--r--test/TEX/TEXCOM.py2
-rw-r--r--test/TEX/TEXCOMSTR.py2
-rw-r--r--test/TEX/TEXFLAGS.py11
-rw-r--r--test/TEX/auxiliaries.py2
-rwxr-xr-xtest/TEX/biber_biblatex.py2
-rw-r--r--test/TEX/biber_biblatex2.py2
-rwxr-xr-xtest/TEX/biblatex.py2
-rw-r--r--test/TEX/biblatex_plain.py2
-rw-r--r--test/TEX/bibliography.py4
-rw-r--r--test/TEX/bibtex-latex-rerun.py2
-rw-r--r--test/TEX/clean.py2
-rw-r--r--test/TEX/configure.py2
-rw-r--r--test/TEX/dryrun.py2
-rw-r--r--test/TEX/eps_graphics.py16
-rw-r--r--test/TEX/eps_graphics2.py20
-rw-r--r--test/TEX/generated_files.py2
-rw-r--r--test/TEX/glossaries.py2
-rw-r--r--test/TEX/glossary.py2
-rw-r--r--test/TEX/input_docClass.py14
-rw-r--r--test/TEX/lstinputlisting.py2
-rw-r--r--test/TEX/makeindex.py2
-rw-r--r--test/TEX/multi-line_include_options.py2
-rw-r--r--test/TEX/multi-run.py2
-rw-r--r--test/TEX/multibib.py2
-rw-r--r--test/TEX/multiple_include.py14
-rw-r--r--test/TEX/multiple_include_subdir.py16
-rw-r--r--test/TEX/newglossary.py6
-rw-r--r--test/TEX/nomencl.py4
-rw-r--r--test/TEX/recursive_scanner_dependencies_import.py4
-rw-r--r--test/TEX/recursive_scanner_dependencies_input.py3
-rw-r--r--test/TEX/rename_result.py2
-rwxr-xr-xtest/TEX/subdir-as-include.py2
-rw-r--r--test/TEX/subdir-input.py2
-rw-r--r--test/TEX/subdir_variantdir_include.py2
-rw-r--r--test/TEX/subdir_variantdir_include2.py10
-rw-r--r--test/TEX/subdir_variantdir_input.py2
-rw-r--r--test/TEX/synctex.py2
-rw-r--r--test/TEX/usepackage.py2
-rw-r--r--test/TEX/variant_dir.py18
-rw-r--r--test/TEX/variant_dir_bibunit.py2
-rw-r--r--test/TEX/variant_dir_dup0.py26
-rw-r--r--test/TEX/variant_dir_newglossary.py6
-rw-r--r--test/TEX/variant_dir_style_dup0.py12
-rw-r--r--test/ToolSurrogate.py8
-rw-r--r--test/Touch.py8
-rw-r--r--test/Value.py1
-rw-r--r--test/Variables/Variables.py4
-rw-r--r--test/Variables/chdir.py4
-rw-r--r--test/VariantDir/Clean.py6
-rw-r--r--test/VariantDir/SConscript-variant_dir.py18
-rw-r--r--test/WhereIs.py2
-rw-r--r--test/Win32/bad-drive.py8
-rw-r--r--test/Win32/default-drive.py8
-rw-r--r--test/YACC/YACC-fixture/myyacc.py12
-rw-r--r--test/YACC/YACCFLAGS-fixture/myyacc.py16
-rw-r--r--test/YACC/YACCHFILESUFFIX.py9
-rw-r--r--test/YACC/YACCHXXFILESUFFIX.py9
-rw-r--r--test/YACC/YACCVCGFILESUFFIX.py9
-rw-r--r--test/builderrors.py10
-rw-r--r--test/chdir.py9
-rw-r--r--test/duplicate-sources.py8
-rw-r--r--test/emitter.py3
-rw-r--r--test/explain/basic.py10
-rw-r--r--test/explain/save-info.py10
-rw-r--r--test/fixture/mycompile.py6
-rw-r--r--test/fixture/mylink.py8
-rw-r--r--test/fixture/myrewrite.py5
-rw-r--r--test/fixture/wrapper.py4
-rw-r--r--test/gnutools.py28
-rw-r--r--test/ignore-command.py8
-rw-r--r--test/implicit/IMPLICIT_COMMAND_DEPENDENCIES.py15
-rw-r--r--test/implicit/asynchronous-modification.py6
-rw-r--r--test/implicit/changed-node.py38
-rw-r--r--test/long-lines/signature.py12
-rw-r--r--test/multiline.py6
-rw-r--r--test/no-arguments.py8
-rw-r--r--test/no-target.py8
-rw-r--r--test/option--max-drift.py6
-rw-r--r--test/option--random.py8
-rw-r--r--test/option-n.py5
-rw-r--r--test/option/debug-count.py5
-rw-r--r--test/option/debug-findlibs.py9
-rw-r--r--test/option/debug-memoizer.py3
-rw-r--r--test/option/debug-memory.py3
-rw-r--r--test/option/debug-multiple.py5
-rw-r--r--test/option/debug-objects.py3
-rw-r--r--test/option/debug-presub.py11
-rw-r--r--test/option/debug-time.py8
-rw-r--r--test/option/md5-chunksize.py11
-rw-r--r--test/option/stack-size.py6
-rw-r--r--test/option/warn-duplicate-environment.py7
-rw-r--r--test/option/warn-misleading-keywords.py7
-rw-r--r--test/overrides.py12
-rw-r--r--test/packaging/convenience-functions/convenience-functions.py2
-rw-r--r--test/packaging/ipkg.py7
-rw-r--r--test/packaging/place-files-in-subdirectory.py5
-rw-r--r--test/packaging/rpm/internationalization.py22
-rw-r--r--test/packaging/rpm/multipackage.py6
-rw-r--r--test/packaging/rpm/package.py8
-rw-r--r--test/packaging/rpm/tagging.py6
-rw-r--r--test/preserve-source.py8
-rw-r--r--test/python-version.py2
-rw-r--r--test/question/basic.py6
-rw-r--r--test/redirection.py9
-rw-r--r--test/runtest/python.py2
-rw-r--r--test/sconsign/corrupt.py11
-rw-r--r--test/sconsign/ghost-entries.py8
-rw-r--r--test/sconsign/script/SConsignFile.py24
-rw-r--r--test/sconsign/script/Signatures.py22
-rw-r--r--test/sconsign/script/bad.py8
-rw-r--r--test/sconsign/script/dblite.py4
-rw-r--r--test/sconsign/script/no-SConsignFile.py24
-rw-r--r--test/silent-command.py8
-rw-r--r--test/site_scons/site_init.py2
-rw-r--r--test/special-filenames.py3
-rw-r--r--test/srcchange.py10
-rw-r--r--test/strfunction.py6
-rw-r--r--test/subclassing.py2
-rw-r--r--test/subdir.py6
-rw-r--r--test/subdivide.py18
-rw-r--r--test/suffixes.py8
-rw-r--r--test/timestamp-fallback.py9
-rw-r--r--test/toolpath/VariantDir.py4
-rw-r--r--test/up-to-date.py6
333 files changed, 1355 insertions, 1252 deletions
diff --git a/test/AS/as-live.py b/test/AS/as-live.py
index 879e7b2..b781caf 100644
--- a/test/AS/as-live.py
+++ b/test/AS/as-live.py
@@ -58,7 +58,8 @@ if sys.platform == "win32":
test.write("wrapper.py", """\
import os
import sys
-open('%s', 'wb').write(("wrapper.py: %%s\\n" %% sys.argv[-1]).encode())
+with open('%s', 'wb') as f:
+ f.write(("wrapper.py: %%s\\n" %% sys.argv[-1]).encode())
cmd = " ".join(sys.argv[1:])
os.system(cmd)
""" % test.workpath('wrapper.out').replace('\\', '\\\\'))
diff --git a/test/AS/fixture/myas.py b/test/AS/fixture/myas.py
index bffae78..4f5d9ac 100644
--- a/test/AS/fixture/myas.py
+++ b/test/AS/fixture/myas.py
@@ -15,11 +15,10 @@ if sys.platform == 'win32':
inf = a
continue
if a[:3] == '/Fo': out = a[3:]
- infile = open(inf, 'rb')
- outfile = open(out, 'wb')
- for l in infile.readlines():
- if l[:3] != b'#as':
- outfile.write(l)
+ with open(inf, 'rb') as ifp, open(out, 'wb') as ofp:
+ for l in ifp.readlines():
+ if l[:3] != b'#as':
+ ofp.write(l)
sys.exit(0)
else:
@@ -27,9 +26,8 @@ else:
opts, args = getopt.getopt(sys.argv[1:], 'co:')
for opt, arg in opts:
if opt == '-o': out = arg
- infile = open(args[0], 'rb')
- outfile = open(out, 'wb')
- for l in infile.readlines():
- if l[:3] != b'#as':
- outfile.write(l)
+ with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp:
+ for l in ifp.readlines():
+ if l[:3] != b'#as':
+ ofp.write(l)
sys.exit(0)
diff --git a/test/AS/fixture/myas_args.py b/test/AS/fixture/myas_args.py
index c7ca315..24d68dc 100644
--- a/test/AS/fixture/myas_args.py
+++ b/test/AS/fixture/myas_args.py
@@ -21,12 +21,11 @@ if sys.platform == 'win32':
out = a[3:]
continue
optstring = optstring + ' ' + a
- infile = open(inf, 'rb')
- outfile = open(out, 'wb')
- outfile.write(bytearray(optstring + "\n",'utf-8'))
- for l in infile.readlines():
- if l[:3] != b'#as':
- outfile.write(l)
+ with open(inf, 'rb') as ifp, open(out, 'wb') as ofp:
+ ofp.write(bytearray(optstring + "\n",'utf-8'))
+ for l in ifp.readlines():
+ if l[:3] != b'#as':
+ ofp.write(l)
sys.exit(0)
else:
import getopt
@@ -37,12 +36,10 @@ else:
if opt == '-o': out = arg
else: optstring = optstring + ' ' + opt
- infile = open(args[0], 'rb')
- outfile = open(out, 'wb')
- outfile.write(bytearray(optstring + "\n",'utf-8'))
-
- for l in infile.readlines():
- if l[:3] != b'#as':
- outfile.write(l)
+ with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp:
+ ofp.write(bytearray(optstring + "\n",'utf-8'))
+ for l in ifp.readlines():
+ if l[:3] != b'#as':
+ ofp.write(l)
sys.exit(0)
diff --git a/test/Actions/actions.py b/test/Actions/actions.py
index e69cdd7..f1bb6fe 100644
--- a/test/Actions/actions.py
+++ b/test/Actions/actions.py
@@ -32,10 +32,9 @@ test = TestSCons.TestSCons()
test.write('build.py', r"""
import sys
-file = open(sys.argv[1], 'wb')
-file.write((sys.argv[2] + "\n").encode())
-file.write(open(sys.argv[3], 'rb').read())
-file.close
+with open(sys.argv[1], 'wb') as f, open(sys.argv[3], 'rb') as infp:
+ f.write((sys.argv[2] + "\n").encode())
+ f.write(infp.read())
sys.exit(0)
""")
diff --git a/test/Actions/append.py b/test/Actions/append.py
index 68646b3..0a59c42 100644
--- a/test/Actions/append.py
+++ b/test/Actions/append.py
@@ -44,19 +44,14 @@ test.write('SConstruct', """
env=Environment()
def before(env, target, source):
- f=open(str(target[0]), "wb")
- f.write(b"Foo\\n")
- f.close()
- f=open("before.txt", "wb")
- f.write(b"Bar\\n")
- f.close()
+ with open(str(target[0]), "wb") as f:
+ f.write(b"Foo\\n")
+ with open("before.txt", "wb") as f:
+ f.write(b"Bar\\n")
def after(env, target, source):
- fin = open(str(target[0]), "rb")
- fout = open("after%s", "wb")
- fout.write(fin.read())
- fout.close()
- fin.close()
+ with open(str(target[0]), "rb") as fin, open("after%s", "wb") as fout:
+ fout.write(fin.read())
env.Prepend(LINKCOM=Action(before))
env.Append(LINKCOM=Action(after))
diff --git a/test/Actions/exitstatfunc.py b/test/Actions/exitstatfunc.py
index c2feef8..2e2a540 100644
--- a/test/Actions/exitstatfunc.py
+++ b/test/Actions/exitstatfunc.py
@@ -38,8 +38,8 @@ def always_succeed(s):
return 0
def copy_fail(target, source, env):
- content = open(str(source[0]), 'rb').read()
- open(str(target[0]), 'wb').write(content)
+ with open(str(source[0]), 'rb') as infp, open(str(target[0]), 'wb') as f:
+ f.write(infp.read())
return 2
a = Action(copy_fail, exitstatfunc=always_succeed)
diff --git a/test/Actions/function.py b/test/Actions/function.py
index 61311af..7f292cf 100644
--- a/test/Actions/function.py
+++ b/test/Actions/function.py
@@ -90,7 +90,7 @@ def toto(header='%(header)s', trailer='%(trailer)s'):
return writeDeps
'''
-exec( withClosure % optEnv )
+exec(withClosure % optEnv)
genHeaderBld = SCons.Builder.Builder(
action = SCons.Action.Action(
diff --git a/test/Actions/pre-post-fixture/work2/SConstruct b/test/Actions/pre-post-fixture/work2/SConstruct
index 61f739f..6f03a53 100644
--- a/test/Actions/pre-post-fixture/work2/SConstruct
+++ b/test/Actions/pre-post-fixture/work2/SConstruct
@@ -1,5 +1,6 @@
def b(target, source, env):
- open(str(target[0]), 'wb').write((env['X'] + '\n').encode())
+ with open(str(target[0]), 'wb') as f:
+ f.write((env['X'] + '\n').encode())
env1 = Environment(X='111')
env2 = Environment(X='222')
B = Builder(action = b, env = env1, multi=1)
diff --git a/test/Actions/pre-post-fixture/work3/SConstruct b/test/Actions/pre-post-fixture/work3/SConstruct
index 0e13fa2..d523295 100644
--- a/test/Actions/pre-post-fixture/work3/SConstruct
+++ b/test/Actions/pre-post-fixture/work3/SConstruct
@@ -3,7 +3,8 @@ def pre(target, source, env):
def post(target, source, env):
pass
def build(target, source, env):
- open(str(target[0]), 'wb').write(b'build()\n')
+ with open(str(target[0]), 'wb') as f:
+ f.write(b'build()\n')
env = Environment()
AddPreAction('dir', pre)
AddPostAction('dir', post)
diff --git a/test/Actions/pre-post-fixture/work4/build.py b/test/Actions/pre-post-fixture/work4/build.py
index db0572a..390c8b9 100644
--- a/test/Actions/pre-post-fixture/work4/build.py
+++ b/test/Actions/pre-post-fixture/work4/build.py
@@ -1,5 +1,5 @@
import sys
-outfp = open(sys.argv[1], 'wb')
-for f in sys.argv[2:]:
- outfp.write(open(f, 'rb').read())
-outfp.close()
+with open(sys.argv[1], 'wb') as outfp:
+ for f in sys.argv[2:]:
+ with open(f, 'rb') as infp:
+ outfp.write(infp.read())
diff --git a/test/Actions/timestamp.py b/test/Actions/timestamp.py
index 835ac7f..d94a287 100644
--- a/test/Actions/timestamp.py
+++ b/test/Actions/timestamp.py
@@ -45,7 +45,8 @@ test.not_up_to_date(arguments = 'file.out')
test.write('SConstruct', """\
def my_copy(target, source, env):
- open(str(target[0]), 'w').write(open(str(source[0]), 'r').read())
+ with open(str(target[0]), 'w') as f, open(str(source[0]), 'r') as infp:
+ f.write(infp.read())
env = Environment()
env.Decider('timestamp-match')
env.Command('file.out', 'file.in', my_copy)
diff --git a/test/Actions/unicode-signature-fixture/SConstruct b/test/Actions/unicode-signature-fixture/SConstruct
index 9c0f03d..4d466e1 100644
--- a/test/Actions/unicode-signature-fixture/SConstruct
+++ b/test/Actions/unicode-signature-fixture/SConstruct
@@ -1,7 +1,8 @@
fnode = File(u'foo.txt')
def funcact(target, source, env):
- open(str(target[0]), 'wb').write(b"funcact\n")
+ with open(str(target[0]), 'wb') as f:
+ f.write(b"funcact\n")
for i in range(300):
pass
return 0
diff --git a/test/Alias/Alias.py b/test/Alias/Alias.py
index a5dd903..c371625 100644
--- a/test/Alias/Alias.py
+++ b/test/Alias/Alias.py
@@ -37,7 +37,8 @@ test.subdir('sub1', 'sub2')
test.write('build.py', r"""
import sys
-open(sys.argv[1], 'wb').write(open(sys.argv[2], 'rb').read())
+with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as ifp:
+ f.write(ifp.read())
sys.exit(0)
""")
diff --git a/test/Alias/Depends.py b/test/Alias/Depends.py
index a1129e4..715374c 100644
--- a/test/Alias/Depends.py
+++ b/test/Alias/Depends.py
@@ -37,7 +37,8 @@ test.subdir('sub1', 'sub2')
test.write('build.py', r"""
import sys
-open(sys.argv[1], 'wb').write(open(sys.argv[2], 'rb').read())
+with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as ifp:
+ f.write(ifp.read())
sys.exit(0)
""")
diff --git a/test/Alias/action.py b/test/Alias/action.py
index 2a10dbc..def27a7 100644
--- a/test/Alias/action.py
+++ b/test/Alias/action.py
@@ -35,20 +35,22 @@ test = TestSCons.TestSCons()
test.write('SConstruct', """
def cat(target, source, env):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as f:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ f.write(ifp.read())
def foo(target, source, env):
target = list(map(str, target))
source = list(map(str, source))
- open('foo', 'wb').write(bytearray("foo(%s, %s)\\n" % (target, source),'utf-8'))
+ with open('foo', 'wb') as f:
+ f.write(bytearray("foo(%s, %s)\\n" % (target, source),'utf-8'))
def bar(target, source, env):
target = list(map(str, target))
source = list(map(str, source))
- open('bar', 'wb').write(bytearray("bar(%s, %s)\\n" % (target, source),'utf-8'))
+ with open('bar', 'wb') as f:
+ f.write(bytearray("bar(%s, %s)\\n" % (target, source),'utf-8'))
env = Environment(BUILDERS = {'Cat':Builder(action=cat)})
env.Alias(target = ['build-f1'], source = 'f1.out', action = foo)
diff --git a/test/Alias/scanner.py b/test/Alias/scanner.py
index d20a729..a6ded81 100644
--- a/test/Alias/scanner.py
+++ b/test/Alias/scanner.py
@@ -35,10 +35,10 @@ test = TestSCons.TestSCons()
test.write('SConstruct', """
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as f:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ f.write(ifp.read())
XBuilder = Builder(action = cat, src_suffix = '.x', suffix = '.c')
env = Environment()
diff --git a/test/Alias/srcdir.py b/test/Alias/srcdir.py
index 4a0de43..977d114 100644
--- a/test/Alias/srcdir.py
+++ b/test/Alias/srcdir.py
@@ -63,21 +63,23 @@ test.subdir('python')
test.write('SConstruct', """\
import os.path
-env = Environment ()
+env = Environment()
-def at_copy_ext (target, source, env):
- n = str (source[0])
- s = open (n, 'rb').read ()
- e = os.path.splitext (n)[1]
- t = str (target[0]) + e
- open (t, 'wb').write (s)
+def at_copy_ext(target, source, env):
+ n = str(source[0])
+ with open(n, 'rb') as f:
+ s = f.read()
+ e = os.path.splitext(n)[1]
+ t = str(target[0]) + e
+ with open(t, 'wb') as f:
+ f.write(s)
-AT_COPY_EXT = Builder (action = at_copy_ext, src_suffix=['.py', '.sh',])
-env.Append (BUILDERS = {'AT_COPY_EXT': AT_COPY_EXT})
+AT_COPY_EXT = Builder(action=at_copy_ext, src_suffix=['.py', '.sh',])
+env.Append(BUILDERS={'AT_COPY_EXT': AT_COPY_EXT})
-env.Alias ('minimal', ['python'])
+env.Alias('minimal', ['python'])
-Export ('env')
+Export('env')
b = 'python/out-scons'
@@ -87,7 +89,7 @@ SConscript(b + '/SConscript')
""")
test.write(['python', 'SConscript'], """\
-Import ('env')
+Import('env')
env.AT_COPY_EXT('foo.py')
""")
diff --git a/test/AlwaysBuild.py b/test/AlwaysBuild.py
index dfd9fd4..55e6f27 100644
--- a/test/AlwaysBuild.py
+++ b/test/AlwaysBuild.py
@@ -55,7 +55,8 @@ c2 = env.Alias('clean2', [], [Delete('clean2-t1'), Delete('clean2-t2')])
env.AlwaysBuild(c2)
def dir_build(target, source, env):
- open('dir_build.txt', 'ab').write(b'dir_build()\\n')
+ with open('dir_build.txt', 'ab') as f:
+ f.write(b'dir_build()\\n')
env.Command(Dir('dir'), None, dir_build)
env.AlwaysBuild('dir')
""" % locals())
diff --git a/test/Batch/Boolean.py b/test/Batch/Boolean.py
index 53cceb6..c118745 100644
--- a/test/Batch/Boolean.py
+++ b/test/Batch/Boolean.py
@@ -36,7 +36,8 @@ test = TestSCons.TestSCons()
test.write('SConstruct', """
def batch_build(target, source, env):
for t, s in zip(target, source):
- open(str(t), 'wb').write(open(str(s), 'rb').read())
+ with open(str(t), 'wb') as f, open(str(s), 'rb') as infp:
+ f.write(infp.read())
env = Environment()
bb = Action(batch_build, batch_key=True)
env['BUILDERS']['Batch'] = Builder(action=bb)
diff --git a/test/Batch/CHANGED_SOURCES.py b/test/Batch/CHANGED_SOURCES.py
index 0b9f3ba..477869f 100644
--- a/test/Batch/CHANGED_SOURCES.py
+++ b/test/Batch/CHANGED_SOURCES.py
@@ -43,7 +43,8 @@ dir = sys.argv[1]
for infile in sys.argv[2:]:
inbase = os.path.splitext(os.path.split(infile)[1])[0]
outfile = os.path.join(dir, inbase+'.out')
- open(outfile, 'wb').write(open(infile, 'rb').read())
+ with open(outfile, 'wb') as f, open(infile, 'rb') as infp:
+ f.write(infp.read())
sys.exit(0)
""")
diff --git a/test/Batch/SOURCES.py b/test/Batch/SOURCES.py
index ddb3b10..8198f92 100644
--- a/test/Batch/SOURCES.py
+++ b/test/Batch/SOURCES.py
@@ -43,7 +43,8 @@ dir = sys.argv[1]
for infile in sys.argv[2:]:
inbase = os.path.splitext(os.path.split(infile)[1])[0]
outfile = os.path.join(dir, inbase+'.out')
- open(outfile, 'wb').write(open(infile, 'rb').read())
+ with open(outfile, 'wb') as f, open(infile, 'rb') as infp:
+ f.write(infp.read())
sys.exit(0)
""")
diff --git a/test/Batch/action-changed.py b/test/Batch/action-changed.py
index 1dc0f08..777c7fb 100644
--- a/test/Batch/action-changed.py
+++ b/test/Batch/action-changed.py
@@ -46,10 +46,9 @@ sources = sys.argv[sep+1:]
for i in range(len(targets)):
t = targets[i]
s = sources[i]
- fp = open(t, 'wb')
- fp.write(bytearray('%s\\n','utf-8'))
- fp.write(open(s, 'rb').read())
- fp.close()
+ with open(t, 'wb') as fp, open(s, 'rb') as infp:
+ fp.write(bytearray('%s\\n','utf-8'))
+ fp.write(infp.read())
sys.exit(0)
"""
diff --git a/test/Batch/callable.py b/test/Batch/callable.py
index 6fbd11c..9fe14ee 100644
--- a/test/Batch/callable.py
+++ b/test/Batch/callable.py
@@ -40,7 +40,8 @@ test.subdir('sub1', 'sub2')
test.write('SConstruct', """
def batch_build(target, source, env):
for t, s in zip(target, source):
- open(str(t), 'wb').write(open(str(s), 'rb').read())
+ with open(str(t), 'wb') as f, open(str(s), 'rb') as infp:
+ f.write(infp.read())
if ARGUMENTS.get('BATCH_CALLABLE'):
def batch_key(action, env, target, source):
return (id(action), id(env), target[0].dir)
diff --git a/test/Batch/removed.py b/test/Batch/removed.py
index f4455c2..b244cb3 100644
--- a/test/Batch/removed.py
+++ b/test/Batch/removed.py
@@ -42,7 +42,8 @@ dir = sys.argv[1]
for infile in sys.argv[2:]:
inbase = os.path.splitext(os.path.split(infile)[1])[0]
outfile = os.path.join(dir, inbase+'.out')
- open(outfile, 'wb').write(open(infile, 'rb').read())
+ with open(outfile, 'wb') as f, open(infile, 'rb') as infp:
+ f.write(infp.read())
sys.exit(0)
""")
diff --git a/test/Batch/up_to_date.py b/test/Batch/up_to_date.py
index 58152e0..229c88f 100644
--- a/test/Batch/up_to_date.py
+++ b/test/Batch/up_to_date.py
@@ -42,7 +42,8 @@ dir = sys.argv[1]
for infile in sys.argv[2:]:
inbase = os.path.splitext(os.path.split(infile)[1])[0]
outfile = os.path.join(dir, inbase+'.out')
- open(outfile, 'wb').write(open(infile, 'rb').read())
+ with open(outfile, 'wb') as f, open(infile, 'rb') as infp:
+ f.write(infp.read())
sys.exit(0)
""")
diff --git a/test/Builder-factories.py b/test/Builder-factories.py
index 45bf08f..e1fb65c 100644
--- a/test/Builder-factories.py
+++ b/test/Builder-factories.py
@@ -43,15 +43,16 @@ import os.path
def mkdir(env, source, target):
t = str(target[0])
os.makedirs(t)
- open(os.path.join(t, 'marker'), 'wb').write(b"MakeDirectory\\n")
+ with open(os.path.join(t, 'marker'), 'wb') as f:
+ f.write(b"MakeDirectory\\n")
MakeDirectory = Builder(action=mkdir, target_factory=Dir)
def collect(env, source, target):
- out = open(str(target[0]), 'wb')
- dir = str(source[0])
- for f in sorted(os.listdir(dir)):
- f = os.path.join(dir, f)
- out.write(open(f, 'rb').read())
- out.close()
+ with open(str(target[0]), 'wb') as out:
+ dir = str(source[0])
+ for f in sorted(os.listdir(dir)):
+ f = os.path.join(dir, f)
+ with open(f, 'rb') as infp:
+ out.write(infp.read())
Collect = Builder(action=collect, source_factory=Dir)
env = Environment(BUILDERS = {'MakeDirectory':MakeDirectory,
'Collect':Collect})
diff --git a/test/Builder/errors.py b/test/Builder/errors.py
index 1e4e16c..bd7e100 100644
--- a/test/Builder/errors.py
+++ b/test/Builder/errors.py
@@ -38,13 +38,10 @@ SConstruct_path = test.workpath('SConstruct')
sconstruct = """
def buildop(env, source, target):
- outf = open(str(target[0]), 'wb')
- inpf = open(str(source[0]), 'r')
- for line in inpf.readlines():
- if line.find(str(target[0])) == -1:
- outf.write(line)
- inpf.close()
- outf.close()
+ with open(str(target[0]), 'wb') as outf, open(str(source[0]), 'r') as infp:
+ for line in inpf.readlines():
+ if line.find(str(target[0])) == -1:
+ outf.write(line)
b1 = Builder(action=buildop, src_suffix='.a', suffix='.b')
%s
env=Environment(tools=[], BUILDERS={'b1':b1, 'b2':b2})
@@ -58,7 +55,7 @@ foo.b
built
""")
-python_file_line = test.python_file_line(SConstruct_path, 14)
+python_file_line = test.python_file_line(SConstruct_path, 11)
### Gross mistake in Builder spec
diff --git a/test/Builder/multi/different-actions.py b/test/Builder/multi/different-actions.py
index 30e98f8..ec07b62 100644
--- a/test/Builder/multi/different-actions.py
+++ b/test/Builder/multi/different-actions.py
@@ -36,9 +36,10 @@ test = TestSCons.TestSCons(match=TestSCons.match_re)
test.write('SConstruct', """\
DefaultEnvironment(tools=[])
def build(env, target, source):
- file = open(str(target[0]), 'wb')
- for s in source:
- file.write(open(str(s), 'rb').read())
+ with open(str(target[0]), 'wb') as f:
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ f.write(infp.read())
B = Builder(action=Action(build, varlist=['XXX']), multi=1)
env = Environment(tools=[], BUILDERS = { 'B' : B }, XXX = 'foo')
diff --git a/test/Builder/multi/different-environments.py b/test/Builder/multi/different-environments.py
index 9ce09b9..82b10ec 100644
--- a/test/Builder/multi/different-environments.py
+++ b/test/Builder/multi/different-environments.py
@@ -39,10 +39,11 @@ _python_ = TestSCons._python_
test.write('build.py', r"""\
import sys
def build(num, target, source):
- file = open(str(target), 'wb')
- file.write('%s\n' % num)
- for s in source:
- file.write(open(str(s), 'rb').read())
+ with open(str(target), 'wb') as f:
+ f.write('%s\n' % num)
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ f.write(infp.read())
build(sys.argv[1],sys.argv[2],sys.argv[3:])
""")
diff --git a/test/Builder/multi/different-multi.py b/test/Builder/multi/different-multi.py
index 28002bd..3084bf5 100644
--- a/test/Builder/multi/different-multi.py
+++ b/test/Builder/multi/different-multi.py
@@ -37,9 +37,10 @@ test.write('SConstruct', """\
DefaultEnvironment(tools=[])
def build(env, target, source):
- file = open(str(target[0]), 'wb')
- for s in source:
- file.write(open(str(s), 'rb').read())
+ with open(str(target[0]), 'wb') as f:
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ f.write(infp.read())
def build2(env, target, source):
build(env, target, source)
diff --git a/test/Builder/multi/different-order.py b/test/Builder/multi/different-order.py
index c423969..4018159 100644
--- a/test/Builder/multi/different-order.py
+++ b/test/Builder/multi/different-order.py
@@ -39,9 +39,10 @@ test.write('SConstruct', """\
DefaultEnvironment(tools=[])
def build(env, target, source):
for t in target:
- file = open(str(target[0]), 'wb')
- for s in source:
- file.write(open(str(s), 'rb').read())
+ with open(str(target[0]), 'wb') as f:
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ f.write(infp.read())
B = Builder(action=build, multi=1)
env = Environment(tools=[], BUILDERS = { 'B' : B })
diff --git a/test/Builder/multi/different-overrides.py b/test/Builder/multi/different-overrides.py
index 6a38a93..c4267f3 100644
--- a/test/Builder/multi/different-overrides.py
+++ b/test/Builder/multi/different-overrides.py
@@ -36,9 +36,10 @@ test = TestSCons.TestSCons(match=TestSCons.match_re)
test.write('SConstruct', """\
DefaultEnvironment(tools=[])
def build(env, target, source):
- file = open(str(target[0]), 'wb')
- for s in source:
- file.write(open(str(s), 'rb').read())
+ with open(str(target[0]), 'wb') as f:
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ f.write(infp.read())
B = Builder(action=build, multi=1)
env = Environment(tools=[], BUILDERS = { 'B' : B })
diff --git a/test/Builder/multi/different-target-lists.py b/test/Builder/multi/different-target-lists.py
index 437311f..4b6c49e 100644
--- a/test/Builder/multi/different-target-lists.py
+++ b/test/Builder/multi/different-target-lists.py
@@ -43,9 +43,10 @@ test.write('SConstruct', """\
DefaultEnvironment(tools=[])
def build(env, target, source):
for t in target:
- file = open(str(target[0]), 'wb')
- for s in source:
- file.write(open(str(s), 'rb').read())
+ with open(str(target[0]), 'wb') as f:
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ f.write(infp.read())
B = Builder(action=build, multi=1)
env = Environment(tools=[], BUILDERS = { 'B' : B })
diff --git a/test/Builder/multi/error.py b/test/Builder/multi/error.py
index 2de23d3..3b2a8d4 100644
--- a/test/Builder/multi/error.py
+++ b/test/Builder/multi/error.py
@@ -37,9 +37,10 @@ test.write('SConstruct', """\
DefaultEnvironment(tools=[])
def build(env, target, source):
- file = open(str(target[0]), 'wb')
- for s in source:
- file.write(open(str(s), 'rb').read())
+ with open(str(target[0]), 'wb') as f:
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ f.write(infp.read())
B = Builder(action=build, multi=0)
env = Environment(tools=[], BUILDERS = { 'B' : B })
diff --git a/test/Builder/multi/lone-target-list.py b/test/Builder/multi/lone-target-list.py
index 7c02c4a..885d34a 100644
--- a/test/Builder/multi/lone-target-list.py
+++ b/test/Builder/multi/lone-target-list.py
@@ -37,9 +37,10 @@ DefaultEnvironment(tools=[])
def build(env, target, source):
for t in target:
- file = open(str(target[0]), 'wb')
- for s in source:
- file.write(open(str(s), 'rb').read())
+ with open(str(target[0]), 'wb') as f:
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ f.write(infp.read())
B = Builder(action=build, multi=1)
env = Environment(tools=[], BUILDERS = { 'B' : B })
diff --git a/test/Builder/multi/multi.py b/test/Builder/multi/multi.py
index 0f83d71..aec0951 100644
--- a/test/Builder/multi/multi.py
+++ b/test/Builder/multi/multi.py
@@ -37,9 +37,10 @@ test.write('SConstruct', """\
DefaultEnvironment(tools=[])
def build(env, target, source):
- file = open(str(target[0]), 'wb')
- for s in source:
- file.write(open(str(s), 'rb').read())
+ with open(str(target[0]), 'wb') as f:
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ f.write(infp.read())
B = Builder(action=build, multi=1)
env = Environment(tools=[], BUILDERS = { 'B' : B })
diff --git a/test/Builder/multi/same-actions.py b/test/Builder/multi/same-actions.py
index 0b75566..f2a8fe3 100644
--- a/test/Builder/multi/same-actions.py
+++ b/test/Builder/multi/same-actions.py
@@ -37,9 +37,10 @@ test.write('SConstruct', """\
DefaultEnvironment(tools=[])
def build(env, target, source):
- file = open(str(target[0]), 'wb')
- for s in source:
- file.write(open(str(s), 'rb').read())
+ with open(str(target[0]), 'wb') as f:
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ f.write(infp.read())
B = Builder(action=build, multi=1)
env = Environment(tools=[], BUILDERS = { 'B' : B })
diff --git a/test/Builder/multi/same-overrides.py b/test/Builder/multi/same-overrides.py
index c4c1893..c545329 100644
--- a/test/Builder/multi/same-overrides.py
+++ b/test/Builder/multi/same-overrides.py
@@ -37,11 +37,12 @@ _python_ = TestSCons._python_
test.write('build.py', r"""\
import sys
def build(num, target, source):
- file = open(str(target), 'wb')
- file.write(bytearray('%s\n'% num,'utf-8'))
- for s in source:
- file.write(open(str(s), 'rb').read())
-build(sys.argv[1],sys.argv[2],sys.argv[3:])
+ with open(str(target), 'wb') as f:
+ f.write(bytearray('%s\n'% num,'utf-8'))
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ f.write(infp.read())
+build(sys.argv[1], sys.argv[2], sys.argv[3:])
""")
test.write('SConstruct', """\
diff --git a/test/Builder/multi/same-targets.py b/test/Builder/multi/same-targets.py
index c800a1c..17f6f99 100644
--- a/test/Builder/multi/same-targets.py
+++ b/test/Builder/multi/same-targets.py
@@ -38,9 +38,10 @@ DefaultEnvironment(tools=[])
def build(env, target, source):
for t in target:
- file = open(str(t), 'wb')
- for s in source:
- file.write(open(str(s), 'rb').read())
+ with open(str(t), 'wb') as f:
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ f.write(infp.read())
B = Builder(action=build, multi=1)
env = Environment(tools=[], BUILDERS = { 'B' : B })
diff --git a/test/Builder/non-multi.py b/test/Builder/non-multi.py
index 0ddb038..3c09db1 100644
--- a/test/Builder/non-multi.py
+++ b/test/Builder/non-multi.py
@@ -37,9 +37,10 @@ test.write('SConstruct', """
DefaultEnvironment(tools=[])
def build(env, target, source):
- file = open(str(target[0]), 'wb')
- for s in source:
- file.write(open(str(s), 'rb').read())
+ with open(str(target[0]), 'wb') as f:
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ f.write(infp.read())
B = Builder(action=build, multi=0)
env = Environment(tools=[], BUILDERS = { 'B' : B })
diff --git a/test/Builder/same-actions-diff-envs.py b/test/Builder/same-actions-diff-envs.py
index 289ee09..b80c988 100644
--- a/test/Builder/same-actions-diff-envs.py
+++ b/test/Builder/same-actions-diff-envs.py
@@ -37,8 +37,8 @@ test.write('SConstruct', """\
DefaultEnvironment(tools=[])
def build(env, target, source):
- file = open(str(target[0]), 'w')
- file.write('1')
+ with open(str(target[0]), 'w') as f:
+ f.write('1')
B = Builder(action=build)
env = Environment(tools=[], BUILDERS = { 'B' : B })
diff --git a/test/Builder/same-actions-diff-overrides.py b/test/Builder/same-actions-diff-overrides.py
index 2b7cefe..8f6bdca 100644
--- a/test/Builder/same-actions-diff-overrides.py
+++ b/test/Builder/same-actions-diff-overrides.py
@@ -37,8 +37,8 @@ test.write('SConstruct', """\
DefaultEnvironment(tools=[])
def build(env, target, source):
- file = open(str(target[0]), 'w')
- file.write('1')
+ with open(str(target[0]), 'w') as f:
+ f.write('1')
B = Builder(action=build)
env = Environment(tools=[], BUILDERS = { 'B' : B })
diff --git a/test/Builder/srcdir.py b/test/Builder/srcdir.py
index d7a9e18..6ce27fe 100644
--- a/test/Builder/srcdir.py
+++ b/test/Builder/srcdir.py
@@ -41,10 +41,10 @@ file3 = test.workpath('file3')
test.write(['src', 'cat.py'], """\
import sys
-o = open(sys.argv[1], 'wb')
-for f in sys.argv[2:]:
- o.write(open(f, 'rb').read())
-o.close()
+with open(sys.argv[1], 'wb') as o:
+ for f in sys.argv[2:]:
+ with open(f, 'rb') as i:
+ o.write(i.read())
""")
test.write(['src', 'SConstruct'], """\
diff --git a/test/Builder/wrapper.py b/test/Builder/wrapper.py
index 3ee9f79..acb1d44 100644
--- a/test/Builder/wrapper.py
+++ b/test/Builder/wrapper.py
@@ -39,9 +39,10 @@ DefaultEnvironment(tools=[])
import os.path
import string
def cat(target, source, env):
- fp = open(str(target[0]), 'wb')
- for s in map(str, source):
- fp.write(open(s, 'rb').read())
+ with open(str(target[0]), 'wb') as fp:
+ for s in map(str, source):
+ with open(s, 'rb') as infp:
+ fp.write(infp.read())
Cat = Builder(action=cat)
def Wrapper(env, target, source):
if not target:
diff --git a/test/CFILESUFFIX.py b/test/CFILESUFFIX.py
index 410ece5..7af4fa4 100644
--- a/test/CFILESUFFIX.py
+++ b/test/CFILESUFFIX.py
@@ -45,7 +45,8 @@ else:
longopts = []
cmd_opts, args = getopt.getopt(sys.argv[1:], 't', longopts)
for a in args:
- contents = open(a, 'rb').read()
+ with open(a, 'rb') as f:
+ contents = f.read()
sys.stdout.write((contents.replace(b'LEX', b'mylex.py')).decode())
sys.exit(0)
""")
diff --git a/test/CPPFLAGS.py b/test/CPPFLAGS.py
index e132876..4c656a1 100644
--- a/test/CPPFLAGS.py
+++ b/test/CPPFLAGS.py
@@ -51,11 +51,10 @@ while args:
break
args.pop(0)
if a[:5] == '/OUT:': out = a[5:]
-infile = open(args[0], 'r')
-outfile = open(out, 'w')
-for l in infile.readlines():
- if l[:5] != '#link':
- outfile.write(l)
+with open(out, 'w') as ofp, open(args[0], 'r') as ifp:
+ for l in ifp.readlines():
+ if l[:5] != '#link':
+ ofp.write(l)
sys.exit(0)
""")
@@ -67,12 +66,12 @@ import sys
opts, args = getopt.getopt(sys.argv[1:], 'o:s:')
for opt, arg in opts:
if opt == '-o': out = arg
-outfile = open(out, 'w')
-for f in args:
- infile = open(f, 'r')
- for l in infile.readlines():
- if l[:5] != '#link':
- outfile.write(l)
+with open(out, 'w') as ofp:
+ for f in args:
+ with open(f, 'r') as ifp:
+ for l in ifp.readlines():
+ if l[:5] != '#link':
+ ofp.write(l)
sys.exit(0)
""")
@@ -85,12 +84,13 @@ clen = len(compiler) + 1
opts, args = getopt.getopt(sys.argv[2:], 'co:xf:K:')
for opt, arg in opts:
if opt == '-o': out = arg
- elif opt == '-x': open('mygcc.out', 'a').write(compiler + "\n")
-infile = open(args[0], 'r')
-outfile = open(out, 'w')
-for l in infile.readlines():
- if l[:clen] != '#' + compiler:
- outfile.write(l)
+ elif opt == '-x':
+ with open('mygcc.out', 'a') as f:
+ f.write(compiler + "\n")
+with open(out, 'w') as ofp, open(args[0], 'r') as ifp:
+ for l in ifp.readlines():
+ if l[:clen] != '#' + compiler:
+ ofp.write(l)
sys.exit(0)
""")
diff --git a/test/CPPSUFFIXES.py b/test/CPPSUFFIXES.py
index 141df29..9b8dd90 100644
--- a/test/CPPSUFFIXES.py
+++ b/test/CPPSUFFIXES.py
@@ -37,14 +37,15 @@ test = TestSCons.TestSCons()
test.write('mycc.py', r"""
import sys
def do_file(outf, inf):
- for line in open(inf, 'r').readlines():
- if line[:10] == '#include <':
- do_file(outf, line[10:-2])
- else:
- outf.write(line)
-outf = open(sys.argv[1], 'w')
-for f in sys.argv[2:]:
- do_file(outf, f)
+ with open(inf, 'r') as ifp:
+ for line in ifp.readlines():
+ if line[:10] == '#include <':
+ do_file(outf, line[10:-2])
+ else:
+ outf.write(line)
+with open(sys.argv[1], 'w') as outf:
+ for f in sys.argv[2:]:
+ do_file(outf, f)
sys.exit(0)
""")
diff --git a/test/CXX/CXXFILESUFFIX.py b/test/CXX/CXXFILESUFFIX.py
index c8dbf0a..48d727e 100644
--- a/test/CXX/CXXFILESUFFIX.py
+++ b/test/CXX/CXXFILESUFFIX.py
@@ -41,7 +41,8 @@ else:
longopts = []
cmd_opts, args = getopt.getopt(sys.argv[1:], 't', longopts)
for a in args:
- contents = open(a, 'r').read()
+ with open(a, 'r') as f:
+ contents = f.read()
sys.stdout.write(contents.replace('LEX', 'mylex.py'))
sys.exit(0)
""")
diff --git a/test/Chmod.py b/test/Chmod.py
index 316800b..64f4ed9 100644
--- a/test/Chmod.py
+++ b/test/Chmod.py
@@ -45,10 +45,10 @@ Execute(Chmod('d2', 0o777))
Execute(Chmod(Dir('d2-Dir'), 0o777))
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as f:
+ for src in source:
+ with open(str(src), "rb") as infp:
+ f.write(infp.read())
Cat = Action(cat)
env = Environment()
env.Command('bar.out', 'bar.in', [Cat,
diff --git a/test/Clean/Option.py b/test/Clean/Option.py
index f49c226..5795ff2 100644
--- a/test/Clean/Option.py
+++ b/test/Clean/Option.py
@@ -39,10 +39,8 @@ test = TestSCons.TestSCons()
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as ofp, open(sys.argv[2], 'rb') as ifp:
+ ofp.write(ifp.read())
""")
test.write('SConstruct', """
diff --git a/test/Clean/basic.py b/test/Clean/basic.py
index e9f0540..fbff9b1 100644
--- a/test/Clean/basic.py
+++ b/test/Clean/basic.py
@@ -38,10 +38,8 @@ test = TestSCons.TestSCons()
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as ofp, open(sys.argv[2], 'rb') as ifp:
+ ofp.write(ifp.read())
""")
test.write('SConstruct', """
diff --git a/test/Clean/function.py b/test/Clean/function.py
index 7ddf727..45c9753 100644
--- a/test/Clean/function.py
+++ b/test/Clean/function.py
@@ -38,10 +38,8 @@ test = TestSCons.TestSCons()
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as ofp, open(sys.argv[2], 'rb') as ifp:
+ ofp.write(ifp.read())
""")
test.subdir('subd')
diff --git a/test/Climb/U-Default-no-target.py b/test/Climb/U-Default-no-target.py
index ca03416..62f1067 100644
--- a/test/Climb/U-Default-no-target.py
+++ b/test/Climb/U-Default-no-target.py
@@ -37,8 +37,8 @@ test.write('SConstruct', """
Default('not_a_target.in')
""")
-test.run(arguments = '-U', status=2, match=TestSCons.match_re, stderr="""\
-scons: \*\*\* Do not know how to make File target `not_a_target.in' \(.*not_a_target.in\). Stop.
+test.run(arguments = '-U', status=2, match=TestSCons.match_re, stderr=\
+r"""scons: \*\*\* Do not know how to make File target `not_a_target.in' \(.*not_a_target.in\). Stop.
""")
test.pass_test()
diff --git a/test/Climb/explicit-parent--D.py b/test/Climb/explicit-parent--D.py
index 6f669c3..a1c3aee 100644
--- a/test/Climb/explicit-parent--D.py
+++ b/test/Climb/explicit-parent--D.py
@@ -39,10 +39,10 @@ test.write('SConstruct', """\
DefaultEnvironment(tools=[])
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, 'wb') as ofp:
+ for src in source:
+ with open(str(src), 'rb') as ifp:
+ ofp.write(ifp.read())
env = Environment(tools=[], BUILDERS={'Cat':Builder(action=cat)})
env.Cat('f1.out', 'f1.in')
f2 = env.Cat('f2.out', 'f2.in')
diff --git a/test/Climb/explicit-parent--U.py b/test/Climb/explicit-parent--U.py
index ab2d33e..5308632 100644
--- a/test/Climb/explicit-parent--U.py
+++ b/test/Climb/explicit-parent--U.py
@@ -38,10 +38,10 @@ test.subdir('subdir')
test.write('SConstruct', """\
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, 'wb') as ofp:
+ for src in source:
+ with open(str(src), 'rb') as ifp:
+ ofp.write(ifp.read())
env = Environment(BUILDERS={'Cat':Builder(action=cat)})
env.Cat('foo.out', 'foo.in')
SConscript('subdir/SConscript', "env")
diff --git a/test/Climb/explicit-parent-u.py b/test/Climb/explicit-parent-u.py
index e3e774e..7210444 100644
--- a/test/Climb/explicit-parent-u.py
+++ b/test/Climb/explicit-parent-u.py
@@ -39,10 +39,10 @@ test.subdir('subdir')
test.write('SConstruct', """\
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, 'wb') as ofp:
+ for src in source:
+ with open(str(src), 'rb') as ifp:
+ ofp.write(ifp.read())
env = Environment(BUILDERS={'Cat':Builder(action=cat)})
env.Cat('f1.out', 'f1.in')
env.Cat('f2.out', 'f2.in')
diff --git a/test/Climb/option--D.py b/test/Climb/option--D.py
index 42b92d8..06c5fa8 100644
--- a/test/Climb/option--D.py
+++ b/test/Climb/option--D.py
@@ -34,10 +34,8 @@ test.subdir('sub1', 'sub2')
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as ofp, open(sys.argv[2], 'rb') as ifp:
+ ofp.write(ifp.read())
""")
test.write('SConstruct', """
diff --git a/test/Climb/option--U.py b/test/Climb/option--U.py
index c0e6e1e..137bb26 100644
--- a/test/Climb/option--U.py
+++ b/test/Climb/option--U.py
@@ -36,10 +36,8 @@ test.subdir('sub1', 'sub2', 'sub3')
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as ofp, open(sys.argv[2], 'rb') as ifp:
+ ofp.write(ifp.read())
""")
test.write('SConstruct', r"""
diff --git a/test/Climb/option-u.py b/test/Climb/option-u.py
index 21e83cf..49874f9 100644
--- a/test/Climb/option-u.py
+++ b/test/Climb/option-u.py
@@ -44,10 +44,10 @@ test.write('SConstruct', """
DefaultEnvironment(tools=[])
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, 'wb') as ofp:
+ for src in source:
+ with open(str(src), 'rb') as ifp:
+ ofp.write(ifp.read())
env = Environment(tools=[])
env.Append(BUILDERS = {'Cat' : Builder(action=cat)})
env.Cat(target = 'sub1/f1a.out', source = 'sub1/f1a.in')
diff --git a/test/Command.py b/test/Command.py
index c36fb33..09a8daa 100644
--- a/test/Command.py
+++ b/test/Command.py
@@ -36,10 +36,8 @@ test.subdir('sub')
build_py = r"""
import sys
-contents = open(sys.argv[2], 'r').read()
-file = open(sys.argv[1], 'w')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'w') as f, open(sys.argv[2], 'r') as infp:
+ f.write(infp.read())
"""
test.write('build.py', build_py)
test.write(['expand_chdir_sub', 'subbuild.py'], build_py)
@@ -48,22 +46,20 @@ test.write('SConstruct', """
import os
def buildIt(env, target, source):
- contents = open(str(source[0]), 'r').read()
- file = open(str(target[0]), 'w')
- xyzzy = env.get('XYZZY', '')
- if xyzzy:
- file.write(xyzzy + '\\n')
- file.write(contents)
- file.close()
+ with open(str(target[0]), 'w') as f, open(str(source[0]), 'r') as infp:
+ xyzzy = env.get('XYZZY', '')
+ if xyzzy:
+ f.write(xyzzy + '\\n')
+ f.write(infp.read())
return 0
def sub(env, target, source):
target = str(target[0])
source = str(source[0])
- t = open(target, 'w')
- for f in sorted(os.listdir(source)):
- t.write(open(os.path.join(source, f), 'r').read())
- t.close()
+ with open(target, 'w') as t:
+ for f in sorted(os.listdir(source)):
+ with open(os.path.join(source, f), 'r') as s:
+ t.write(s.read())
return 0
env = Environment(COPY_THROUGH_TEMP = r'%(_python_)s build.py .tmp $SOURCE' + '\\n' + r'%(_python_)s build.py $TARGET .tmp',
diff --git a/test/CommandGenerator.py b/test/CommandGenerator.py
index a3a995b..b8155e7 100644
--- a/test/CommandGenerator.py
+++ b/test/CommandGenerator.py
@@ -34,10 +34,8 @@ test = TestSCons.TestSCons()
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'r').read()
-file = open(sys.argv[1], 'w')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'w') as f, open(sys.argv[2], 'r') as ifp:
+ f.write(ifp.read())
sys.exit(0)
""")
diff --git a/test/Configure/Builder-call.py b/test/Configure/Builder-call.py
index b85b039..b4c9d33 100644
--- a/test/Configure/Builder-call.py
+++ b/test/Configure/Builder-call.py
@@ -39,7 +39,8 @@ test.write('mycommand.py', r"""
import sys
sys.stderr.write( 'Hello World on stderr\n' )
sys.stdout.write( 'Hello World on stdout\n' )
-open(sys.argv[1], 'w').write( 'Hello World\n' )
+with open(sys.argv[1], 'w') as f:
+ f.write( 'Hello World\n' )
""")
test.write('SConstruct', """\
diff --git a/test/Configure/VariantDir.py b/test/Configure/VariantDir.py
index 23a4b14..2c54b84 100644
--- a/test/Configure/VariantDir.py
+++ b/test/Configure/VariantDir.py
@@ -45,26 +45,27 @@ test.write('SConstruct', """\
env = Environment(LOGFILE='build/config.log')
import os
env.AppendENVPath('PATH', os.environ['PATH'])
-VariantDir( 'build', '.' )
+VariantDir('build', '.')
conf = env.Configure(conf_dir='build/config.tests', log_file='$LOGFILE')
-r1 = conf.CheckCHeader( 'math.h' )
-r2 = conf.CheckCHeader( 'no_std_c_header.h' ) # leads to compile error
+r1 = conf.CheckCHeader('math.h')
+r2 = conf.CheckCHeader('no_std_c_header.h') # leads to compile error
env = conf.Finish()
-Export( 'env' )
-# print open( 'build/config.log' ).readlines()
-SConscript( 'build/SConscript' )
+Export('env')
+# with open('build/config.log') as f:
+# print f.readlines()
+SConscript('build/SConscript')
""")
test.write('SConscript', """\
-Import( 'env' )
-env.Program( 'TestProgram', 'TestProgram.c' )
+Import('env')
+env.Program('TestProgram', 'TestProgram.c')
""")
test.write('TestProgram.c', """\
#include <stdio.h>
int main(void) {
- printf( "Hello\\n" );
+ printf("Hello\\n");
}
""")
diff --git a/test/Configure/custom-tests.py b/test/Configure/custom-tests.py
index 6362e25..1c6eac8 100644
--- a/test/Configure/custom-tests.py
+++ b/test/Configure/custom-tests.py
@@ -170,7 +170,7 @@ env = conf.Finish()
test.run()
test.must_match('config.log',
-""".*
+r""".*
.*
scons: Configure: Display of list ...
scons: Configure: \(cached\) yes
diff --git a/test/Copy-Action.py b/test/Copy-Action.py
index 6003aa9..4bfa0da 100644
--- a/test/Copy-Action.py
+++ b/test/Copy-Action.py
@@ -43,10 +43,10 @@ Execute(Copy(File('d2.out'), 'd2.in'))
Execute(Copy('d3.out', File('f3.in')))
def cat(env, source, target):
target = str(target[0])
- f = open(target, "w")
- for src in source:
- f.write(open(str(src), "r").read())
- f.close()
+ with open(target, "w") as f:
+ for src in source:
+ with open(str(src), "r") as ifp:
+ f.write(ifp.read())
Cat = Action(cat)
env = Environment()
env.Command('bar.out', 'bar.in', [Cat,
diff --git a/test/D/AllAtOnce/Common/common.py b/test/D/AllAtOnce/Common/common.py
index 1713028..0d87213 100644
--- a/test/D/AllAtOnce/Common/common.py
+++ b/test/D/AllAtOnce/Common/common.py
@@ -44,7 +44,9 @@ def testForTool(tool):
test.skip_test("Required executable for tool '{0}' not found, skipping test.\n".format(tool))
test.dir_fixture('Image')
- test.write('SConstruct', open('SConstruct_template', 'r').read().format(tool))
+ with open('SConstruct_template', 'r') as f:
+ config = f.read().format(tool)
+ test.write('SConstruct', config)
test.run()
diff --git a/test/D/CoreScanner/Common/common.py b/test/D/CoreScanner/Common/common.py
index 1d2fde0..d6a6280 100644
--- a/test/D/CoreScanner/Common/common.py
+++ b/test/D/CoreScanner/Common/common.py
@@ -47,7 +47,9 @@ def testForTool(tool):
test.skip_test("Required executable for tool '{0}' not found, skipping test.\n".format(tool))
test.dir_fixture('Image')
- test.write('SConstruct', open('SConstruct_template', 'r').read().format(tool))
+ with open('SConstruct_template', 'r') as f:
+ config = f.read().format(tool)
+ test.write('SConstruct', config)
arguments = 'test1%(_obj)s test2%(_obj)s' % locals()
diff --git a/test/D/HSTeoh/Common/arLibIssue.py b/test/D/HSTeoh/Common/arLibIssue.py
index 9bca3d8..6ea8caf 100644
--- a/test/D/HSTeoh/Common/arLibIssue.py
+++ b/test/D/HSTeoh/Common/arLibIssue.py
@@ -46,7 +46,9 @@ def testForTool(tool):
test.skip_test("Required executable for tool '{0}' not found, skipping test.\n".format(tool))
test.dir_fixture('ArLibIssue')
- test.write('SConstruct', open('SConstruct_template', 'r').read().format('tools=["{0}", "ar"]'.format(tool)))
+ with open('SConstruct_template', 'r') as f:
+ config = f.read().format('tools=["{0}", "ar"]'.format(tool))
+ test.write('SConstruct', config)
test.run()
diff --git a/test/D/HSTeoh/Common/libCompileOptions.py b/test/D/HSTeoh/Common/libCompileOptions.py
index 4a21c45..94616ae 100644
--- a/test/D/HSTeoh/Common/libCompileOptions.py
+++ b/test/D/HSTeoh/Common/libCompileOptions.py
@@ -46,7 +46,9 @@ def testForTool(tool):
test.skip_test("Required executable for tool '{0}' not found, skipping test.\n".format(tool))
test.dir_fixture('LibCompileOptions')
- test.write('SConstruct', open('SConstruct_template', 'r').read().format('tools=["{0}", "link", "ar"]'.format(tool)))
+ with open('SConstruct_template', 'r') as f:
+ config = f.read().format('tools=["{0}", "link", "ar"]'.format(tool))
+ test.write('SConstruct', config)
test.run()
diff --git a/test/D/HSTeoh/Common/linkingProblem.py b/test/D/HSTeoh/Common/linkingProblem.py
index b526ad7..0669695 100644
--- a/test/D/HSTeoh/Common/linkingProblem.py
+++ b/test/D/HSTeoh/Common/linkingProblem.py
@@ -47,7 +47,9 @@ def testForTool(tool):
test.skip_test("ncurses not apparently installed, skip this test.")
test.dir_fixture('LinkingProblem')
- test.write('SConstruct', open('SConstruct_template', 'r').read().format(tool))
+ with open('SConstruct_template', 'r') as f:
+ config = f.read().format(tool)
+ test.write('SConstruct', config)
test.run()
diff --git a/test/D/HSTeoh/Common/singleStringCannotBeMultipleOptions.py b/test/D/HSTeoh/Common/singleStringCannotBeMultipleOptions.py
index 4716f1c..2632f87 100644
--- a/test/D/HSTeoh/Common/singleStringCannotBeMultipleOptions.py
+++ b/test/D/HSTeoh/Common/singleStringCannotBeMultipleOptions.py
@@ -45,7 +45,9 @@ def testForTool(tool):
test.skip_test("Required executable for tool '{0}' not found, skipping test.\n".format(tool))
test.dir_fixture('SingleStringCannotBeMultipleOptions')
- test.write('SConstruct', open('SConstruct_template', 'r').read().format(tool))
+ with open('SConstruct_template', 'r') as f:
+ config = f.read().format(tool)
+ test.write('SConstruct', config)
test.run(status=2, stdout=None, stderr=None)
diff --git a/test/D/HelloWorld/CompileAndLinkOneStep/Common/common.py b/test/D/HelloWorld/CompileAndLinkOneStep/Common/common.py
index e757d47..675091c 100644
--- a/test/D/HelloWorld/CompileAndLinkOneStep/Common/common.py
+++ b/test/D/HelloWorld/CompileAndLinkOneStep/Common/common.py
@@ -44,7 +44,9 @@ def testForTool(tool):
test.skip_test("Required executable for tool '{0}' not found, skipping test.\n".format(tool))
test.dir_fixture('Image')
- test.write('SConstruct', open('SConstruct_template', 'r').read().format(tool))
+ with open('SConstruct_template', 'r') as f:
+ config = f.read().format(tool)
+ test.write('SConstruct', config)
if tool == 'dmd':
# The gdmd executable in Debian Unstable as at 2012-05-12, version 4.6.3 puts out messages on stderr
diff --git a/test/D/HelloWorld/CompileThenLinkTwoSteps/Common/common.py b/test/D/HelloWorld/CompileThenLinkTwoSteps/Common/common.py
index e757d47..675091c 100644
--- a/test/D/HelloWorld/CompileThenLinkTwoSteps/Common/common.py
+++ b/test/D/HelloWorld/CompileThenLinkTwoSteps/Common/common.py
@@ -44,7 +44,9 @@ def testForTool(tool):
test.skip_test("Required executable for tool '{0}' not found, skipping test.\n".format(tool))
test.dir_fixture('Image')
- test.write('SConstruct', open('SConstruct_template', 'r').read().format(tool))
+ with open('SConstruct_template', 'r') as f:
+ config = f.read().format(tool)
+ test.write('SConstruct', config)
if tool == 'dmd':
# The gdmd executable in Debian Unstable as at 2012-05-12, version 4.6.3 puts out messages on stderr
diff --git a/test/D/Issues/2939_Ariovistus/Common/correctLinkOptions.py b/test/D/Issues/2939_Ariovistus/Common/correctLinkOptions.py
index 1b42580..b2acb43 100644
--- a/test/D/Issues/2939_Ariovistus/Common/correctLinkOptions.py
+++ b/test/D/Issues/2939_Ariovistus/Common/correctLinkOptions.py
@@ -46,7 +46,9 @@ def testForTool(tool):
test.skip_test("Required executable for tool '{0}' not found, skipping test.\n".format(tool))
test.dir_fixture('Project')
- test.write('SConstruct', open('SConstruct_template', 'r').read().format('tools=["{0}", "link"]'.format(tool)))
+ with open('SConstruct_template', 'r') as f:
+ config = f.read().format('tools=["{0}", "link"]'.format(tool))
+ test.write('SConstruct', config)
test.run()
diff --git a/test/D/Issues/2940_Ariovistus/Common/correctLinkOptions.py b/test/D/Issues/2940_Ariovistus/Common/correctLinkOptions.py
index 5acd26a..19b96b9 100644
--- a/test/D/Issues/2940_Ariovistus/Common/correctLinkOptions.py
+++ b/test/D/Issues/2940_Ariovistus/Common/correctLinkOptions.py
@@ -61,7 +61,9 @@ def testForTool(tool):
test.fail_test('No information about platform: ' + platform)
test.dir_fixture('Project')
- test.write('SConstruct', open('SConstruct_template', 'r').read().format('tools=["{0}", "link"]'.format(tool)))
+ with open('SConstruct_template', 'r') as f:
+ config = f.read().format('tools=["{0}", "link"]'.format(tool))
+ test.write('SConstruct', config)
test.run()
diff --git a/test/D/Issues/2994/Common/D_changed_DFLAGS_not_rebuilding.py b/test/D/Issues/2994/Common/D_changed_DFLAGS_not_rebuilding.py
index 07b1366..b58227d 100644
--- a/test/D/Issues/2994/Common/D_changed_DFLAGS_not_rebuilding.py
+++ b/test/D/Issues/2994/Common/D_changed_DFLAGS_not_rebuilding.py
@@ -46,7 +46,9 @@ def testForTool(tool):
test.skip_test("Required executable for tool '{0}' not found, skipping test.\n".format(tool))
test.dir_fixture('Project')
- test.write('SConstruct', open('SConstruct_template', 'r').read().format('tools=["{0}", "link"]'.format(tool)))
+ with open('SConstruct_template', 'r') as f:
+ config = f.read().format('tools=["{0}", "link"]'.format(tool))
+ test.write('SConstruct', config)
test.run()
test.fail_test('main.o' not in test.stdout())
diff --git a/test/D/SharedObjects/Common/common.py b/test/D/SharedObjects/Common/common.py
index bae376d..5113cc4 100644
--- a/test/D/SharedObjects/Common/common.py
+++ b/test/D/SharedObjects/Common/common.py
@@ -76,7 +76,9 @@ def testForTool(tool):
test.fail_test()
test.dir_fixture('Image')
- test.write('SConstruct', open('SConstruct_template', 'r').read().format(tool))
+ with open('SConstruct_template', 'r') as f:
+ config = f.read().format(tool)
+ test.write('SConstruct', config)
if Base()['DC'] == 'gdmd':
# The gdmd executable in Debian Unstable as at 2012-05-12, version 4.6.3 puts out messages on stderr
diff --git a/test/DSUFFIXES.py b/test/DSUFFIXES.py
index 46bdf83..54a506c 100644
--- a/test/DSUFFIXES.py
+++ b/test/DSUFFIXES.py
@@ -37,14 +37,15 @@ test = TestSCons.TestSCons()
test.write('mydc.py', r"""
import sys
def do_file(outf, inf):
- for line in open(inf, 'rb').readlines():
- if line[:7] == b'import ':
- do_file(outf, line[7:-2] + b'.d')
- else:
- outf.write(line)
-outf = open(sys.argv[1], 'wb')
-for f in sys.argv[2:]:
- do_file(outf, f)
+ with open(inf, 'rb') as ifp:
+ for line in ifp.readlines():
+ if line[:7] == b'import ':
+ do_file(outf, line[7:-2] + b'.d')
+ else:
+ outf.write(line)
+with open(sys.argv[1], 'wb') as outf:
+ for f in sys.argv[2:]:
+ do_file(outf, f)
sys.exit(0)
""")
diff --git a/test/Decider/switch-rebuild.py b/test/Decider/switch-rebuild.py
index d2b288d..2926455 100644
--- a/test/Decider/switch-rebuild.py
+++ b/test/Decider/switch-rebuild.py
@@ -38,7 +38,8 @@ DefaultEnvironment(tools=[])
Decider('%s')
def build(env, target, source):
- open(str(target[0]), 'wt').write(open(str(source[0]), 'rt').read())
+ with open(str(target[0]), 'wt') as f, open(str(source[0]), 'rt') as ifp:
+ f.write(ifp.read())
B = Builder(action=build)
env = Environment(tools=[], BUILDERS = { 'B' : B })
env.B(target='switch.out', source='switch.in')
diff --git a/test/Default.py b/test/Default.py
index 05944a6..b9896f8 100644
--- a/test/Default.py
+++ b/test/Default.py
@@ -43,10 +43,8 @@ for dirname in ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight']:
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'r').read()
-file = open(sys.argv[1], 'w')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'w') as f, open(sys.argv[2], 'r') as ifp:
+ f.write(ifp.read())
""")
#
diff --git a/test/Delete.py b/test/Delete.py
index 94ba24a..fc4ab4f 100644
--- a/test/Delete.py
+++ b/test/Delete.py
@@ -44,10 +44,10 @@ Execute(Delete('symlinks/dirlink'))
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as ofp:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ ofp.write(ifp.read())
Cat = Action(cat)
env = Environment()
env.Command('f3.out', 'f3.in', [Cat, Delete("f4"), Delete("d5")])
@@ -194,10 +194,10 @@ if sys.platform != 'win32':
test.write("SConstruct", """\
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as ifp:
+ for src in source:
+ with open(str(src), "rb") as ofp:
+ ofp.write(ifp.read())
Cat = Action(cat)
env = Environment()
env.Command('f14-nonexistent.out', 'f14.in', [Delete("$TARGET", must_exist=1),
diff --git a/test/Depends/Depends.py b/test/Depends/Depends.py
index 054b9a1..3ed9e12 100644
--- a/test/Depends/Depends.py
+++ b/test/Depends/Depends.py
@@ -40,10 +40,10 @@ test.subdir('subdir', 'sub2')
test.write('build.py', r"""
import sys
-fp = open(sys.argv[1], 'wb')
-for fname in sys.argv[2:]:
- fp.write(open(fname, 'rb').read())
-fp.close()
+with open(sys.argv[1], 'wb') as ofp:
+ for fname in sys.argv[2:]:
+ with open(fname, 'rb') as ifp:
+ ofp.write(ifp.read())
sys.exit(0)
""")
diff --git a/test/Depends/spurious-rebuilds.py b/test/Depends/spurious-rebuilds.py
index 6afc829..f4ad040 100644
--- a/test/Depends/spurious-rebuilds.py
+++ b/test/Depends/spurious-rebuilds.py
@@ -47,7 +47,8 @@ import os.path
if not os.path.exists('mkl'):
os.mkdir('mkl')
if not os.path.exists('test.c'):
- open('test.c', 'w').write('int i;')
+ with open('test.c', 'w') as f:
+ f.write('int i;')
env=Environment()
env.SharedObject('all-defuns.obj', 'all-defuns.c')
diff --git a/test/Deprecated/BuildDir.py b/test/Deprecated/BuildDir.py
index b0d6610..1a1ba02 100644
--- a/test/Deprecated/BuildDir.py
+++ b/test/Deprecated/BuildDir.py
@@ -97,11 +97,8 @@ import os.path
def buildIt(target, source, env):
if not os.path.exists('build'):
os.mkdir('build')
- f1=open(str(source[0]), 'r')
- f2=open(str(target[0]), 'w')
- f2.write(f1.read())
- f2.close()
- f1.close()
+ with open(str(source[0]), 'r') as ifp, open(str(target[0]), 'w') as ofp:
+ ofp.write(ifp.read())
return 0
Import("env")
env.Command(target='f2.c', source='f2.in', action=buildIt)
diff --git a/test/Deprecated/SConscript-build_dir.py b/test/Deprecated/SConscript-build_dir.py
index c9ec07e..0d1ba6a 100644
--- a/test/Deprecated/SConscript-build_dir.py
+++ b/test/Deprecated/SConscript-build_dir.py
@@ -73,10 +73,10 @@ var9 = Dir('../build/var9')
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as ofp:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ ofp.write(ifp.read())
env = Environment(BUILDERS={'Cat':Builder(action=cat)},
BUILD='build')
diff --git a/test/Deprecated/SourceCode/SourceCode.py b/test/Deprecated/SourceCode/SourceCode.py
index b5c0ba9..b7f1305 100644
--- a/test/Deprecated/SourceCode/SourceCode.py
+++ b/test/Deprecated/SourceCode/SourceCode.py
@@ -49,10 +49,10 @@ import os
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as ofp:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ ofp.write(ifp.read())
def sc_cat(env, source, target):
source = []
diff --git a/test/Deprecated/SourceSignatures/basic.py b/test/Deprecated/SourceSignatures/basic.py
index 52a2c5c..7951dbd 100644
--- a/test/Deprecated/SourceSignatures/basic.py
+++ b/test/Deprecated/SourceSignatures/basic.py
@@ -35,7 +35,8 @@ test = TestSCons.TestSCons(match = TestSCons.match_re_dotall)
base_sconstruct_contents = """\
SetOption('warn', 'deprecated-source-signatures')
def build(env, target, source):
- open(str(target[0]), 'wt').write(open(str(source[0]), 'rt').read())
+ with open(str(target[0]), 'wt') as ofp, open(str(source[0]), 'rt') as ifp:
+ ofp.write(ifp.read())
B = Builder(action = build)
env = Environment(BUILDERS = { 'B' : B })
env.B(target = 'f1.out', source = 'f1.in')
diff --git a/test/Deprecated/SourceSignatures/env.py b/test/Deprecated/SourceSignatures/env.py
index bb76ff4..c63b176 100644
--- a/test/Deprecated/SourceSignatures/env.py
+++ b/test/Deprecated/SourceSignatures/env.py
@@ -39,7 +39,8 @@ test = TestSCons.TestSCons(match = TestSCons.match_re_dotall)
base_sconstruct_contents = """\
SetOption('warn', 'deprecated-source-signatures')
def build(env, target, source):
- open(str(target[0]), 'wt').write(open(str(source[0]), 'rt').read())
+ with open(str(target[0]), 'wt') as ofp, open(str(source[0]), 'rt') as ifp:
+ ofp.write(ifp.read())
B = Builder(action = build)
env = Environment(BUILDERS = { 'B' : B })
env2 = env.Clone()
diff --git a/test/Deprecated/SourceSignatures/implicit-cache.py b/test/Deprecated/SourceSignatures/implicit-cache.py
index af6aa49..a4bdc78 100644
--- a/test/Deprecated/SourceSignatures/implicit-cache.py
+++ b/test/Deprecated/SourceSignatures/implicit-cache.py
@@ -41,7 +41,8 @@ SetOption('implicit_cache', 1)
SourceSignatures('timestamp')
def build(env, target, source):
- open(str(target[0]), 'wt').write(open(str(source[0]), 'rt').read())
+ with open(str(target[0]), 'wt') as ofp, open(str(source[0]), 'rt') as ifp:
+ ofp.write(ifp.read())
B = Builder(action = build)
env = Environment(BUILDERS = { 'B' : B })
env.B(target = 'both.out', source = 'both.in')
diff --git a/test/Deprecated/SourceSignatures/no-csigs.py b/test/Deprecated/SourceSignatures/no-csigs.py
index f815538..c4f2a78 100644
--- a/test/Deprecated/SourceSignatures/no-csigs.py
+++ b/test/Deprecated/SourceSignatures/no-csigs.py
@@ -36,7 +36,8 @@ test = TestSConsign.TestSConsign(match = TestSConsign.match_re)
test.write('SConstruct', """\
SetOption('warn', 'deprecated-source-signatures')
def build(env, target, source):
- open(str(target[0]), 'wt').write(open(str(source[0]), 'rt').read())
+ with open(str(target[0]), 'wt') as ofp, open(str(source[0]), 'rt') as ifp:
+ ofp.write(ifp.read())
B = Builder(action = build)
env = Environment(BUILDERS = { 'B' : B })
env.B(target = 'f1.out', source = 'f1.in')
diff --git a/test/Deprecated/SourceSignatures/switch-rebuild.py b/test/Deprecated/SourceSignatures/switch-rebuild.py
index e8af27a..b9cc3d5 100644
--- a/test/Deprecated/SourceSignatures/switch-rebuild.py
+++ b/test/Deprecated/SourceSignatures/switch-rebuild.py
@@ -45,7 +45,8 @@ SetOption('warn', 'deprecated-source-signatures')
SourceSignatures('%s')
def build(env, target, source):
- open(str(target[0]), 'wt').write(open(str(source[0]), 'rt').read())
+ with open(str(target[0]), 'wt') as ofp, open(str(source[0]), 'rt') as ifp:
+ ofp.write(ifp.read())
B = Builder(action = build)
env = Environment(BUILDERS = { 'B' : B })
env.B(target = 'switch.out', source = 'switch.in')
diff --git a/test/Deprecated/TargetSignatures/content.py b/test/Deprecated/TargetSignatures/content.py
index 2cd90ec..aca63f3 100644
--- a/test/Deprecated/TargetSignatures/content.py
+++ b/test/Deprecated/TargetSignatures/content.py
@@ -48,10 +48,10 @@ SetOption('warn', 'deprecated-target-signatures')
env = Environment()
def copy(env, source, target):
- fp = open(str(target[0]), 'wb')
- for s in source:
- fp.write(open(str(s), 'rb').read())
- fp.close()
+ with open(str(target[0]), 'wb') as ofp:
+ for s in source:
+ with open(str(s), 'rb') as ifp:
+ ofp.write(ifp.read())
copyAction = Action(copy, "Copying $TARGET")
diff --git a/test/Deprecated/debug-nomemoizer.py b/test/Deprecated/debug-nomemoizer.py
index c533efa..6d05cb2 100644
--- a/test/Deprecated/debug-nomemoizer.py
+++ b/test/Deprecated/debug-nomemoizer.py
@@ -34,7 +34,8 @@ test = TestSCons.TestSCons(match = TestSCons.match_re)
test.write('SConstruct', """
def cat(target, source, env):
- open(str(target[0]), 'wb').write(open(str(source[0]), 'rb').read())
+ with open(str(target[0]), 'wb') as ofp, open(str(source[0]), 'rb') as ifp:
+ ofp.write(ifp.read())
env = Environment(BUILDERS={'Cat':Builder(action=Action(cat))})
env.Cat('file.out', 'file.in')
""")
diff --git a/test/ENV.py b/test/ENV.py
index 36ad844..0866cf5 100644
--- a/test/ENV.py
+++ b/test/ENV.py
@@ -49,8 +49,10 @@ test.write('build.py',
r"""\
import os
import sys
-contents = open(sys.argv[2], 'r').read()
-open(sys.argv[1], 'w').write("build.py %s\n%s" % (os.environ['X'], contents))
+with open(sys.argv[2], 'r') as f:
+ contents = f.read()
+with open(sys.argv[1], 'w') as f:
+ f.write("build.py %s\n%s" % (os.environ['X'], contents))
""")
test.write('input', "input file\n")
diff --git a/test/ESCAPE.py b/test/ESCAPE.py
index 819d60b..853ab57 100644
--- a/test/ESCAPE.py
+++ b/test/ESCAPE.py
@@ -36,10 +36,10 @@ test = TestSCons.TestSCons()
test.write('cat.py', """\
import sys
-ofp = open(sys.argv[1], 'wb')
-for s in sys.argv[2:]:
- ofp.write(open(s, 'rb').read())
-ofp.close()
+with open(sys.argv[1], 'wb') as ofp:
+ for s in sys.argv[2:]:
+ with open(s, 'rb') as ifp:
+ ofp.write(ifp.read())
""")
test.write('SConstruct', """\
diff --git a/test/Errors/AttributeError.py b/test/Errors/AttributeError.py
index c666a2d..09e0d4b 100644
--- a/test/Errors/AttributeError.py
+++ b/test/Errors/AttributeError.py
@@ -39,9 +39,9 @@ a.append(2)
""")
test.run(status = 2, stderr = """\
-(AttributeError|<type 'exceptions\.AttributeError'>): 'int' object has no attribute 'append':
+(AttributeError|<type 'exceptions\\.AttributeError'>): 'int' object has no attribute 'append':
File ".+SConstruct", line 2:
- a.append\(2\)
+ a.append\\(2\\)
""")
test.pass_test()
diff --git a/test/Errors/Exception.py b/test/Errors/Exception.py
index 30404fc..c08a09e 100644
--- a/test/Errors/Exception.py
+++ b/test/Errors/Exception.py
@@ -31,7 +31,8 @@ test = TestSCons.TestSCons(match = TestSCons.match_re_dotall)
test.write('SConstruct', """\
def foo(env, target, source):
print(str(target[0]))
- open(str(target[0]), 'wt').write('foo')
+ with open(str(target[0]), 'wt') as f:
+ f.write('foo')
def exit(env, target, source):
raise Exception('exit')
@@ -51,7 +52,7 @@ test.write('exit.in', 'exit\n')
# no longer exists or that line in the source file no longer exists,
# so make sure the proper variations are supported in the following
# regexp.
-expect = """scons: \*\*\* \[exit.out\] Exception : exit
+expect = r"""scons: \*\*\* \[exit.out\] Exception : exit
Traceback \((most recent call|innermost) last\):
( File ".+", line \d+, in \S+
[^\n]+
diff --git a/test/Errors/SyntaxError.py b/test/Errors/SyntaxError.py
index e6b8e4d..2cdebea 100644
--- a/test/Errors/SyntaxError.py
+++ b/test/Errors/SyntaxError.py
@@ -42,7 +42,7 @@ test.run(stdout = "scons: Reading SConscript files ...\n",
a ! x
- \^
+ \\^
SyntaxError: (invalid syntax|Unknown character)
diff --git a/test/Errors/TypeError.py b/test/Errors/TypeError.py
index 286fa26..802d3df 100644
--- a/test/Errors/TypeError.py
+++ b/test/Errors/TypeError.py
@@ -41,7 +41,7 @@ a[2] = 3
test.run(status = 2, stderr = """\
TypeError:( 'int')? object does not support item assignment:
File ".+SConstruct", line 2:
- a\[2\] = 3
+ a\\[2\\] = 3
""")
test.pass_test()
diff --git a/test/Errors/UserError.py b/test/Errors/UserError.py
index 669260d..0906a45 100644
--- a/test/Errors/UserError.py
+++ b/test/Errors/UserError.py
@@ -39,7 +39,7 @@ import SCons.Errors
raise SCons.Errors.UserError('Depends() requires both sources and targets.')
""")
-expect = """
+expect = r"""
scons: \*\*\* Depends\(\) requires both sources and targets.
""" + TestSCons.file_expr
diff --git a/test/Execute.py b/test/Execute.py
index c40d0d0..9dcafac 100644
--- a/test/Execute.py
+++ b/test/Execute.py
@@ -36,7 +36,8 @@ test = TestSCons.TestSCons()
test.write('my_copy.py', """\
import sys
-open(sys.argv[2], 'wb').write(open(sys.argv[1], 'rb').read())
+with open(sys.argv[2], 'wb') as ofp, open(sys.argv[1], 'rb') as ifp:
+ ofp.write(ifp.read())
try:
exitval = int(sys.argv[3])
except IndexError:
diff --git a/test/Exit.py b/test/Exit.py
index 394ee2f..f00986d 100644
--- a/test/Exit.py
+++ b/test/Exit.py
@@ -104,10 +104,10 @@ SConscript('subdir/SConscript')
test.write(['subdir', 'SConscript'], """\
def exit_builder(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as f:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ f.write(ifp.read())
Exit(27)
env = Environment(BUILDERS = {'my_exit' : Builder(action=exit_builder)})
env.my_exit('foo.out', 'foo.in')
@@ -133,10 +133,10 @@ exitscan = Scanner(function = exit_scanner, skeys = ['.k'])
def cat(env, source, target):
target = str(target[0])
- outf = open(target, 'wb')
- for src in source:
- outf.write(open(str(src), "rb").read())
- outf.close()
+ with open(target, 'wb') as ofp:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ outf.write(ifp.read())
env = Environment(BUILDERS={'Cat':Builder(action=cat)})
env.Append(SCANNERS = [exitscan])
diff --git a/test/FindFile.py b/test/FindFile.py
index e878172..fa195c4 100644
--- a/test/FindFile.py
+++ b/test/FindFile.py
@@ -40,13 +40,17 @@ test.write(['bar', 'baz', 'testfile2'], 'test 4\n')
test.write('SConstruct', """
env = Environment(FILE = 'file', BAR = 'bar')
file1 = FindFile('testfile1', [ 'foo', '.', 'bar', 'bar/baz' ])
-print(open(str(file1), 'r').read())
+with open(str(file1), 'r') as f:
+ print(f.read())
file2 = env.FindFile('test${FILE}1', [ 'bar', 'foo', '.', 'bar/baz' ])
-print(open(str(file2), 'r').read())
+with open(str(file2), 'r') as f:
+ print(f.read())
file3 = FindFile('testfile2', [ 'foo', '.', 'bar', 'bar/baz' ])
-print(open(str(file3), 'r').read())
+with open(str(file3), 'r') as f:
+ print(f.read())
file4 = env.FindFile('testfile2', [ '$BAR/baz', 'foo', '.', 'bar' ])
-print(open(str(file4), 'r').read())
+with open(str(file4), 'r') as f:
+ print(f.read())
""")
expect = test.wrap_stdout(read_str = """test 1
diff --git a/test/Flatten.py b/test/Flatten.py
index fd9943d..40bbb3e 100644
--- a/test/Flatten.py
+++ b/test/Flatten.py
@@ -37,10 +37,10 @@ test.subdir('work')
test.write(['work', 'SConstruct'], """
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as ofp:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ ofp.write(ifp.read())
env = Environment(BUILDERS={'Cat':Builder(action=cat)})
f1 = env.Cat('../file1.out', 'file1.in')
f2 = env.Cat('../file2.out', ['file2a.in', 'file2b.in'])
diff --git a/test/Fortran/FORTRANMODDIR.py b/test/Fortran/FORTRANMODDIR.py
index 61dcc45..a0e03af 100644
--- a/test/Fortran/FORTRANMODDIR.py
+++ b/test/Fortran/FORTRANMODDIR.py
@@ -47,14 +47,16 @@ import re
import sys
# case insensitive matching, because Fortran is case insensitive
mod_regex = "(?im)^\\s*MODULE\\s+(?!PROCEDURE)(\\w+)"
-contents = open(sys.argv[2]).read()
+with open(sys.argv[2]) as f:
+ contents = f.read()
modules = re.findall(mod_regex, contents)
(prefix, moddir) = sys.argv[1].split('=')
if prefix != 'moduledir':
sys.exit(1)
modules = [os.path.join(moddir, m.lower()+'.mod') for m in modules]
for t in sys.argv[3:] + modules:
- open(t, 'wb').write(('myfortran.py wrote %s\n' % os.path.split(t)[1]).encode())
+ with open(t, 'wb') as f:
+ f.write(('myfortran.py wrote %s\n' % os.path.split(t)[1]).encode())
""")
test.write('SConstruct', """
diff --git a/test/Fortran/FORTRANSUFFIXES.py b/test/Fortran/FORTRANSUFFIXES.py
index c1b3455..b703c60 100644
--- a/test/Fortran/FORTRANSUFFIXES.py
+++ b/test/Fortran/FORTRANSUFFIXES.py
@@ -37,14 +37,15 @@ test = TestSCons.TestSCons()
test.write('myfc.py', r"""
import sys
def do_file(outf, inf):
- for line in open(inf, 'rb').readlines():
- if line[:15] == b" INCLUDE '":
- do_file(outf, line[15:-2])
- else:
- outf.write(line)
-outf = open(sys.argv[1], 'wb')
-for f in sys.argv[2:]:
- do_file(outf, f)
+ with open(inf, 'rb') as inf:
+ for line in inf.readlines():
+ if line[:15] == b" INCLUDE '":
+ do_file(outf, line[15:-2])
+ else:
+ outf.write(line)
+with open(sys.argv[1], 'wb') as outf:
+ for f in sys.argv[2:]:
+ do_file(outf, f)
sys.exit(0)
""")
diff --git a/test/Fortran/USE-MODULE.py b/test/Fortran/USE-MODULE.py
index 0d78e7a..ab76f3d 100644
--- a/test/Fortran/USE-MODULE.py
+++ b/test/Fortran/USE-MODULE.py
@@ -38,11 +38,13 @@ import os.path
import re
import sys
mod_regex = "(?im)^\\s*MODULE\\s+(?!PROCEDURE)(\\w+)"
-contents = open(sys.argv[1]).read()
+with open(sys.argv[1]) as f:
+ contents = f.read()
modules = re.findall(mod_regex, contents)
modules = [m.lower()+'.mod' for m in modules]
for t in sys.argv[2:] + modules:
- open(t, 'wb').write(('myfortran.py wrote %s\n' % os.path.split(t)[1]).encode())
+ with open(t, 'wb') as f:
+ f.write(('myfortran.py wrote %s\n' % os.path.split(t)[1]).encode())
sys.exit(0)
""")
diff --git a/test/Fortran/link-with-cxx.py b/test/Fortran/link-with-cxx.py
index bf10fc8..f559b0a 100644
--- a/test/Fortran/link-with-cxx.py
+++ b/test/Fortran/link-with-cxx.py
@@ -42,25 +42,25 @@ test = TestSCons.TestSCons(match = TestSCons.match_re)
test.write('test_linker.py', r"""
import sys
if sys.argv[1] == '-o':
- outfile = open(sys.argv[2], 'wb')
+ ofp = open(sys.argv[2], 'wb')
infiles = sys.argv[3:]
elif sys.argv[1][:5] == '/OUT:':
- outfile = open(sys.argv[1][5:], 'wb')
+ ofp = open(sys.argv[1][5:], 'wb')
infiles = sys.argv[2:]
for infile in infiles:
- with open(infile, 'rb') as f:
- outfile.write(f.read())
-outfile.close()
+ with open(infile, 'rb') as ifp:
+ ofp.write(ifp.read())
+ofp.close()
sys.exit(0)
""")
test.write('test_fortran.py', r"""
import sys
-outfile = open(sys.argv[2], 'wb')
-for infile in sys.argv[4:]:
- outfile.write(open(infile, 'rb').read())
-outfile.close()
+with open(sys.argv[2], 'wb') as ofp:
+ for infile in sys.argv[4:]:
+ with open(infile, 'rb') as ifp:
+ ofp.write(ifp.read())
sys.exit(0)
""")
@@ -70,8 +70,9 @@ import SCons.Tool.link
def copier(target, source, env):
s = str(source[0])
t = str(target[0])
- with open(t, 'wb') as fo, open(s, 'rb') as fi:
- fo.write(fi.read())
+ with open(t, 'wb') as ofp, open(s, 'rb') as ifp:
+ ofp.write(ifp.read())
+
env = Environment(CXX = r'%(_python_)s test_linker.py',
CXXCOM = Action(copier),
SMARTLINK = SCons.Tool.link.smart_link,
diff --git a/test/Fortran/module-subdir.py b/test/Fortran/module-subdir.py
index 6224d44..0b87aa2 100644
--- a/test/Fortran/module-subdir.py
+++ b/test/Fortran/module-subdir.py
@@ -52,23 +52,23 @@ for opt, arg in opts:
if opt == '-o': out = arg
elif opt == '-M': modsubdir = arg
import os
-infile = open(args[0], 'rb')
-outfile = open(out, 'wb')
-for l in infile.readlines():
- if l[:7] == b'module ':
- module = modsubdir + os.sep + l[7:-1].decode() + '.mod'
- open(module, 'wb').write(('myfortran.py wrote %s\n' % module).encode())
- if l[:length] != comment:
- outfile.write(l)
+with open(out, 'wb') as ofp, open(args[0], 'rb') as ifp:
+ for l in ifp.readlines():
+ if l[:7] == b'module ':
+ module = modsubdir + os.sep + l[7:-1].decode() + '.mod'
+ with open(module, 'wb') as f:
+ f.write(('myfortran.py wrote %s\n' % module).encode())
+ if l[:length] != comment:
+ ofp.write(l)
sys.exit(0)
""")
test.write('myar.py', """\
import sys
-t = open(sys.argv[1], 'wb')
-for s in sys.argv[2:]:
- t.write(open(s, 'rb').read())
-t.close
+with open(sys.argv[1], 'wb') as ofp:
+ for s in sys.argv[2:]:
+ with open(s, 'rb') as ifp:
+ ofp.write(ifp.read())
sys.exit(0)
""")
diff --git a/test/GetBuildFailures/option-k.py b/test/GetBuildFailures/option-k.py
index 28e80c8..92a9db8 100644
--- a/test/GetBuildFailures/option-k.py
+++ b/test/GetBuildFailures/option-k.py
@@ -46,7 +46,8 @@ test = TestSCons.TestSCons()
contents = r"""\
import sys
if sys.argv[0] == 'mypass.py':
- open(sys.argv[3], 'wb').write(open(sys.argv[4], 'rb').read())
+ with open(sys.argv[3], 'wb') as ofp, open(sys.argv[4], 'rb') as ifp:
+ ofp.write(ifp.read())
exit_value = 0
elif sys.argv[0] == 'myfail.py':
exit_value = 1
diff --git a/test/GetBuildFailures/parallel.py b/test/GetBuildFailures/parallel.py
index ee8847f..5387e4a 100644
--- a/test/GetBuildFailures/parallel.py
+++ b/test/GetBuildFailures/parallel.py
@@ -60,7 +60,8 @@ if wait_marker != '-.marker':
while not os.path.exists(wait_marker):
time.sleep(1)
if sys.argv[0] == 'mypass.py':
- open(sys.argv[3], 'wb').write(open(sys.argv[4], 'rb').read())
+ with open(sys.argv[3], 'wb') as ofp, open(sys.argv[4], 'rb') as ifp:
+ ofp.write(ifp.read())
exit_value = 0
elif sys.argv[0] == 'myfail.py':
exit_value = 1
diff --git a/test/GetBuildFailures/serial.py b/test/GetBuildFailures/serial.py
index 4d1b7cd..7557dd5 100644
--- a/test/GetBuildFailures/serial.py
+++ b/test/GetBuildFailures/serial.py
@@ -49,7 +49,8 @@ test = TestSCons.TestSCons()
contents = r"""\
import sys
if sys.argv[0] == 'mypass.py':
- open(sys.argv[3], 'wb').write(open(sys.argv[4], 'rb').read())
+ with open(sys.argv[3], 'wb') as ofp, open(sys.argv[4], 'rb') as ifp:
+ ofp.write(ifp.read())
exit_value = 0
elif sys.argv[0] == 'myfail.py':
exit_value = 1
@@ -195,8 +196,7 @@ scons: *** [f12] f12: My SConsEnvironmentError
scons: *** [f13] f13: My SConsEnvironmentError
scons: *** [f14] InternalError : My InternalError
""") + \
-"""\
-Traceback \((most recent call|innermost) last\):
+r"""Traceback \((most recent call|innermost) last\):
( File ".+", line \d+, in \S+
[^\n]+
)*( File ".+", line \d+, in \S+
diff --git a/test/Glob/Repository.py b/test/Glob/Repository.py
index 3308e62..714bafa 100644
--- a/test/Glob/Repository.py
+++ b/test/Glob/Repository.py
@@ -50,10 +50,10 @@ test.write(['repository', 'SConstruct'], """\
DefaultEnvironment(tools=[])
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as ofp:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ ofp.write(ifp.read())
# Verify that we can glob a repository-only Node that exists
# only in memory, not on disk.
diff --git a/test/Glob/VariantDir.py b/test/Glob/VariantDir.py
index 3beb9ab..6340bb8 100644
--- a/test/Glob/VariantDir.py
+++ b/test/Glob/VariantDir.py
@@ -52,10 +52,10 @@ test.write(['src', 'SConscript'], """\
env = Environment(tools=[])
def concatenate(target, source, env):
- fp = open(str(target[0]), 'wb')
- for s in source:
- fp.write(open(str(s), 'rb').read())
- fp.close()
+ with open(str(target[0]), 'wb') as ofp:
+ for s in source:
+ with open(str(s), 'rb') as ifp:
+ ofp.write(ifp.read())
env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
@@ -67,10 +67,10 @@ test.write(['src', 'sub1', 'SConscript'], """\
env = Environment(tools=[])
def concatenate(target, source, env):
- fp = open(str(target[0]), 'wb')
- for s in source:
- fp.write(open(str(s), 'rb').read())
- fp.close()
+ with open(str(target[0]), 'wb') as ofp:
+ for s in source:
+ with open(str(s), 'rb') as ifp:
+ ofp.write(ifp.read())
env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
diff --git a/test/Glob/basic.py b/test/Glob/basic.py
index ad998c3..5e5cdb5 100644
--- a/test/Glob/basic.py
+++ b/test/Glob/basic.py
@@ -37,10 +37,10 @@ DefaultEnvironment(tools=[])
env = Environment(tools=[])
def concatenate(target, source, env):
- fp = open(str(target[0]), 'wb')
- for s in source:
- fp.write(open(str(s), 'rb').read())
- fp.close()
+ with open(str(target[0]), 'wb') as ofp:
+ for s in source:
+ with open(str(s), 'rb') as ifp:
+ ofp.write(ifp.read())
env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
diff --git a/test/Glob/exclude.py b/test/Glob/exclude.py
index bc3e774..658d99a 100644
--- a/test/Glob/exclude.py
+++ b/test/Glob/exclude.py
@@ -40,10 +40,10 @@ DefaultEnvironment(tools=[])
env = Environment(tools=[])
def concatenate(target, source, env):
- fp = open(str(target[0]), 'wb')
- for s in source:
- fp.write(open(str(s), 'rb').read())
- fp.close()
+ with open(str(target[0]), 'wb') as ofp:
+ for s in source:
+ with open(str(s), 'rb') as ifp:
+ ofp.write(ifp.read())
env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
diff --git a/test/Glob/source.py b/test/Glob/source.py
index 3d40d05..33aff85 100644
--- a/test/Glob/source.py
+++ b/test/Glob/source.py
@@ -41,10 +41,10 @@ DefaultEnvironment(tools=[])
env = Environment(tools=[])
def concatenate(target, source, env):
- fp = open(str(target[0]), 'wb')
- for s in source:
- fp.write(open(str(s), 'rb').read())
- fp.close()
+ with open(str(target[0]), 'wb') as ofp:
+ for s in source:
+ with open(str(s), 'rb') as ifp:
+ ofp.write(ifp.read())
env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
diff --git a/test/Glob/strings.py b/test/Glob/strings.py
index 0780ace..2a4a624 100644
--- a/test/Glob/strings.py
+++ b/test/Glob/strings.py
@@ -49,10 +49,10 @@ test.write(['src', 'SConscript'], """\
env = Environment(tools=[])
def concatenate(target, source, env):
- fp = open(str(target[0]), 'wb')
- for s in source:
- fp.write(open(str(s), 'rb').read())
- fp.close()
+ with open(str(target[0]), 'wb') as ofp:
+ for s in source:
+ with open(str(s), 'rb') as ifp:
+ ofp.write(ifp.read())
env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
diff --git a/test/Glob/subdir.py b/test/Glob/subdir.py
index 1227788..22439f7 100644
--- a/test/Glob/subdir.py
+++ b/test/Glob/subdir.py
@@ -40,10 +40,10 @@ DefaultEnvironment(tools=[])
env = Environment(tools=[])
def concatenate(target, source, env):
- fp = open(str(target[0]), 'wb')
- for s in source:
- fp.write(open(str(s), 'rb').read())
- fp.close()
+ with open(str(target[0]), 'wb') as ofp:
+ for s in source:
+ with open(str(s), 'rb') as ifp:
+ ofp.write(ifp.read())
env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
diff --git a/test/Glob/subst.py b/test/Glob/subst.py
index 6a145f1..efbc916 100644
--- a/test/Glob/subst.py
+++ b/test/Glob/subst.py
@@ -38,10 +38,10 @@ DefaultEnvironment(tools=[])
env = Environment(tools=[], PATTERN = 'f*.in')
def copy(target, source, env):
- fp = open(str(target[0]), 'wb')
- for s in source:
- fp.write(open(str(s), 'rb').read())
- fp.close()
+ with open(str(target[0]), 'wb') as ofp:
+ for s in source:
+ with open(str(s), 'rb') as ifp:
+ ofp.write(ifp.read())
env['BUILDERS']['Copy'] = Builder(action=copy)
diff --git a/test/HeaderGen.py b/test/HeaderGen.py
index 2763b34..f66ef57 100644
--- a/test/HeaderGen.py
+++ b/test/HeaderGen.py
@@ -35,9 +35,8 @@ test = TestSCons.TestSCons()
test.write('SConstruct', """\
def writeFile(target, contents):
- file = open(str(target[0]), 'w')
- file.write(contents)
- file.close()
+ with open(str(target[0]), 'w') as f:
+ f.write(contents)
return 0
env = Environment()
@@ -60,10 +59,9 @@ test.write('SConstruct', """\
env = Environment()
def gen_a_h(target, source, env):
- t = open(str(target[0]), 'w')
- s = open(str(source[0]), 'r')
- s.readline()
- t.write(s.readline()[:-1] + ';\\n')
+ with open(str(target[0]), 'w') as t, open(str(source[0]), 'r') as s:
+ s.readline()
+ t.write(s.readline()[:-1] + ';\\n')
MakeHeader = Builder(action = gen_a_h)
env_no_scan = env.Clone(SCANNERS=[], BUILDERS={'MakeHeader' : MakeHeader})
diff --git a/test/IDL/MIDLCOM.py b/test/IDL/MIDLCOM.py
index a478da0..af5ce01 100644
--- a/test/IDL/MIDLCOM.py
+++ b/test/IDL/MIDLCOM.py
@@ -39,16 +39,14 @@ test = TestSCons.TestSCons()
test.write('mymidl.py', """
import os.path
import sys
-out_tlb = open(sys.argv[1], 'w')
base = os.path.splitext(sys.argv[1])[0]
-out_h = open(base + '.h', 'w')
-out_c = open(base + '_i.c', 'w')
-for f in sys.argv[2:]:
- infile = open(f, 'r')
- for l in [l for l in infile.readlines() if l != '/*midl*/\\n']:
- out_tlb.write(l)
- out_h.write(l)
- out_c.write(l)
+with open(sys.argv[1], 'w') as out_tlb, open(base + '.h', 'w') as out_h, open(base + '_i.c', 'w') as out_c:
+ for f in sys.argv[2:]:
+ with open(f, 'r') as ifp:
+ for l in [l for l in ifp.readlines() if l != '/*midl*/\\n']:
+ out_tlb.write(l)
+ out_h.write(l)
+ out_c.write(l)
sys.exit(0)
""")
diff --git a/test/Ignore.py b/test/Ignore.py
index 0716e11..053f785 100644
--- a/test/Ignore.py
+++ b/test/Ignore.py
@@ -36,11 +36,12 @@ test.subdir('subdir')
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read() + open(sys.argv[3], 'rb').read()
-file = open(sys.argv[1], 'wb')
-for arg in sys.argv[2:]:
- file.write(open(arg, 'rb').read())
-file.close()
+with open(sys.argv[2], 'rb') as afp2, open(sys.argv[3], 'rb') as afp3:
+ contents = afp2.read() + afp3.read()
+with open(sys.argv[1], 'wb') as f:
+ for arg in sys.argv[2:]:
+ with open(arg, 'rb') as ifp:
+ f.write(ifp.read())
""")
SUBDIR_f3_out = os.path.join('$SUBDIR', 'f3.out')
diff --git a/test/Install/Install.py b/test/Install/Install.py
index da97d2a..0647002 100644
--- a/test/Install/Install.py
+++ b/test/Install/Install.py
@@ -51,15 +51,16 @@ test.write(['work', 'SConstruct'], """\
DefaultEnvironment(tools=[])
def cat(env, source, target):
target = str(target[0])
- f = open(target, "w")
- for src in source:
- f.write(open(str(src), "r").read())
- f.close()
+ with open(target, 'wb') as ofp:
+ for src in source:
+ with open(str(src), 'rb') as ifp:
+ ofp.write(ifp.read())
def my_install(dest, source, env):
import shutil
shutil.copy2(source, dest)
- open('my_install.out', 'a').write(dest)
+ with open('my_install.out', 'a') as f:
+ f.write(dest)
env1 = Environment(tools=[])
env1.Append(BUILDERS={'Cat':Builder(action=cat)})
@@ -123,7 +124,8 @@ test.fail_test(oldtime1 == os.path.getmtime(f1_out))
test.fail_test(oldtime2 != os.path.getmtime(f2_out))
# Verify that we didn't link to the Installed file.
-open(f2_out, 'w').write("xyzzy\n")
+with open(f2_out, 'w') as f:
+ f.write("xyzzy\n")
test.must_match(['work', 'f2.out'], "f2.in\n", mode='r')
# Verify that scons prints an error message
@@ -131,20 +133,16 @@ test.must_match(['work', 'f2.out'], "f2.in\n", mode='r')
test.write(['work', 'f1.in'], "f1.in again again\n")
os.chmod(test.workpath('work', 'export'), 0o555)
-f = open(f1_out, 'rb')
+with open(f1_out, 'rb'):
+ expect = [
+ "Permission denied",
+ "The process cannot access the file because it is being used by another process",
+ "Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird",
+ ]
+ test.run(chdir='work', arguments=f1_out, stderr=None, status=2)
-expect = [
- "Permission denied",
- "The process cannot access the file because it is being used by another process",
- "Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird",
-]
-
-test.run(chdir = 'work', arguments = f1_out, stderr=None, status=2)
-
-test.must_contain_any_line(test.stderr(), expect)
-
-f.close()
+ test.must_contain_any_line(test.stderr(), expect)
test.pass_test()
diff --git a/test/Install/wrap-by-attribute.py b/test/Install/wrap-by-attribute.py
index 6989fa8..014b7a5 100644
--- a/test/Install/wrap-by-attribute.py
+++ b/test/Install/wrap-by-attribute.py
@@ -47,10 +47,10 @@ import os.path
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, 'wb') as ofp:
+ for src in source:
+ with open(str(src), 'rb') as ifp:
+ ofp.write(ifp.read())
env = Environment(tools=[], DESTDIR='dest')
env.Append(BUILDERS={'Cat':Builder(action=cat)})
diff --git a/test/Interactive/configure.py b/test/Interactive/configure.py
index a7f0735..9c7ef49 100644
--- a/test/Interactive/configure.py
+++ b/test/Interactive/configure.py
@@ -51,15 +51,14 @@ env = Environment(CXXCOM = r'%(_python_)s mycc.py $TARGET $SOURCE',
# Ensure that our 'compiler' works...
def CheckMyCC(context):
context.Message('Checking for MyCC compiler...')
- result = context.TryBuild(context.env.Object,
- 'int main(void) {return 0;}',
+ result = context.TryBuild(context.env.Object,
+ 'int main(void) {return 0;}',
'.cpp')
context.Result(result)
return result
-
-conf = Configure(env,
- custom_tests = {'CheckMyCC' : CheckMyCC})
-
+
+conf = Configure(env, custom_tests = {'CheckMyCC' : CheckMyCC})
+
if conf.CheckMyCC():
pass # build succeeded
else:
diff --git a/test/LEX/LEX.py b/test/LEX/LEX.py
index 65e4497..a739bfe 100644
--- a/test/LEX/LEX.py
+++ b/test/LEX/LEX.py
@@ -44,7 +44,8 @@ else:
longopts = []
cmd_opts, args = getopt.getopt(sys.argv[1:], 't', longopts)
for a in args:
- contents = open(a, 'rb').read()
+ with open(a, 'rb') as f:
+ contents = f.read()
sys.stdout.write(contents.replace(b'LEX', b'mylex.py').decode())
sys.exit(0)
""")
diff --git a/test/LEX/LEXFLAGS.py b/test/LEX/LEXFLAGS.py
index 51b6614..994834e 100644
--- a/test/LEX/LEXFLAGS.py
+++ b/test/LEX/LEXFLAGS.py
@@ -51,7 +51,8 @@ for opt, arg in cmd_opts:
if opt == '-I': i_arguments = i_arguments + ' ' + arg
else: opt_string = opt_string + ' ' + opt
for a in args:
- contents = open(a, 'r').read()
+ with open(a, 'r') as f:
+ contents = f.read()
contents = contents.replace('LEXFLAGS', opt_string)
contents = contents.replace('I_ARGS', i_arguments)
sys.stdout.write(contents)
diff --git a/test/LINK/LINKFLAGS.py b/test/LINK/LINKFLAGS.py
index f0c7518..1642459 100644
--- a/test/LINK/LINKFLAGS.py
+++ b/test/LINK/LINKFLAGS.py
@@ -36,7 +36,8 @@ test = TestSCons.TestSCons()
test.write("wrapper.py",
"""import os
import sys
-open('%s', 'wb').write(("wrapper.py\\n").encode())
+with open('%s', 'wb') as f:
+ f.write(("wrapper.py\\n").encode())
args = [s for s in sys.argv[1:] if s != 'fake_link_flag']
os.system(" ".join(args))
""" % test.workpath('wrapper.out').replace('\\', '\\\\'))
diff --git a/test/LINK/SHLINKFLAGS.py b/test/LINK/SHLINKFLAGS.py
index 51b6e22..ab90ece 100644
--- a/test/LINK/SHLINKFLAGS.py
+++ b/test/LINK/SHLINKFLAGS.py
@@ -37,7 +37,8 @@ test = TestSCons.TestSCons()
test.write("wrapper.py",
"""import os
import sys
-open('%s', 'wb').write(("wrapper.py\\n").encode())
+with open('%s', 'wb') as f:
+ f.write(("wrapper.py\\n").encode())
args = [s for s in sys.argv[1:] if s != 'fake_shlink_flag']
os.system(" ".join(args))
""" % test.workpath('wrapper.out').replace('\\', '\\\\'))
diff --git a/test/M4/M4COM.py b/test/M4/M4COM.py
index 4e95419..756cd55 100644
--- a/test/M4/M4COM.py
+++ b/test/M4/M4COM.py
@@ -38,11 +38,11 @@ test = TestSCons.TestSCons()
test.write('mym4.py', """
import sys
-outfile = open(sys.argv[1], 'wb')
-for f in sys.argv[2:]:
- infile = open(f, 'rb')
- for l in [l for l in infile.readlines() if l != b'/*m4*/\\n']:
- outfile.write(l)
+with open(sys.argv[1], 'wb') as ofp:
+ for f in sys.argv[2:]:
+ with open(f, 'rb') as ifp:
+ for l in [l for l in ifp.readlines() if l != b'/*m4*/\\n']:
+ ofp.write(l)
sys.exit(0)
""")
diff --git a/test/M4/M4COMSTR.py b/test/M4/M4COMSTR.py
index 0e6725b..106cd1d 100644
--- a/test/M4/M4COMSTR.py
+++ b/test/M4/M4COMSTR.py
@@ -39,11 +39,11 @@ test = TestSCons.TestSCons()
test.write('mym4.py', """
import sys
-outfile = open(sys.argv[1], 'wb')
-for f in sys.argv[2:]:
- infile = open(f, 'rb')
- for l in [l for l in infile.readlines() if l != b'/*m4*/\\n']:
- outfile.write(l)
+with open(sys.argv[1], 'wb') as ofp:
+ for f in sys.argv[2:]:
+ with open(f, 'rb') as ifp:
+ for l in [l for l in ifp.readlines() if l != b'/*m4*/\\n']:
+ ofp.write(l)
sys.exit(0)
""")
diff --git a/test/MSVC/batch.py b/test/MSVC/batch.py
index 0d3063f..d9033ec 100644
--- a/test/MSVC/batch.py
+++ b/test/MSVC/batch.py
@@ -56,20 +56,24 @@ else:
# Delay writing the .log output until here so any trailing slash or
# backslash has been stripped, and the output comparisons later in this
# script don't have to account for the difference.
-open('fake_cl.log', 'a').write(" ".join(sys.argv[1:]) + '\\n')
+with open('fake_cl.log', 'a') as ofp:
+ ofp.write(" ".join(sys.argv[1:]) + '\\n')
for infile in input_files:
if dir:
outfile = os.path.join(dir, infile.replace('.c', '.obj'))
else:
outfile = output
- open(outfile, 'w').write(open(infile, 'r').read())
+ with open(outfile, 'w') as ofp:
+ with open(infile, 'r') as ifp:
+ ofp.write(ifp.read())
""")
test.write('fake_link.py', """\
import sys
-ofp = open(sys.argv[1], 'w')
-for infile in sys.argv[2:]:
- ofp.write(open(infile, 'r').read())
+with open(sys.argv[1], 'w') as ofp:
+ for infile in sys.argv[2:]:
+ with open(infile, 'r') as ifp:
+ ofp.write(ifp.read())
""")
test.write('SConstruct', """
diff --git a/test/MSVS/vs-10.0-scc-files.py b/test/MSVS/vs-10.0-scc-files.py
index 0b8bd76..8a08ece 100644
--- a/test/MSVS/vs-10.0-scc-files.py
+++ b/test/MSVS/vs-10.0-scc-files.py
@@ -51,7 +51,7 @@ env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='10.0',
MSVS_SCC_PROJECT_NAME='Perforce Project')
testsrc = ['test1.cpp', 'test2.cpp']
-testincs = ['sdk_dir\sdk.h']
+testincs = [r'sdk_dir\\sdk.h']
testlocalincs = ['test.h']
testresources = ['test.rc']
testmisc = ['readme.txt']
diff --git a/test/MSVS/vs-10.0-scc-legacy-files.py b/test/MSVS/vs-10.0-scc-legacy-files.py
index 14276a7..9cb65d8 100644
--- a/test/MSVS/vs-10.0-scc-legacy-files.py
+++ b/test/MSVS/vs-10.0-scc-legacy-files.py
@@ -46,11 +46,11 @@ SConscript_contents = """\
env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='10.0',
CPPDEFINES=['DEF1', 'DEF2',('DEF3','1234')],
CPPPATH=['inc1', 'inc2'],
- MSVS_SCC_LOCAL_PATH='C:\\MyMsVsProjects',
+ MSVS_SCC_LOCAL_PATH=r'C:\\MyMsVsProjects',
MSVS_SCC_PROJECT_NAME='Perforce Project')
testsrc = ['test1.cpp', 'test2.cpp']
-testincs = ['sdk_dir\sdk.h']
+testincs = [r'sdk_dir\\sdk.h']
testlocalincs = ['test.h']
testresources = ['test.rc']
testmisc = ['readme.txt']
diff --git a/test/MSVS/vs-11.0-scc-files.py b/test/MSVS/vs-11.0-scc-files.py
index a25b954..2b13e46 100644
--- a/test/MSVS/vs-11.0-scc-files.py
+++ b/test/MSVS/vs-11.0-scc-files.py
@@ -51,7 +51,7 @@ env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='11.0',
MSVS_SCC_PROJECT_NAME='Perforce Project')
testsrc = ['test1.cpp', 'test2.cpp']
-testincs = ['sdk_dir\sdk.h']
+testincs = [r'sdk_dir\\sdk.h']
testlocalincs = ['test.h']
testresources = ['test.rc']
testmisc = ['readme.txt']
diff --git a/test/MSVS/vs-11.0-scc-legacy-files.py b/test/MSVS/vs-11.0-scc-legacy-files.py
index 726f994..9e46f6a 100644
--- a/test/MSVS/vs-11.0-scc-legacy-files.py
+++ b/test/MSVS/vs-11.0-scc-legacy-files.py
@@ -46,11 +46,11 @@ SConscript_contents = """\
env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='11.0',
CPPDEFINES=['DEF1', 'DEF2',('DEF3','1234')],
CPPPATH=['inc1', 'inc2'],
- MSVS_SCC_LOCAL_PATH='C:\\MyMsVsProjects',
+ MSVS_SCC_LOCAL_PATH=r'C:\\MyMsVsProjects',
MSVS_SCC_PROJECT_NAME='Perforce Project')
testsrc = ['test1.cpp', 'test2.cpp']
-testincs = ['sdk_dir\sdk.h']
+testincs = [r'sdk_dir\\sdk.h']
testlocalincs = ['test.h']
testresources = ['test.rc']
testmisc = ['readme.txt']
diff --git a/test/MSVS/vs-14.0-scc-files.py b/test/MSVS/vs-14.0-scc-files.py
index b6db6d5..d706b32 100644
--- a/test/MSVS/vs-14.0-scc-files.py
+++ b/test/MSVS/vs-14.0-scc-files.py
@@ -51,7 +51,7 @@ env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='14.0',
MSVS_SCC_PROJECT_NAME='Perforce Project')
testsrc = ['test1.cpp', 'test2.cpp']
-testincs = ['sdk_dir\sdk.h']
+testincs = [r'sdk_dir\\sdk.h']
testlocalincs = ['test.h']
testresources = ['test.rc']
testmisc = ['readme.txt']
diff --git a/test/MSVS/vs-14.0-scc-legacy-files.py b/test/MSVS/vs-14.0-scc-legacy-files.py
index ba6ebad..904a103 100644
--- a/test/MSVS/vs-14.0-scc-legacy-files.py
+++ b/test/MSVS/vs-14.0-scc-legacy-files.py
@@ -46,11 +46,11 @@ SConscript_contents = """\
env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='14.0',
CPPDEFINES=['DEF1', 'DEF2',('DEF3','1234')],
CPPPATH=['inc1', 'inc2'],
- MSVS_SCC_LOCAL_PATH='C:\\MyMsVsProjects',
+ MSVS_SCC_LOCAL_PATH=r'C:\\MyMsVsProjects',
MSVS_SCC_PROJECT_NAME='Perforce Project')
testsrc = ['test1.cpp', 'test2.cpp']
-testincs = ['sdk_dir\sdk.h']
+testincs = [r'sdk_dir\\sdk.h']
testlocalincs = ['test.h']
testresources = ['test.rc']
testmisc = ['readme.txt']
diff --git a/test/MSVS/vs-14.1-scc-files.py b/test/MSVS/vs-14.1-scc-files.py
index 74e055e..465c904 100644
--- a/test/MSVS/vs-14.1-scc-files.py
+++ b/test/MSVS/vs-14.1-scc-files.py
@@ -49,7 +49,7 @@ env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='14.1',
MSVS_SCC_PROJECT_NAME='Perforce Project')
testsrc = ['test1.cpp', 'test2.cpp']
-testincs = ['sdk_dir\sdk.h']
+testincs = [r'sdk_dir\\sdk.h']
testlocalincs = ['test.h']
testresources = ['test.rc']
testmisc = ['readme.txt']
diff --git a/test/MSVS/vs-14.1-scc-legacy-files.py b/test/MSVS/vs-14.1-scc-legacy-files.py
index 0444b16..45d94a6 100644
--- a/test/MSVS/vs-14.1-scc-legacy-files.py
+++ b/test/MSVS/vs-14.1-scc-legacy-files.py
@@ -44,11 +44,11 @@ SConscript_contents = """\
env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='14.1',
CPPDEFINES=['DEF1', 'DEF2',('DEF3','1234')],
CPPPATH=['inc1', 'inc2'],
- MSVS_SCC_LOCAL_PATH='C:\\MyMsVsProjects',
+ MSVS_SCC_LOCAL_PATH=r'C:\\MyMsVsProjects',
MSVS_SCC_PROJECT_NAME='Perforce Project')
testsrc = ['test1.cpp', 'test2.cpp']
-testincs = ['sdk_dir\sdk.h']
+testincs = [r'sdk_dir\\sdk.h']
testlocalincs = ['test.h']
testresources = ['test.rc']
testmisc = ['readme.txt']
diff --git a/test/MSVS/vs-7.0-scc-files.py b/test/MSVS/vs-7.0-scc-files.py
index 8586060..4d90a92 100644
--- a/test/MSVS/vs-7.0-scc-files.py
+++ b/test/MSVS/vs-7.0-scc-files.py
@@ -42,8 +42,8 @@ test._msvs_versions = ['7.0']
expected_slnfile = TestSConsMSVS.expected_slnfile_7_0
expected_vcprojfile = TestSConsMSVS.expected_vcprojfile_7_0
-SConscript_contents = """\
-env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='7.0',
+SConscript_contents = \
+r"""env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='7.0',
CPPDEFINES=['DEF1', 'DEF2',('DEF3','1234')],
CPPPATH=['inc1', 'inc2'],
MSVS_SCC_CONNECTION_ROOT='.',
diff --git a/test/MSVS/vs-7.0-scc-legacy-files.py b/test/MSVS/vs-7.0-scc-legacy-files.py
index d458cf3..e87441b 100644
--- a/test/MSVS/vs-7.0-scc-legacy-files.py
+++ b/test/MSVS/vs-7.0-scc-legacy-files.py
@@ -46,7 +46,7 @@ SConscript_contents = """\
env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='7.0',
CPPDEFINES=['DEF1', 'DEF2',('DEF3','1234')],
CPPPATH=['inc1', 'inc2'],
- MSVS_SCC_LOCAL_PATH='C:\\MyMsVsProjects',
+ MSVS_SCC_LOCAL_PATH=r'C:\\MyMsVsProjects',
MSVS_SCC_PROJECT_NAME='Perforce Project')
testsrc = ['test1.cpp', 'test2.cpp']
diff --git a/test/MSVS/vs-7.1-scc-legacy-files.py b/test/MSVS/vs-7.1-scc-legacy-files.py
index 9f0f809..f80c965 100644
--- a/test/MSVS/vs-7.1-scc-legacy-files.py
+++ b/test/MSVS/vs-7.1-scc-legacy-files.py
@@ -46,7 +46,7 @@ SConscript_contents = """\
env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='7.1',
CPPDEFINES=['DEF1', 'DEF2',('DEF3','1234')],
CPPPATH=['inc1', 'inc2'],
- MSVS_SCC_LOCAL_PATH='C:\\MyMsVsProjects',
+ MSVS_SCC_LOCAL_PATH=r'C:\\MyMsVsProjects',
MSVS_SCC_PROJECT_NAME='Perforce Project')
testsrc = ['test1.cpp', 'test2.cpp']
diff --git a/test/MSVS/vs-8.0-scc-legacy-files.py b/test/MSVS/vs-8.0-scc-legacy-files.py
index 865e1aa..bfb8416 100644
--- a/test/MSVS/vs-8.0-scc-legacy-files.py
+++ b/test/MSVS/vs-8.0-scc-legacy-files.py
@@ -46,7 +46,7 @@ SConscript_contents = """\
env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='8.0',
CPPDEFINES=['DEF1', 'DEF2',('DEF3','1234')],
CPPPATH=['inc1', 'inc2'],
- MSVS_SCC_LOCAL_PATH='C:\\MyMsVsProjects',
+ MSVS_SCC_LOCAL_PATH=r'C:\\MyMsVsProjects',
MSVS_SCC_PROJECT_NAME='Perforce Project')
testsrc = ['test1.cpp', 'test2.cpp']
diff --git a/test/MSVS/vs-9.0-scc-legacy-files.py b/test/MSVS/vs-9.0-scc-legacy-files.py
index 1e609f8..0085f64 100644
--- a/test/MSVS/vs-9.0-scc-legacy-files.py
+++ b/test/MSVS/vs-9.0-scc-legacy-files.py
@@ -46,7 +46,7 @@ SConscript_contents = """\
env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='9.0',
CPPDEFINES=['DEF1', 'DEF2',('DEF3','1234')],
CPPPATH=['inc1', 'inc2'],
- MSVS_SCC_LOCAL_PATH='C:\\MyMsVsProjects',
+ MSVS_SCC_LOCAL_PATH=r'C:\\MyMsVsProjects',
MSVS_SCC_PROJECT_NAME='Perforce Project')
testsrc = ['test1.cpp', 'test2.cpp']
diff --git a/test/Mkdir.py b/test/Mkdir.py
index 8ace476..367c834 100644
--- a/test/Mkdir.py
+++ b/test/Mkdir.py
@@ -41,10 +41,10 @@ Execute(Mkdir('d1'))
Execute(Mkdir(Dir('#d1-Dir')))
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as f:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ f.write(ifp.read())
Cat = Action(cat)
env = Environment()
env.Command('f2.out', 'f2.in', [Cat, Mkdir("d3")])
@@ -126,14 +126,14 @@ test.write(['work2', 'SConstruct'], """\
import os
def catdir(env, source, target):
target = str(target[0])
- outfp = open(target, "wb")
- for src in source:
- s = str(src)
- for f in sorted(os.listdir(s)):
- f = os.path.join(s, f)
- if os.path.isfile(f):
- outfp.write(open(f, "rb").read())
- outfp.close()
+ with open(target, "wb") as outfp:
+ for src in source:
+ s = str(src)
+ for f in sorted(os.listdir(s)):
+ f = os.path.join(s, f)
+ if os.path.isfile(f):
+ with open(f, "rb") as infp:
+ outfp.write(infp.read())
CatDir = Builder(action = catdir)
env = Environment(BUILDERS = {'CatDir' : CatDir})
env.Command(Dir('hello'), None, [Mkdir('$TARGET')])
diff --git a/test/Move.py b/test/Move.py
index b58fa34..1da3aa7 100644
--- a/test/Move.py
+++ b/test/Move.py
@@ -37,10 +37,10 @@ Execute(Move('f1.out', 'f1.in'))
Execute(Move('File-f1.out', File('f1.in-File')))
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as f:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ f.write(ifp.read())
Cat = Action(cat)
env = Environment()
env.Command('f2.out', 'f2.in', [Cat, Move("f3.out", "f3.in")])
diff --git a/test/NoClean.py b/test/NoClean.py
index 63e3e28..fe6a2bc 100644
--- a/test/NoClean.py
+++ b/test/NoClean.py
@@ -34,15 +34,20 @@ test = TestSCons.TestSCons()
test.write('SConstruct', """
def action(target, source, env):
- for t in target: open(t.get_internal_path(), 'w')
+ for t in target:
+ with open(t.get_internal_path(), 'w'):
+ pass
Command('1.out', 'SConstruct', action)
NoClean('1.out')
""")
test.write('SConstruct.force', """
def action(target, source, env):
- for t in target: open(t.get_internal_path(), 'w')
- open('4.out', 'w')
+ for t in target:
+ with open(t.get_internal_path(), 'w'):
+ pass
+ with open('4.out', 'w'):
+ pass
res = Command('3.out', 'SConstruct.force', action)
Clean('4.out', res)
NoClean('4.out')
@@ -50,7 +55,9 @@ NoClean('4.out')
test.write('SConstruct.multi', """
def action(target, source, env):
- for t in target: open(t.get_internal_path(), 'w')
+ for t in target:
+ with open(t.get_internal_path(), 'w'):
+ pass
Command(['5.out', '6.out'], 'SConstruct.multi', action)
NoClean('6.out')
""")
diff --git a/test/ParseDepends.py b/test/ParseDepends.py
index 12b02e2..2de2105 100644
--- a/test/ParseDepends.py
+++ b/test/ParseDepends.py
@@ -36,10 +36,8 @@ test.subdir('subdir', 'sub2')
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read() + open(sys.argv[3], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as afp2, open(sys.argv[3], 'rb') as afp3:
+ f.write(afp2.read() + afp3.read())
""")
test.write('SConstruct', """
diff --git a/test/QT/qt_warnings.py b/test/QT/qt_warnings.py
index a1cf221..23612de 100644
--- a/test/QT/qt_warnings.py
+++ b/test/QT/qt_warnings.py
@@ -84,8 +84,8 @@ if moc:
qtdir = os.path.dirname(os.path.dirname(moc))
qtdir = qtdir.replace('\\', '\\\\' )
- expect = """
-scons: warning: Could not detect qt, using moc executable as a hint \(QTDIR=%s\)
+ expect = \
+r"""scons: warning: Could not detect qt, using moc executable as a hint \(QTDIR=%s\)
File "%s", line \d+, in (\?|<module>)
""" % (qtdir, re.escape(SConstruct_path))
else:
diff --git a/test/Repository/Default.py b/test/Repository/Default.py
index bd9d5f8..e33a26e 100644
--- a/test/Repository/Default.py
+++ b/test/Repository/Default.py
@@ -47,7 +47,8 @@ def copy(env, source, target):
source = str(source[0])
target = str(target[0])
print('copy() < %s > %s' % (source, target))
- open(target, "w").write(open(source, "r").read())
+ with open(target, "w") as ofp, open(source, "r") as ifp:
+ ofp.write(ifp.read())
Build = Builder(action=copy)
env = Environment(BUILDERS={'Build':Build})
diff --git a/test/Repository/LIBPATH.py b/test/Repository/LIBPATH.py
index 8b396fa..646b5d7 100644
--- a/test/Repository/LIBPATH.py
+++ b/test/Repository/LIBPATH.py
@@ -46,14 +46,13 @@ bbb_exe = env_yyy.Program('bbb', 'bbb.c')
def write_LIBDIRFLAGS(env, target, source):
pre = env.subst('$LIBDIRPREFIX')
suf = env.subst('$LIBDIRSUFFIX')
- f = open(str(target[0]), 'w')
- for arg in env.subst('$_LIBDIRFLAGS', target=target).split():
- if arg[:len(pre)] == pre:
- arg = arg[len(pre):]
- if arg[-len(suf):] == suf:
- arg = arg[:-len(pre)]
- f.write(arg + '\n')
- f.close()
+ with open(str(target[0]), 'w') as f:
+ for arg in env.subst('$_LIBDIRFLAGS', target=target).split():
+ if arg[:len(pre)] == pre:
+ arg = arg[len(pre):]
+ if arg[-len(suf):] == suf:
+ arg = arg[:-len(pre)]
+ f.write(arg + '\n')
return 0
env_zzz.Command('zzz.out', aaa_exe, write_LIBDIRFLAGS)
env_yyy.Command('yyy.out', bbb_exe, write_LIBDIRFLAGS)
diff --git a/test/Repository/Local.py b/test/Repository/Local.py
index 7062075..a906245 100644
--- a/test/Repository/Local.py
+++ b/test/Repository/Local.py
@@ -49,8 +49,8 @@ def copy(env, source, target):
source = str(source[0])
target = str(target[0])
print('copy() < %s > %s' % (source, target))
- with open(target, 'w') as fo, open(source, 'r') as fi:
- fo.write(fi.read())
+ with open(target, 'w') as ofp, open(source, 'r') as ifp:
+ ofp.write(ifp.read())
Build = Builder(action=copy)
env = Environment(BUILDERS={'Build':Build}, BBB='bbb')
diff --git a/test/Repository/SConscript.py b/test/Repository/SConscript.py
index 1b67c07..1482800 100644
--- a/test/Repository/SConscript.py
+++ b/test/Repository/SConscript.py
@@ -61,10 +61,11 @@ SConscript('src/SConscript')
test.write(['rep1', 'src', 'SConscript'], """\
def cat(env, source, target):
target = str(target[0])
- f = open(target, "w")
- for src in source:
- f.write(open(str(src), "r").read())
- f.close()
+ with open(target, "w") as ofp:
+ for src in source:
+ with open(str(src), "r") as ifp:
+ ofp.write(ifp.read())
+
env = Environment(BUILDERS={'Cat':Builder(action=cat)})
env.Cat(target = 'foo', source = ['aaa.in', 'bbb.in', 'ccc.in'])
""")
@@ -97,10 +98,11 @@ SConscript('src/SConscript')
test.write(['rep2', 'src', 'SConscript'], """\
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "w") as ofp:
+ for src in source:
+ with open(str(src), "r") as ifp:
+ ofp.write(ifp.read())
+
env = Environment(BUILDERS={'Cat':Builder(action=cat)})
env.Cat(target = 'foo', source = ['aaa.in', 'bbb.in', 'ccc.in'])
SConscript('sub/SConscript')
diff --git a/test/Repository/VariantDir.py b/test/Repository/VariantDir.py
index 8887f86..327e550 100644
--- a/test/Repository/VariantDir.py
+++ b/test/Repository/VariantDir.py
@@ -49,10 +49,10 @@ def cat(env, source, target):
target = str(target[0])
source = list(map(str, source))
print('cat(%s) > %s' % (source, target))
- f = open(target, "w")
- for src in source:
- f.write(open(src, "r").read())
- f.close()
+ with open(target, "w") as ofp:
+ for src in source:
+ with open(src, "r") as ifp:
+ ofp.write(ifp.read())
env = Environment(BUILDERS={'Build':Builder(action=cat)})
env.Build('aaa.mid', 'aaa.in')
diff --git a/test/Repository/option-c.py b/test/Repository/option-c.py
index 58c4876..a73bcf7 100644
--- a/test/Repository/option-c.py
+++ b/test/Repository/option-c.py
@@ -66,8 +66,8 @@ def copy(env, source, target):
source = str(source[0])
target = str(target[0])
print('copy() < %s > %s' % (source, target))
- with open(target, 'w') as fo, open(source, 'r') as fi:
- fo.write(fi.read())
+ with open(target, 'w') as ofp, open(source, 'r') as ifp:
+ ofp.write(ifp.read())
Build = Builder(action=copy)
env = Environment(BUILDERS={'Build':Build})
diff --git a/test/Repository/option-f.py b/test/Repository/option-f.py
index c990f2f..f1b2cc6 100644
--- a/test/Repository/option-f.py
+++ b/test/Repository/option-f.py
@@ -43,10 +43,10 @@ test.write(['repository', 'SConstruct'], """\
Repository(r'%s')
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as ofp:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ ofp.write(ifp.read())
env = Environment(BUILDERS={'Build':Builder(action=cat)})
env.Build('aaa.out', 'aaa.in')
diff --git a/test/Repository/option-n.py b/test/Repository/option-n.py
index d23a200..d99e92a 100644
--- a/test/Repository/option-n.py
+++ b/test/Repository/option-n.py
@@ -49,7 +49,8 @@ def copy(env, source, target):
source = str(source[0])
target = str(target[0])
print('copy() < %s > %s' % (source, target))
- open(target, "w").write(open(source, "r").read())
+ with open(target, "w") as ofp, open(source, "r") as ifp:
+ ofp.write(ifp.read())
Build = Builder(action=copy)
env = Environment(BUILDERS={'Build':Build})
diff --git a/test/Repository/targets.py b/test/Repository/targets.py
index 0bc625a..5899c57 100644
--- a/test/Repository/targets.py
+++ b/test/Repository/targets.py
@@ -44,10 +44,10 @@ def cat(env, source, target):
target = str(target[0])
source = list(map(str, source))
print('cat(%s) > %s' % (source, target))
- f = open(target, "w")
- for src in source:
- f.write(open(src, "r").read())
- f.close()
+ with open(target, "w") as ofp:
+ for src in source:
+ with open(src, "r") as ifp:
+ ofp.write(ifp.read())
env = Environment(BUILDERS={'Build':Builder(action=cat)})
env.Build('aaa.out', 'aaa.in')
diff --git a/test/Requires/basic.py b/test/Requires/basic.py
index edce13b..4851ac8 100644
--- a/test/Requires/basic.py
+++ b/test/Requires/basic.py
@@ -35,11 +35,12 @@ test = TestSCons.TestSCons()
test.write('SConstruct', """
def append_prereq_func(target, source, env):
- fp = open(str(target[0]), 'wb')
- for s in source:
- fp.write(open(str(s), 'rb').read())
- fp.write(open('prereq.out', 'rb').read())
- fp.close()
+ with open(str(target[0]), 'wb') as ofp:
+ for s in source:
+ with open(str(s), 'rb') as ifp:
+ ofp.write(ifp.read())
+ with open('prereq.out', 'rb') as ifp:
+ ofp.write(ifp.read())
return None
append_prereq = Action(append_prereq_func)
env = Environment()
diff --git a/test/Requires/eval-order.py b/test/Requires/eval-order.py
index 77fbc98..fddf232 100644
--- a/test/Requires/eval-order.py
+++ b/test/Requires/eval-order.py
@@ -34,11 +34,10 @@ test = TestSCons.TestSCons()
test.write('SConstruct', """
def copy_and_create_func(target, source, env):
- with open(str(target[0]), 'w') as fp:
+ with open(str(target[0]), 'w') as ofp:
for s in source:
- with open(str(s), 'r') as f:
- fp.write(f.read())
- open('file.in', 'w').write("file.in 1\\n")
+ with open(str(s), 'r') as ifp:
+ ofp.write(ifp.read())
with open('file.in', 'w') as f:
f.write("file.in 1\\n")
return None
diff --git a/test/Rpcgen/RPCGEN.py b/test/Rpcgen/RPCGEN.py
index 2f793e2..eaa4e16 100644
--- a/test/Rpcgen/RPCGEN.py
+++ b/test/Rpcgen/RPCGEN.py
@@ -38,12 +38,13 @@ import getopt
import sys
cmd_opts, args = getopt.getopt(sys.argv[1:], 'chlmo:', [])
for opt, arg in cmd_opts:
- if opt == '-o': output = open(arg, 'w')
-output.write(" ".join(sys.argv) + "\\n")
-for a in args:
- contents = open(a, 'r').read()
- output.write(contents.replace('RPCGEN', 'myrpcgen.py'))
-output.close()
+ if opt == '-o': out = arg
+with open(out, 'w') as ofp:
+ ofp.write(" ".join(sys.argv) + "\\n")
+ for a in args:
+ with open(a, 'r') as ifp:
+ contents = ifp.read()
+ ofp.write(contents.replace('RPCGEN', 'myrpcgen.py'))
sys.exit(0)
""")
diff --git a/test/Rpcgen/RPCGENCLIENTFLAGS.py b/test/Rpcgen/RPCGENCLIENTFLAGS.py
index 9612952..a298ebd 100644
--- a/test/Rpcgen/RPCGENCLIENTFLAGS.py
+++ b/test/Rpcgen/RPCGENCLIENTFLAGS.py
@@ -38,12 +38,13 @@ import getopt
import sys
cmd_opts, args = getopt.getopt(sys.argv[1:], 'chlmo:x', [])
for opt, arg in cmd_opts:
- if opt == '-o': output = open(arg, 'w')
-output.write(" ".join(sys.argv) + "\\n")
-for a in args:
- contents = open(a, 'r').read()
- output.write(contents.replace('RPCGEN', 'myrpcgen.py'))
-output.close()
+ if opt == '-o': out = arg
+with open(out, 'w') as ofp:
+ ofp.write(" ".join(sys.argv) + "\\n")
+ for a in args:
+ with open(a, 'r') as ifp:
+ contents = ifp.read()
+ ofp.write(contents.replace('RPCGEN', 'myrpcgen.py'))
sys.exit(0)
""")
diff --git a/test/Rpcgen/RPCGENFLAGS.py b/test/Rpcgen/RPCGENFLAGS.py
index d4be92c..c254ed0 100644
--- a/test/Rpcgen/RPCGENFLAGS.py
+++ b/test/Rpcgen/RPCGENFLAGS.py
@@ -38,12 +38,13 @@ import getopt
import sys
cmd_opts, args = getopt.getopt(sys.argv[1:], 'chlmo:x', [])
for opt, arg in cmd_opts:
- if opt == '-o': output = open(arg, 'w')
-output.write(" ".join(sys.argv) + "\\n")
-for a in args:
- contents = open(a, 'r').read()
- output.write(contents.replace('RPCGEN', 'myrpcgen.py'))
-output.close()
+ if opt == '-o': out = arg
+with open(out, 'w') as ofp:
+ ofp.write(" ".join(sys.argv) + "\\n")
+ for a in args:
+ with open(a, 'r') as ifp:
+ contents = ifp.read()
+ ofp.write(contents.replace('RPCGEN', 'myrpcgen.py'))
sys.exit(0)
""")
diff --git a/test/Rpcgen/RPCGENHEADERFLAGS.py b/test/Rpcgen/RPCGENHEADERFLAGS.py
index 4beca64..8e40ad7 100644
--- a/test/Rpcgen/RPCGENHEADERFLAGS.py
+++ b/test/Rpcgen/RPCGENHEADERFLAGS.py
@@ -38,12 +38,13 @@ import getopt
import sys
cmd_opts, args = getopt.getopt(sys.argv[1:], 'chlmo:x', [])
for opt, arg in cmd_opts:
- if opt == '-o': output = open(arg, 'w')
-output.write(" ".join(sys.argv) + "\\n")
-for a in args:
- contents = open(a, 'r').read()
- output.write(contents.replace('RPCGEN', 'myrpcgen.py'))
-output.close()
+ if opt == '-o': out = arg
+with open(out, 'w') as ofp:
+ ofp.write(" ".join(sys.argv) + "\\n")
+ for a in args:
+ with open(a, 'r') as ifp:
+ contents = ifp.read()
+ ofp.write(contents.replace('RPCGEN', 'myrpcgen.py'))
sys.exit(0)
""")
diff --git a/test/Rpcgen/RPCGENSERVICEFLAGS.py b/test/Rpcgen/RPCGENSERVICEFLAGS.py
index 7644485..2edc77c 100644
--- a/test/Rpcgen/RPCGENSERVICEFLAGS.py
+++ b/test/Rpcgen/RPCGENSERVICEFLAGS.py
@@ -38,12 +38,13 @@ import getopt
import sys
cmd_opts, args = getopt.getopt(sys.argv[1:], 'chlmo:x', [])
for opt, arg in cmd_opts:
- if opt == '-o': output = open(arg, 'w')
-output.write(" ".join(sys.argv) + "\\n")
-for a in args:
- contents = open(a, 'r').read()
- output.write(contents.replace('RPCGEN', 'myrpcgen.py'))
-output.close()
+ if opt == '-o': out = arg
+with open(out, 'w') as ofp:
+ ofp.write(" ".join(sys.argv) + "\\n")
+ for a in args:
+ with open(a, 'r') as ifp:
+ contents = ifp.read()
+ ofp.write(contents.replace('RPCGEN', 'myrpcgen.py'))
sys.exit(0)
""")
diff --git a/test/Rpcgen/RPCGENXDRFLAGS.py b/test/Rpcgen/RPCGENXDRFLAGS.py
index 41da70c..2d1ca96 100644
--- a/test/Rpcgen/RPCGENXDRFLAGS.py
+++ b/test/Rpcgen/RPCGENXDRFLAGS.py
@@ -38,12 +38,13 @@ import getopt
import sys
cmd_opts, args = getopt.getopt(sys.argv[1:], 'chlmo:x', [])
for opt, arg in cmd_opts:
- if opt == '-o': output = open(arg, 'w')
-output.write(" ".join(sys.argv) + "\\n")
-for a in args:
- contents = open(a, 'r').read()
- output.write(contents.replace('RPCGEN', 'myrpcgen.py'))
-output.close()
+ if opt == '-o': out = arg
+with open(out, 'w') as ofp:
+ ofp.write(" ".join(sys.argv) + "\\n")
+ for a in args:
+ with open(a, 'r') as ifp:
+ contents = ifp.read()
+ ofp.write(contents.replace('RPCGEN', 'myrpcgen.py'))
sys.exit(0)
""")
diff --git a/test/SConscript/SConscript.py b/test/SConscript/SConscript.py
index 36288be..fd8511d 100644
--- a/test/SConscript/SConscript.py
+++ b/test/SConscript/SConscript.py
@@ -74,7 +74,7 @@ SConscript('SConscript5')
try:
from collections import UserList
except ImportError:
- exec('from UserList import UserList')
+ from UserList import UserList
x7 = "SConstruct x7"
x8 = "SConstruct x8"
x9 = SConscript('SConscript6', UserList(["x7", "x8"]))
diff --git a/test/SConscript/SConscriptChdir.py b/test/SConscript/SConscriptChdir.py
index 6cd4566..5468a54 100644
--- a/test/SConscript/SConscriptChdir.py
+++ b/test/SConscript/SConscriptChdir.py
@@ -44,33 +44,43 @@ SConscript('dir5/SConscript')
""")
test.write(['dir1', 'SConscript'], """
-exec(open("create_test.py", 'r').read())
+with open("create_test.py", 'r') as f:
+ contents = f.read()
+exec(contents)
""")
test.write(['dir2', 'SConscript'], """
-exec(open("create_test.py", 'r').read())
+with open("create_test.py", 'r') as f:
+ contents = f.read()
+exec(contents)
""")
test.write(['dir3', 'SConscript'], """
import os.path
name = os.path.join('dir3', 'create_test.py')
-exec(open(name, 'r').read())
+with open(name, 'r') as f:
+ contents = f.read()
+exec(contents)
""")
test.write(['dir4', 'SConscript'], """
-exec(open("create_test.py", 'r').read())
+with open("create_test.py", 'r') as f:
+ contents = f.read()
+exec(contents)
""")
test.write(['dir5', 'SConscript'], """
import os.path
name = os.path.join('dir5', 'create_test.py')
-exec(open(name, 'r').read())
+with open(name, 'r') as f:
+ contents = f.read()
+exec(contents)
""")
for dir in ['dir1', 'dir2', 'dir3','dir4', 'dir5']:
test.write([dir, 'create_test.py'], r"""
-f = open("test.txt", "a")
-f.write("This is the %s test.\n")
+with open("test.txt", "a") as f:
+ f.write("This is the %s test.\n")
f.close()
""" % dir)
diff --git a/test/SConsignFile/default.py b/test/SConsignFile/default.py
index 4d56a5e..62ac006 100644
--- a/test/SConsignFile/default.py
+++ b/test/SConsignFile/default.py
@@ -39,10 +39,8 @@ test.subdir('subdir')
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as ofp, open(sys.argv[2], 'rb') as ifp:
+ ofp.write(ifp.read())
sys.exit(0)
""")
diff --git a/test/SConsignFile/explicit-file.py b/test/SConsignFile/explicit-file.py
index 90c2241..7583bdc 100644
--- a/test/SConsignFile/explicit-file.py
+++ b/test/SConsignFile/explicit-file.py
@@ -39,10 +39,8 @@ test.subdir('subdir')
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as ofp, open(sys.argv[2], 'rb') as ifp:
+ ofp.write(ifp.read())
""")
#
diff --git a/test/SConsignFile/use-dbhash.py b/test/SConsignFile/use-dbhash.py
index f70c8b0..e57e244 100644
--- a/test/SConsignFile/use-dbhash.py
+++ b/test/SConsignFile/use-dbhash.py
@@ -43,10 +43,8 @@ test.subdir('subdir')
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as ofp, open(sys.argv[2], 'rb') as ifp:
+ ofp.write(ifp.read())
sys.exit(0)
""")
diff --git a/test/SConsignFile/use-dbm.py b/test/SConsignFile/use-dbm.py
index b5021c4..fcf4420 100644
--- a/test/SConsignFile/use-dbm.py
+++ b/test/SConsignFile/use-dbm.py
@@ -49,10 +49,8 @@ test.subdir('subdir')
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as ofp, open(sys.argv[2], 'rb') as ifp:
+ ofp.write(ifp.read())
sys.exit(0)
""")
diff --git a/test/SConsignFile/use-dumbdbm.py b/test/SConsignFile/use-dumbdbm.py
index 2dcfa61..36ba18b 100644
--- a/test/SConsignFile/use-dumbdbm.py
+++ b/test/SConsignFile/use-dumbdbm.py
@@ -48,10 +48,8 @@ test.subdir('subdir')
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as ofp, open(sys.argv[2], 'rb') as ifp:
+ ofp.write(ifp.read())
sys.exit(0)
""")
diff --git a/test/SConsignFile/use-gdbm.py b/test/SConsignFile/use-gdbm.py
index 1eb3645..8f863fb 100644
--- a/test/SConsignFile/use-gdbm.py
+++ b/test/SConsignFile/use-gdbm.py
@@ -43,10 +43,8 @@ test.subdir('subdir')
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as ofp, open(sys.argv[2], 'rb') as ifp:
+ ofp.write(ifp.read())
sys.exit(0)
""")
diff --git a/test/SHELL.py b/test/SHELL.py
index faee27f..5d97b97 100644
--- a/test/SHELL.py
+++ b/test/SHELL.py
@@ -57,10 +57,10 @@ def stripquote(s):
return s
args = stripquote(sys.argv[2]).split()
args = list(map(stripquote, args))
-ofp = open(args[2], 'wb')
-for f in args[3:] + ['extra.txt']:
- ofp.write(open(f, 'rb').read())
-ofp.close()
+with open(args[2], 'wb') as ofp:
+ for f in args[3:] + ['extra.txt']:
+ with open(f, 'rb') as ifp:
+ ofp.write(ifp.read())
sys.exit(0)
""" % locals())
diff --git a/test/SPAWN.py b/test/SPAWN.py
index 6802524..fba21d5 100644
--- a/test/SPAWN.py
+++ b/test/SPAWN.py
@@ -36,10 +36,10 @@ test = TestSCons.TestSCons()
test.write('cat.py', """\
import sys
-ofp = open(sys.argv[1], 'wb')
-for s in sys.argv[2:]:
- ofp.write(open(s, 'rb').read())
-ofp.close()
+with open(sys.argv[1], 'wb') as ofp:
+ for s in sys.argv[2:]:
+ with open(s, 'rb') as ifp:
+ ofp.write(ifp.read())
""")
test.write('SConstruct', """
diff --git a/test/Scanner/FindPathDirs.py b/test/Scanner/FindPathDirs.py
index c56f448..34eb779 100644
--- a/test/Scanner/FindPathDirs.py
+++ b/test/Scanner/FindPathDirs.py
@@ -41,8 +41,6 @@ test.write('build.py', r"""
import os.path
import sys
path = sys.argv[1].split()
-input = open(sys.argv[2], 'r')
-output = open(sys.argv[3], 'w')
def find_file(f):
for dir in path:
@@ -55,11 +53,13 @@ def process(infp, outfp):
for line in infp.readlines():
if line[:8] == 'include ':
file = line[8:-1]
- process(find_file(file), outfp)
+ with find_file(file) as f:
+ process(f, outfp)
else:
outfp.write(line)
-process(input, output)
+with open(sys.argv[2], 'r') as ifp, open(sys.argv[3], 'w') as ofp:
+ process(ifp, ofp)
sys.exit(0)
""")
diff --git a/test/Scanner/Scanner.py b/test/Scanner/Scanner.py
index e5516bd..272f26a 100644
--- a/test/Scanner/Scanner.py
+++ b/test/Scanner/Scanner.py
@@ -33,14 +33,13 @@ test = TestSCons.TestSCons()
test.write('build.py', r"""
import sys
-input = open(sys.argv[1], 'r')
-output = open(sys.argv[2], 'w')
def process(infp, outfp):
for line in infp.readlines():
if line[:8] == 'include ':
file = line[8:-1]
- process(open(file, 'r'), outfp)
+ with open(file, 'r') as f:
+ process(f, outfp)
elif line[:8] == 'getfile ':
outfp.write('include ')
outfp.write(line[8:])
@@ -48,7 +47,8 @@ def process(infp, outfp):
else:
outfp.write(line)
-process(input, output)
+with open(sys.argv[1], 'r') as ifp, open(sys.argv[2], 'w') as ofp:
+ process(ifp, ofp)
sys.exit(0)
""", mode='w')
@@ -118,7 +118,8 @@ def third(env, target, source):
contents = source[0].get_contents()
# print("TYPE:"+str(type(contents)))
contents = contents.replace(b'getfile', b'MISSEDME')
- open(str(target[0]), 'wb').write(contents)
+ with open(str(target[0]), 'wb') as f:
+ f.write(contents)
kbld = Builder(action=r'%(_python_)s build.py $SOURCES $TARGET',
src_suffix='.first',
diff --git a/test/Scanner/dictionary.py b/test/Scanner/dictionary.py
index c587098..efe3cd2 100644
--- a/test/Scanner/dictionary.py
+++ b/test/Scanner/dictionary.py
@@ -36,8 +36,6 @@ test = TestSCons.TestSCons()
test.write('build.py', r"""
import sys
-input = open(sys.argv[1], 'r')
-output = open(sys.argv[2], 'w')
include_prefix = 'include%s ' % sys.argv[1][-1]
@@ -45,11 +43,13 @@ def process(infp, outfp):
for line in infp.readlines():
if line[:len(include_prefix)] == include_prefix:
file = line[len(include_prefix):-1]
- process(open(file, 'r'), outfp)
+ with open(file, 'r') as f:
+ process(f, outfp)
else:
outfp.write(line)
-process(input, output)
+with open(sys.argv[2], 'w') as ofp, open(sys.argv[1], 'r') as ifp:
+ process(ifp, ofp)
sys.exit(0)
""")
diff --git a/test/Scanner/empty-implicit.py b/test/Scanner/empty-implicit.py
index 8d9a47d..a1e7b03 100644
--- a/test/Scanner/empty-implicit.py
+++ b/test/Scanner/empty-implicit.py
@@ -53,7 +53,8 @@ def echo(env, target, source):
t = os.path.split(str(target[0]))[1]
s = os.path.split(str(source[0]))[1]
print('create %s from %s' % (t, s))
- open(t, 'wb').write(open(s, 'rb').read())
+ with open(t, 'wb') as ofb, open(s, 'rb') as ifb:
+ ofb.write(ifb.read())
Echo = Builder(action = Action(echo, None),
src_suffix = '.x',
diff --git a/test/Scanner/exception.py b/test/Scanner/exception.py
index 1a14152..ec19842 100644
--- a/test/Scanner/exception.py
+++ b/test/Scanner/exception.py
@@ -61,16 +61,17 @@ def process(outf, inf):
for line in inf.readlines():
if line[:8] == 'include ':
file = line[8:-1]
- process(outf, open(file, 'rb'))
+ with open(file, 'rb') as ifp:
+ process(outf, ifp)
else:
outf.write(line)
def cat(env, source, target):
target = str(target[0])
- outf = open(target, 'wb')
- for src in source:
- process(outf, open(str(src), 'rb'))
- outf.close()
+ with open(target, 'wb') as outf:
+ for src in source:
+ with open(str(src), 'rb') as inf:
+ process(outf, inf)
env = Environment(BUILDERS={'Cat':Builder(action=cat)})
env.Append(SCANNERS = [kscan])
diff --git a/test/Scanner/generated.py b/test/Scanner/generated.py
index 3e08549..5e808e1 100644
--- a/test/Scanner/generated.py
+++ b/test/Scanner/generated.py
@@ -245,7 +245,7 @@ lib_name = "g"
lib_fullname = env.subst("${LIBPREFIX}g${LIBSUFFIX}")
lib_srcs = "libg_1.c libg_2.c libg_3.c".split()
import re
-lib_objs = [re.sub("\.c$", ".o", x) for x in lib_srcs]
+lib_objs = [re.sub(r"\.c$", ".o", x) for x in lib_srcs]
Mylib.ExportHeader(env, exported_hdrs)
Mylib.ExportLib(env, lib_fullname)
@@ -259,7 +259,7 @@ Mylib.ExportLib(env, lib_fullname)
#cmd_generated = "cd %s ; sh MAKE-HEADER.sh" % Dir(".")
#cmd_justlib = "cd %s ; make" % Dir(".")
-_ws = re.compile('\s')
+_ws = re.compile(r'\s')
def escape(s):
if _ws.search(s):
@@ -294,7 +294,8 @@ import sys
os.chdir(os.path.split(sys.argv[0])[0])
for h in ['libg_gx.h', 'libg_gy.h', 'libg_gz.h']:
- open(h, 'w').write('')
+ with open(h, 'w') as f:
+ f.write('')
""" % locals())
test.write(['src', 'lib_geng', 'SConstruct'], """\
@@ -302,12 +303,11 @@ import os
Scanned = {}
-def write_out(file, dict):
- f = open(file, 'w')
- for k in sorted(dict.keys()):
- file = os.path.split(k)[1]
- f.write(file + ": " + str(dict[k]) + "\\n")
- f.close()
+def write_out(fname, dict):
+ with open(fname, 'w') as f:
+ for k in sorted(dict.keys()):
+ name = os.path.split(k)[1]
+ f.write(name + ": " + str(dict[k]) + "\\n")
# A hand-coded new-style class proxy to wrap the underlying C Scanner
# with a method that counts the calls.
diff --git a/test/Scanner/multi-env.py b/test/Scanner/multi-env.py
index 9cf86dc..1cc85d0 100644
--- a/test/Scanner/multi-env.py
+++ b/test/Scanner/multi-env.py
@@ -72,12 +72,13 @@ def process(infp, outfp):
l = len(prefix)
for line in infp.readlines():
if line[:l] == prefix:
- process(open(line[l:-1], 'r'), outfp)
+ with open(line[l:-1], 'r') as f:
+ process(f, outfp)
else:
outfp.write(line)
-process(open(sys.argv[2], 'r'),
- open(sys.argv[1], 'w'))
+with open(sys.argv[2], 'r') as ifp, open(sys.argv[1], 'w') as ofp:
+ process(ifp, ofp)
sys.exit(0)
"""
diff --git a/test/Scanner/no-Dir-node.py b/test/Scanner/no-Dir-node.py
index 69b665a..a230ea6 100644
--- a/test/Scanner/no-Dir-node.py
+++ b/test/Scanner/no-Dir-node.py
@@ -54,8 +54,6 @@ test.write('build.py', r"""
import os.path
import sys
path = sys.argv[1].split()
-input = open(sys.argv[2], 'r')
-output = open(sys.argv[3], 'w')
def find_file(f):
if os.path.isabs(f):
@@ -69,12 +67,14 @@ def find_file(f):
def process(infp, outfp):
for line in infp.readlines():
if line[:8] == 'include ':
- file = line[8:-1]
- process(find_file(file), outfp)
+ fname = line[8:-1]
+ with find_file(fname) as f:
+ process(f, outfp)
else:
outfp.write(line)
-process(input, output)
+with open(sys.argv[2], 'r') as ifp, open(sys.argv[3], 'w') as ofp:
+ process(ifp, ofp)
sys.exit(0)
""")
diff --git a/test/Scanner/source_scanner-dict.py b/test/Scanner/source_scanner-dict.py
index 47773b8..f719f00 100644
--- a/test/Scanner/source_scanner-dict.py
+++ b/test/Scanner/source_scanner-dict.py
@@ -39,21 +39,21 @@ test = TestSCons.TestSCons()
test.write('build.py', r"""
import sys
-output = open(sys.argv[1], 'w')
-for infile in sys.argv[2:]:
- input = open(infile, 'r')
-
- include_prefix = 'include%s ' % infile[-1]
-
- def process(infp, outfp, include_prefix=include_prefix):
- for line in infp.readlines():
- if line[:len(include_prefix)] == include_prefix:
- file = line[len(include_prefix):-1]
- process(open(file, 'r'), outfp)
- else:
- outfp.write(line)
-
- process(input, output)
+with open(sys.argv[1], 'w') as ofp:
+ for infile in sys.argv[2:]:
+ with open(infile, 'r') as ifp:
+ include_prefix = 'include%s ' % infile[-1]
+
+ def process(infp, outfp, include_prefix=include_prefix):
+ for line in infp.readlines():
+ if line[:len(include_prefix)] == include_prefix:
+ file = line[len(include_prefix):-1]
+ with open(file, 'r') as f:
+ process(f, outfp)
+ else:
+ outfp.write(line)
+
+ process(ifp, ofp)
sys.exit(0)
""")
diff --git a/test/Scanner/unicode.py b/test/Scanner/unicode.py
index 96010de..227c72e 100644
--- a/test/Scanner/unicode.py
+++ b/test/Scanner/unicode.py
@@ -49,7 +49,8 @@ import codecs
import sys
def process(outfp, infile):
- contents = open(infile, 'rb').read()
+ with open(infile, 'rb') as f:
+ contents = f.read()
if contents[:len(codecs.BOM_UTF8)] == codecs.BOM_UTF8:
contents = contents[len(codecs.BOM_UTF8):].decode('utf-8')
elif contents[:len(codecs.BOM_UTF16_LE)] == codecs.BOM_UTF16_LE:
@@ -70,8 +71,8 @@ def process(outfp, infile):
else:
outfp.write(line + '\n')
-output = open(sys.argv[2], 'w')
-process(output, sys.argv[1])
+with open(sys.argv[2], 'w') as ofp:
+ process(ofp, sys.argv[1])
sys.exit(0)
""")
diff --git a/test/SideEffect/directory.py b/test/SideEffect/directory.py
index 23f50af..9fcbea2 100644
--- a/test/SideEffect/directory.py
+++ b/test/SideEffect/directory.py
@@ -37,7 +37,8 @@ import os.path
import os
def copy(source, target):
- open(target, "wb").write(open(source, "rb").read())
+ with open(target, "wb") as ofp, open(source, "rb") as ifp:
+ ofp.write(ifp.read())
def build(env, source, target):
copy(str(source[0]), str(target[0]))
diff --git a/test/SideEffect/parallel.py b/test/SideEffect/parallel.py
index 63538f3..7ec53b3 100644
--- a/test/SideEffect/parallel.py
+++ b/test/SideEffect/parallel.py
@@ -52,7 +52,8 @@ except OSError as e:
src, target = sys.argv[1:]
-open(logfile, 'ab').write(('%s -> %s\\n' % (src, target)).encode())
+with open(logfile, 'ab') as f:
+ f.write(('%s -> %s\\n' % (src, target)).encode())
# Give the other threads a chance to start.
time.sleep(1)
diff --git a/test/Subst/null-sources-attr.py b/test/Subst/null-sources-attr.py
index 64a0b5b..729aa99 100644
--- a/test/Subst/null-sources-attr.py
+++ b/test/Subst/null-sources-attr.py
@@ -37,10 +37,10 @@ test = TestSCons.TestSCons()
test.write('cat.py', """\
import sys
-fp = open(sys.argv[1], 'wb')
-for infile in sys.argv[2:]:
- fp.write(open(infile, 'rb').read())
-fp.close()
+with open(sys.argv[1], 'wb') as ofp:
+ for infile in sys.argv[2:]:
+ with open(infile, 'rb') as ifp:
+ ofp.write(ifp.read())
sys.exit(0)
""")
diff --git a/test/TAR/TAR.py b/test/TAR/TAR.py
index 65e6182..159f047 100644
--- a/test/TAR/TAR.py
+++ b/test/TAR/TAR.py
@@ -42,16 +42,18 @@ import sys
opts, args = getopt.getopt(sys.argv[1:], 'cf:')
for opt, arg in opts:
if opt == '-f': out = arg
+
def process(outfile, name):
if os.path.isdir(name):
for entry in sorted(os.listdir(name)):
process(outfile, os.path.join(name, entry))
else:
- outfile.write(open(name, 'r').read())
-outfile = open(out, 'w')
-for infile in args:
- process(outfile, infile)
-outfile.close()
+ with open(name, 'r') as ifp:
+ outfile.write(ifp.read())
+
+with open(out, 'w') as ofp:
+ for infile in args:
+ process(ofp, infile)
sys.exit(0)
""")
diff --git a/test/TAR/TARFLAGS.py b/test/TAR/TARFLAGS.py
index e1eae0f..29a1866 100644
--- a/test/TAR/TARFLAGS.py
+++ b/test/TAR/TARFLAGS.py
@@ -44,17 +44,19 @@ opt_string = ''
for opt, arg in cmd_opts:
if opt == '-f': out = arg
else: opt_string = opt_string + ' ' + opt
+
def process(outfile, name):
if os.path.isdir(name):
for entry in sorted(os.listdir(name)):
process(outfile, os.path.join(name, entry))
else:
- outfile.write(open(name, 'r').read())
-outfile = open(out, 'w')
-outfile.write('options: %s\\n' % opt_string)
-for infile in args:
- process(outfile, infile)
-outfile.close()
+ with open(name, 'r') as ifp:
+ outfile.write(ifp.read())
+
+with open(out, 'w') as ofp:
+ ofp.write('options: %s\\n' % opt_string)
+ for infile in args:
+ process(ofp, infile)
sys.exit(0)
""")
diff --git a/test/TARGET-dir.py b/test/TARGET-dir.py
index 9e99087..652cf77 100644
--- a/test/TARGET-dir.py
+++ b/test/TARGET-dir.py
@@ -43,9 +43,10 @@ test.subdir('src', 'build1', 'build2')
test.write('SConstruct', """
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
+ with open(target, "wb") as f:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ f.write(ifp.read())
f.close()
env = Environment(CPPPATH='${TARGET.dir}')
env.Append(BUILDERS = {'Cat' : Builder(action=cat)})
diff --git a/test/TEX/LATEX.py b/test/TEX/LATEX.py
index dc5e535..553313e 100644
--- a/test/TEX/LATEX.py
+++ b/test/TEX/LATEX.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that we can set the LATEX string to our own utility, that
the produced .dvi, .aux and .log files get removed by the -c option,
and that we can use this to wrap calls to the real latex utility.
@@ -44,15 +44,16 @@ import os
import getopt
cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
-infile = open(arg[0], 'r')
-dvi_file = open(base_name+'.dvi', 'w')
-aux_file = open(base_name+'.aux', 'w')
-log_file = open(base_name+'.log', 'w')
-for l in infile.readlines():
- if l[0] != '\\':
- dvi_file.write(l)
- aux_file.write(l)
- log_file.write(l)
+with open(arg[0], 'r') as ifp:
+ with open(base_name+'.dvi', 'w') as dvi_file, \
+ open(base_name+'.aux', 'w') as aux_file, \
+ open(base_name+'.log', 'w') as log_file:
+
+ for l in ifp.readlines():
+ if l[0] != '\\':
+ dvi_file.write(l)
+ aux_file.write(l)
+ log_file.write(l)
sys.exit(0)
""")
diff --git a/test/TEX/LATEX2.py b/test/TEX/LATEX2.py
index 566f164..a3ac125 100644
--- a/test/TEX/LATEX2.py
+++ b/test/TEX/LATEX2.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that we can produce several .pdf at once from several sources.
"""
diff --git a/test/TEX/LATEXCOM.py b/test/TEX/LATEXCOM.py
index 878d4cf..8ea87c8 100644
--- a/test/TEX/LATEXCOM.py
+++ b/test/TEX/LATEXCOM.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test the ability to configure the $LATEXCOM construction variable.
"""
diff --git a/test/TEX/LATEXCOMSTR.py b/test/TEX/LATEXCOMSTR.py
index f8a377d..41c5dc7 100644
--- a/test/TEX/LATEXCOMSTR.py
+++ b/test/TEX/LATEXCOMSTR.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test that the $LATEXCOMSTR construction variable allows you to configure
the C compilation output.
"""
diff --git a/test/TEX/LATEXFLAGS.py b/test/TEX/LATEXFLAGS.py
index 48cfa9c..5e8b4af 100644
--- a/test/TEX/LATEXFLAGS.py
+++ b/test/TEX/LATEXFLAGS.py
@@ -43,12 +43,11 @@ opt_string = ''
for opt, arg in cmd_opts:
opt_string = opt_string + ' ' + opt
base_name = os.path.splitext(args[0])[0]
-infile = open(args[0], 'r')
-out_file = open(base_name+'.dvi', 'w')
-out_file.write(opt_string + "\n")
-for l in infile.readlines():
- if l[0] != '\\':
- out_file.write(l)
+with open(base_name+'.dvi', 'w') as ofp, open(args[0], 'r') as ifp:
+ ofp.write(opt_string + "\n")
+ for l in ifp.readlines():
+ if l[0] != '\\':
+ ofp.write(l)
sys.exit(0)
""")
diff --git a/test/TEX/PDFLATEX.py b/test/TEX/PDFLATEX.py
index dece385..a350b28 100644
--- a/test/TEX/PDFLATEX.py
+++ b/test/TEX/PDFLATEX.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that we can set the PDFLATEX string to our own utility, that
the produced .dvi, .aux and .log files get removed by the -c option,
and that we can use this to wrap calls to the real latex utility.
@@ -44,15 +44,16 @@ import os
import getopt
cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
-infile = open(arg[0], 'rb')
-pdf_file = open(base_name+'.pdf', 'wb')
-aux_file = open(base_name+'.aux', 'wb')
-log_file = open(base_name+'.log', 'wb')
-for l in infile.readlines():
- if l[0] != '\\':
- pdf_file.write(l)
- aux_file.write(l)
- log_file.write(l)
+with open(arg[0], 'r') as ifp:
+ with open(base_name+'.pdf', 'w') as pdf_file, \
+ open(base_name+'.aux', 'w') as aux_file, \
+ open(base_name+'.log', 'w') as log_file:
+
+ for l in ifp.readlines():
+ if l[0] != '\\':
+ pdf_file.write(l)
+ aux_file.write(l)
+ log_file.write(l)
sys.exit(0)
""")
diff --git a/test/TEX/PDFLATEXCOM.py b/test/TEX/PDFLATEXCOM.py
index c2b54ce..5e9d68d 100644
--- a/test/TEX/PDFLATEXCOM.py
+++ b/test/TEX/PDFLATEXCOM.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test the ability to configure the $PDFLATEXCOM construction variable.
"""
diff --git a/test/TEX/PDFLATEXCOMSTR.py b/test/TEX/PDFLATEXCOMSTR.py
index 1d911bd..d695bde 100644
--- a/test/TEX/PDFLATEXCOMSTR.py
+++ b/test/TEX/PDFLATEXCOMSTR.py
@@ -1,4 +1,3 @@
-
#!/usr/bin/env python
#
# __COPYRIGHT__
@@ -25,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test that the $PDFLATEXCOMSTR construction variable allows you to configure
the C compilation output.
"""
diff --git a/test/TEX/PDFLATEXFLAGS.py b/test/TEX/PDFLATEXFLAGS.py
index 47643e4..9bea1f0 100644
--- a/test/TEX/PDFLATEXFLAGS.py
+++ b/test/TEX/PDFLATEXFLAGS.py
@@ -43,12 +43,11 @@ opt_string = ''
for opt, arg in cmd_opts:
opt_string = opt_string + ' ' + opt
base_name = os.path.splitext(args[0])[0]
-infile = open(args[0], 'r')
-out_file = open(base_name+'.pdf', 'w')
-out_file.write(opt_string + "\n")
-for l in infile.readlines():
- if l[0] != '\\':
- out_file.write(l)
+with open(base_name+'.pdf', 'w') as ofp, open(args[0], 'r') as ifp:
+ ofp.write(opt_string + "\n")
+ for l in ifp.readlines():
+ if l[0] != '\\':
+ ofp.write(l)
sys.exit(0)
""")
diff --git a/test/TEX/PDFTEX.py b/test/TEX/PDFTEX.py
index 5a958d5..0309fce 100644
--- a/test/TEX/PDFTEX.py
+++ b/test/TEX/PDFTEX.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that we can set the PDFTEX string to our own utility, that
the produced .dvi, .aux and .log files get removed by the -c option,
and that we can use this to wrap calls to the real latex utility.
@@ -44,15 +44,16 @@ import os
import getopt
cmd_opts, arg = getopt.getopt(sys.argv[2:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
-infile = open(arg[0], 'rb')
-pdf_file = open(base_name+'.pdf', 'wb')
-aux_file = open(base_name+'.aux', 'wb')
-log_file = open(base_name+'.log', 'wb')
-for l in infile.readlines():
- if l[0] != '\\':
- pdf_file.write(l)
- aux_file.write(l)
- log_file.write(l)
+with open(arg[0], 'r') as ifp:
+ with open(base_name+'.pdf', 'w') as pdf_file, \
+ open(base_name+'.aux', 'w') as aux_file, \
+ open(base_name+'.log', 'w') as log_file:
+
+ for l in ifp.readlines():
+ if l[0] != '\\':
+ pdf_file.write(l)
+ aux_file.write(l)
+ log_file.write(l)
sys.exit(0)
""")
diff --git a/test/TEX/PDFTEXCOM.py b/test/TEX/PDFTEXCOM.py
index 6e915a4..fd0ba69 100644
--- a/test/TEX/PDFTEXCOM.py
+++ b/test/TEX/PDFTEXCOM.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test the ability to configure the $PDFTEXCOM construction variable.
"""
diff --git a/test/TEX/PDFTEXCOMSTR.py b/test/TEX/PDFTEXCOMSTR.py
index 7ee5b41..50edd28 100644
--- a/test/TEX/PDFTEXCOMSTR.py
+++ b/test/TEX/PDFTEXCOMSTR.py
@@ -1,4 +1,3 @@
-
#!/usr/bin/env python
#
# __COPYRIGHT__
@@ -25,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test that the $PDFTEXCOMSTR construction variable allows you to configure
the C compilation output.
"""
diff --git a/test/TEX/PDFTEXFLAGS.py b/test/TEX/PDFTEXFLAGS.py
index 97b352e..c9fcdca 100644
--- a/test/TEX/PDFTEXFLAGS.py
+++ b/test/TEX/PDFTEXFLAGS.py
@@ -43,12 +43,11 @@ opt_string = ''
for opt, arg in cmd_opts:
opt_string = opt_string + ' ' + opt
base_name = os.path.splitext(args[0])[0]
-infile = open(args[0], 'r')
-out_file = open(base_name+'.pdf', 'w')
-out_file.write(opt_string + "\n")
-for l in infile.readlines():
- if l[0] != '\\':
- out_file.write(l)
+with open(base_name+'.pdf', 'w') as ofp, open(args[0], 'r') as ifp:
+ ofp.write(opt_string + "\n")
+ for l in ifp.readlines():
+ if l[0] != '\\':
+ ofp.write(l)
sys.exit(0)
""")
diff --git a/test/TEX/PDF_single_source.py b/test/TEX/PDF_single_source.py
index aefdd3e..cd11234 100644
--- a/test/TEX/PDF_single_source.py
+++ b/test/TEX/PDF_single_source.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test creation of a mulitple pdf's from a list of PostScript files.
Test courtesy Rob Managan.
@@ -108,7 +108,7 @@ $F2psBegin
0.06299 0.06299 sc
%
% Fig objects follow
-%
+%
7.500 slw
% Ellipse
n 1170 945 766 766 0 360 DrawEllipse gs col0 s gr
diff --git a/test/TEX/TEX.py b/test/TEX/TEX.py
index 7b20106..3964eb8 100644
--- a/test/TEX/TEX.py
+++ b/test/TEX/TEX.py
@@ -24,7 +24,7 @@ from __future__ import print_function
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that we can set the TEX string to our own utility, that
the produced .dvi, .aux and .log files get removed by the -c option,
and that we can use this to wrap calls to the real latex utility.
@@ -47,15 +47,16 @@ import os
import getopt
cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
-infile = open(arg[0], 'r')
-dvi_file = open(base_name+'.dvi', 'w')
-aux_file = open(base_name+'.aux', 'w')
-log_file = open(base_name+'.log', 'w')
-for l in infile.readlines():
- if l[0] != '\\':
- dvi_file.write(l)
- aux_file.write(l)
- log_file.write(l)
+with open(arg[0], 'r') as ifp:
+ with open(base_name+'.dvi', 'w') as dvi_file, \
+ open(base_name+'.aux', 'w') as aux_file, \
+ open(base_name+'.log', 'w') as log_file:
+
+ for l in ifp.readlines():
+ if l[0] != '\\':
+ dvi_file.write(l)
+ aux_file.write(l)
+ log_file.write(l)
sys.exit(0)
""")
diff --git a/test/TEX/TEXCOM.py b/test/TEX/TEXCOM.py
index 9d820bc..10da59e 100644
--- a/test/TEX/TEXCOM.py
+++ b/test/TEX/TEXCOM.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test the ability to configure the $TEXCOM construction variable.
"""
diff --git a/test/TEX/TEXCOMSTR.py b/test/TEX/TEXCOMSTR.py
index 0facc6f..9dbba13 100644
--- a/test/TEX/TEXCOMSTR.py
+++ b/test/TEX/TEXCOMSTR.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test that the $TEXCOMSTR construction variable allows you to configure
the C compilation output.
"""
diff --git a/test/TEX/TEXFLAGS.py b/test/TEX/TEXFLAGS.py
index 7b4fd15..287b537 100644
--- a/test/TEX/TEXFLAGS.py
+++ b/test/TEX/TEXFLAGS.py
@@ -43,12 +43,11 @@ opt_string = ''
for opt, arg in cmd_opts:
opt_string = opt_string + ' ' + opt
base_name = os.path.splitext(args[0])[0]
-infile = open(args[0], 'r')
-out_file = open(base_name+'.dvi', 'w')
-out_file.write(opt_string + "\n")
-for l in infile.readlines():
- if l[0] != '\\':
- out_file.write(l)
+with open(base_name+'.dvi', 'w') as ofp, open(args[0], 'r') as ifp:
+ ofp.write(opt_string + "\n")
+ for l in ifp.readlines():
+ if l[0] != '\\':
+ ofp.write(l)
sys.exit(0)
""")
diff --git a/test/TEX/auxiliaries.py b/test/TEX/auxiliaries.py
index 8d220c5..e28c212 100644
--- a/test/TEX/auxiliaries.py
+++ b/test/TEX/auxiliaries.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Verify that sections of LaTeX output that use auxiliary files (a
bibliography in our configuration below) are consistent when re-run
after modifying the input file.
diff --git a/test/TEX/biber_biblatex.py b/test/TEX/biber_biblatex.py
index b4a4969..6ee8121 100755
--- a/test/TEX/biber_biblatex.py
+++ b/test/TEX/biber_biblatex.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test creation of a Tex document that uses the multibib oackage
Test courtesy Rob Managan.
diff --git a/test/TEX/biber_biblatex2.py b/test/TEX/biber_biblatex2.py
index e9893ee..61fafcf 100644
--- a/test/TEX/biber_biblatex2.py
+++ b/test/TEX/biber_biblatex2.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test creation of a Tex document that uses the biblatex package
It uses the default backend, could be bibtex or biber.
Require both be installed
diff --git a/test/TEX/biblatex.py b/test/TEX/biblatex.py
index 21e1a93..bb88aaa 100755
--- a/test/TEX/biblatex.py
+++ b/test/TEX/biblatex.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test creation of a Tex document that uses the biblatex package
Test courtesy Rob Managan.
diff --git a/test/TEX/biblatex_plain.py b/test/TEX/biblatex_plain.py
index 06b3cc6..5cad924 100644
--- a/test/TEX/biblatex_plain.py
+++ b/test/TEX/biblatex_plain.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test creation of a Tex document that uses the biblatex package
Test courtesy Rob Managan.
diff --git a/test/TEX/bibliography.py b/test/TEX/bibliography.py
index 9e79320..a8032db 100644
--- a/test/TEX/bibliography.py
+++ b/test/TEX/bibliography.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that use of \bibliography in TeX source files causes SCons to
be aware of the necessary created bibliography files.
@@ -48,7 +48,7 @@ have_latex = test.where_is('latex')
if not have_latex:
test.skip_test('Could not find latex; skipping test(s).\n')
-
+
test.write('SConstruct', """\
import os
env = Environment(tools = ['tex', 'latex', 'dvips'])
diff --git a/test/TEX/bibtex-latex-rerun.py b/test/TEX/bibtex-latex-rerun.py
index a2538f1..300f03b 100644
--- a/test/TEX/bibtex-latex-rerun.py
+++ b/test/TEX/bibtex-latex-rerun.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Verify that we re-run LaTeX after running BibTeX in response to
changes in a .bib file.
diff --git a/test/TEX/clean.py b/test/TEX/clean.py
index b0e5ee4..ad828d2 100644
--- a/test/TEX/clean.py
+++ b/test/TEX/clean.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Check that all auxilary files created by LaTeX are properly cleaned by scons -c.
"""
diff --git a/test/TEX/configure.py b/test/TEX/configure.py
index 60ebb9c..763f86f 100644
--- a/test/TEX/configure.py
+++ b/test/TEX/configure.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Verify execution of custom test case.
The old code base would not be able to fail the test
"""
diff --git a/test/TEX/dryrun.py b/test/TEX/dryrun.py
index 308e167..4265791 100644
--- a/test/TEX/dryrun.py
+++ b/test/TEX/dryrun.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that we can set the LATEX string to our own utility, that
the produced .dvi, .aux and .log files get removed by the -c option,
and that we can use this to wrap calls to the real latex utility.
diff --git a/test/TEX/eps_graphics.py b/test/TEX/eps_graphics.py
index e0a8731..9e36148 100644
--- a/test/TEX/eps_graphics.py
+++ b/test/TEX/eps_graphics.py
@@ -24,8 +24,8 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
-Test creation of a Tex document with nested includes in a
+r"""
+Test creation of a Tex document with nested includes in a
subdir that needs to create a fig.pdf.
Test courtesy Rob Managan.
@@ -115,7 +115,7 @@ $F2psBegin
0.06299 0.06299 sc
%
% Fig objects follow
-%
+%
7.500 slw
% Ellipse
n 1170 945 766 766 0 360 DrawEllipse gs col0 s gr
@@ -133,13 +133,13 @@ r"""\documentclass{report}
\usepackage{epsfig,color} % for .tex version of figures if we go that way
\begin{document}
-
+
\title{Report Title}
\author{A. N. Author}
-
-\maketitle
-
+
+\maketitle
+
\begin{abstract}
there is no abstract
\end{abstract}
@@ -150,7 +150,7 @@ The introduction is short.
\section{Acknowledgements}
-The Acknowledgements are shown as well.
+The Acknowledgements are shown as well.
To get a hard copy of this report call me.
diff --git a/test/TEX/eps_graphics2.py b/test/TEX/eps_graphics2.py
index e523df7..19ea98b 100644
--- a/test/TEX/eps_graphics2.py
+++ b/test/TEX/eps_graphics2.py
@@ -24,8 +24,8 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
-Test creation of a Tex document with nested includes in a
+r"""
+Test creation of a Tex document with nested includes in a
subdir that needs to create a fig.pdf.
Test creation with pdflatex
@@ -117,7 +117,7 @@ $F2psBegin
0.06299 0.06299 sc
%
% Fig objects follow
-%
+%
7.500 slw
% Ellipse
n 1170 945 766 766 0 360 DrawEllipse gs col0 s gr
@@ -135,13 +135,13 @@ r"""\documentclass{report}
\usepackage{epsfig,color} % for .tex version of figures if we go that way
\begin{document}
-
+
\title{Report Title}
\author{A. N. Author}
-
-\maketitle
-
+
+\maketitle
+
\begin{abstract}
there is no abstract
\end{abstract}
@@ -152,14 +152,14 @@ The introduction is short.
\section{Acknowledgements}
-The Acknowledgements are shown as well.
+The Acknowledgements are shown as well.
To get a hard copy of this report call me.
\begin{figure}[htbp]
\begin{center}
-\includegraphics
- [width=.5\textwidth]
+\includegraphics
+ [width=.5\textwidth]
{Fig1}
\caption{Zone and Node indexing}
\label{fig1}
diff --git a/test/TEX/generated_files.py b/test/TEX/generated_files.py
index 0325154..9bafc9b 100644
--- a/test/TEX/generated_files.py
+++ b/test/TEX/generated_files.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test creation of a Tex document with generated tex files
This checks whether the .bbl file is kept as a side effect
Test creation with pdflatex
diff --git a/test/TEX/glossaries.py b/test/TEX/glossaries.py
index 05ddf12..21180a0 100644
--- a/test/TEX/glossaries.py
+++ b/test/TEX/glossaries.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that use of \glossaries in TeX source files causes SCons to
be aware of the necessary created glossary files.
diff --git a/test/TEX/glossary.py b/test/TEX/glossary.py
index be0a870..0becb40 100644
--- a/test/TEX/glossary.py
+++ b/test/TEX/glossary.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that use of \glossary in TeX source files causes SCons to
be aware of the necessary created glossary files.
diff --git a/test/TEX/input_docClass.py b/test/TEX/input_docClass.py
index 3fa2b08..413cba5 100644
--- a/test/TEX/input_docClass.py
+++ b/test/TEX/input_docClass.py
@@ -24,9 +24,9 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test creation of a LaTeX document that uses \input{filename}
-to set the documentclass. When the file has .tex we have to search
+to set the documentclass. When the file has .tex we have to search
to find the documentclass command.
Test courtesy Rob Managan.
@@ -53,13 +53,13 @@ r"""
\input{theClass}
\begin{document}
-
+
\title{Report Title}
\author{A. N. Author}
-
-\maketitle
-
+
+\maketitle
+
\begin{abstract}
there is no abstract
\end{abstract}
@@ -73,7 +73,7 @@ The introduction is short.
\section{Acknowledgements}
-The Acknowledgements are shown as well.
+The Acknowledgements are shown as well.
\end{document}
""")
diff --git a/test/TEX/lstinputlisting.py b/test/TEX/lstinputlisting.py
index fcfe5a8..1d60df7 100644
--- a/test/TEX/lstinputlisting.py
+++ b/test/TEX/lstinputlisting.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Verify that we re-run LaTeX when a source file in \lstinputlisting
changes.
diff --git a/test/TEX/makeindex.py b/test/TEX/makeindex.py
index 638224a..960ed68 100644
--- a/test/TEX/makeindex.py
+++ b/test/TEX/makeindex.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that use of \makeindex in TeX source files causes SCons to be
aware of the necessary created index files.
diff --git a/test/TEX/multi-line_include_options.py b/test/TEX/multi-line_include_options.py
index 5266455..bb8a5f2 100644
--- a/test/TEX/multi-line_include_options.py
+++ b/test/TEX/multi-line_include_options.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
When an inclusion's optional argument (enclosed in square brackets:
[]) spans multiple lines (via comment wrapping), ensure that the LaTeX
Scanner doesn't throw an IndexError.
diff --git a/test/TEX/multi-run.py b/test/TEX/multi-run.py
index ff4e82a..9de0da4 100644
--- a/test/TEX/multi-run.py
+++ b/test/TEX/multi-run.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that both .tex and .ltx files can handle a LaTeX-style
bibliography (by calling $BIBTEX to generate a .bbl file) and
correctly re-run to resolve undefined references.
diff --git a/test/TEX/multibib.py b/test/TEX/multibib.py
index cdb9b87..114ade6 100644
--- a/test/TEX/multibib.py
+++ b/test/TEX/multibib.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test creation of a Tex document that uses the multibib oackage
Test courtesy Rob Managan.
diff --git a/test/TEX/multiple_include.py b/test/TEX/multiple_include.py
index 0480d45..76a95e2 100644
--- a/test/TEX/multiple_include.py
+++ b/test/TEX/multiple_include.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test creation of a fully-featured TeX document (with bibliography
and index) in a variant_dir.
@@ -116,7 +116,7 @@ $F2psBegin
0.06299 0.06299 sc
%
% Fig objects follow
-%
+%
7.500 slw
% Ellipse
n 1170 945 766 766 0 360 DrawEllipse gs col0 s gr
@@ -155,13 +155,13 @@ r"""\documentclass{report}
\makeindex
\begin{document}
-
+
\title{Report Title}
\author{A. N. Author}
-
-\maketitle
-
+
+\maketitle
+
\begin{abstract}
there is no abstract
\end{abstract}
@@ -177,7 +177,7 @@ The introduction is short.
\section{Acknowledgements}
-The Acknowledgements are shown as well.
+The Acknowledgements are shown as well.
\index{Getting the Report}
diff --git a/test/TEX/multiple_include_subdir.py b/test/TEX/multiple_include_subdir.py
index ade4713..589aa06 100644
--- a/test/TEX/multiple_include_subdir.py
+++ b/test/TEX/multiple_include_subdir.py
@@ -24,8 +24,8 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
-Test creation of a Tex document with nested includes in a
+r"""
+Test creation of a Tex document with nested includes in a
subdir that needs to create a fig.pdf.
Test courtesy Rob Managan.
@@ -116,7 +116,7 @@ $F2psBegin
0.06299 0.06299 sc
%
% Fig objects follow
-%
+%
7.500 slw
% Ellipse
n 1170 945 766 766 0 360 DrawEllipse gs col0 s gr
@@ -155,13 +155,13 @@ r"""\documentclass{report}
\makeindex
\begin{document}
-
+
\title{Report Title}
\author{A. N. Author}
-
-\maketitle
-
+
+\maketitle
+
\begin{abstract}
there is no abstract
\end{abstract}
@@ -177,7 +177,7 @@ The introduction is short.
\section{Acknowledgements}
-The Acknowledgements are shown as well.
+The Acknowledgements are shown as well.
\index{Getting the Report}
diff --git a/test/TEX/newglossary.py b/test/TEX/newglossary.py
index 12c68a7..faae7d3 100644
--- a/test/TEX/newglossary.py
+++ b/test/TEX/newglossary.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that use of \newglossary in TeX source files causes SCons to
be aware of the necessary created glossary files.
@@ -72,7 +72,7 @@ test.write('newglossary.tex', r"""
\newacronym{gnu}{GNU}{GNU's Not UNIX}
\makeglossaries
-\glstoctrue
+\glstoctrue
%\loadglsentries[\acronymtype]{chapters/acronyms}
\loadglsentries[symbol]{symbols}
%\loadglsentries[definition]{defns}
@@ -97,7 +97,7 @@ a definition \gls{defPower}
test.write('symbols.tex', r"""
-\newglossaryentry{mel}{name={Microelectronic Fundamentals},description={\nopostdesc},sort=d}
+\newglossaryentry{mel}{name={Microelectronic Fundamentals},description={\nopostdesc},sort=d}
\newsym{dynPower}{P_{dyn}}{P}{Dynamic power consumption}{mel}
%\newcommand{\newsym}[5]{\newglossaryentry{#1}{name=\ensuremath{#2},description={\symtab{#2}{#4}},parent={#5},sort={#3}}}
diff --git a/test/TEX/nomencl.py b/test/TEX/nomencl.py
index 1c121c0..7afb84b 100644
--- a/test/TEX/nomencl.py
+++ b/test/TEX/nomencl.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that use of \nomencl in TeX source files causes SCons to
be aware of the necessary created glossary files.
@@ -65,7 +65,7 @@ test.write('nomencl.tex', r"""
\begin{document}
-A nomenclature entry \nomenclature{gnu}{an animal or software group}
+A nomenclature entry \nomenclature{gnu}{an animal or software group}
and another\nomenclature{nix}{not sure}.
%handle old version of nomencl.sty
diff --git a/test/TEX/recursive_scanner_dependencies_import.py b/test/TEX/recursive_scanner_dependencies_import.py
index b31dfbe..c8c6569 100644
--- a/test/TEX/recursive_scanner_dependencies_import.py
+++ b/test/TEX/recursive_scanner_dependencies_import.py
@@ -24,14 +24,14 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""Verify that we re-run LaTeX after changing a nested \import. This
+r"""
+Verify that we re-run LaTeX after changing a nested \import. This
checks that recursive implicit dependencies are found correctly.
This is a separate test from the
recursive_scanner_dependencies_input.py test because \input and
\include are handled specially by the PDF builder, whereas \import
dependencies are found only by the scanner.
-
"""
import os
diff --git a/test/TEX/recursive_scanner_dependencies_input.py b/test/TEX/recursive_scanner_dependencies_input.py
index 257051e..5f37bf1 100644
--- a/test/TEX/recursive_scanner_dependencies_input.py
+++ b/test/TEX/recursive_scanner_dependencies_input.py
@@ -24,7 +24,8 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""Verify that we re-run LaTeX after changing a nested \input. This
+r"""
+Verify that we re-run LaTeX after changing a nested \input. This
checks that recursive implicit dependencies are found correctly.
"""
diff --git a/test/TEX/rename_result.py b/test/TEX/rename_result.py
index f061e26..b06d388 100644
--- a/test/TEX/rename_result.py
+++ b/test/TEX/rename_result.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that we can rename the output from latex to the
target name provided by the user.
"""
diff --git a/test/TEX/subdir-as-include.py b/test/TEX/subdir-as-include.py
index 8b897ca..bb3f2e5 100755
--- a/test/TEX/subdir-as-include.py
+++ b/test/TEX/subdir-as-include.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
This is an obscure test case. When
1) a file without a suffix is included in a TeX build and
2) there is a directory with the same name as that file,
diff --git a/test/TEX/subdir-input.py b/test/TEX/subdir-input.py
index 8c7febe..0d9311e 100644
--- a/test/TEX/subdir-input.py
+++ b/test/TEX/subdir-input.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Verify that we execute TeX in a subdirectory (if that's where the document
resides) by checking that all the auxiliary files get created there and
not in the top-level directory.
diff --git a/test/TEX/subdir_variantdir_include.py b/test/TEX/subdir_variantdir_include.py
index 7af3733..a7004b5 100644
--- a/test/TEX/subdir_variantdir_include.py
+++ b/test/TEX/subdir_variantdir_include.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Verify that we execute TeX in a subdirectory (if that's where the document
resides) by checking that all the auxiliary files get created there and
not in the top-level directory. Test this when variantDir is used
diff --git a/test/TEX/subdir_variantdir_include2.py b/test/TEX/subdir_variantdir_include2.py
index 4dbc4d2..5a0b49f 100644
--- a/test/TEX/subdir_variantdir_include2.py
+++ b/test/TEX/subdir_variantdir_include2.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Verify that we execute TeX in a subdirectory (if that's where the document
resides) by checking that all the auxiliary files get created there and
not in the top-level directory. Test this when variantDir is used
@@ -73,8 +73,8 @@ Hi there.
\end{document}
""")
-test.write(['docs','content','chapter.tex'], """\
-Sub-document 1
+test.write(['docs','content','chapter.tex'],
+r"""Sub-document 1
\input{content/subchap}
""")
@@ -87,8 +87,8 @@ Sub-chapter 2
#test.run(arguments = '.')
#test.run(arguments = '.', stderr=None, stdout=None)
-# next line tests that side effect nodes get disambiguated
-# and their directories created in a variantDir before
+# next line tests that side effect nodes get disambiguated
+# and their directories created in a variantDir before
# the builder tries to populate them and fails
test.run(arguments = 'build/main.pdf', stderr=None, stdout=None)
diff --git a/test/TEX/subdir_variantdir_input.py b/test/TEX/subdir_variantdir_input.py
index efc0692..c817c83 100644
--- a/test/TEX/subdir_variantdir_input.py
+++ b/test/TEX/subdir_variantdir_input.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Verify that we execute TeX in a subdirectory (if that's where the document
resides) by checking that all the auxiliary files get created there and
not in the top-level directory. Test this when variantDir is used
diff --git a/test/TEX/synctex.py b/test/TEX/synctex.py
index 867063a..f07db78 100644
--- a/test/TEX/synctex.py
+++ b/test/TEX/synctex.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that use of -synctex command option causes SCons to
be aware of the created synctex.gz file.
diff --git a/test/TEX/usepackage.py b/test/TEX/usepackage.py
index 637956a..0bb8c22 100644
--- a/test/TEX/usepackage.py
+++ b/test/TEX/usepackage.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate that we can set the LATEX string to our own utility, that
the produced .dvi, .aux and .log files get removed by the -c option,
and that we can use this to wrap calls to the real latex utility.
diff --git a/test/TEX/variant_dir.py b/test/TEX/variant_dir.py
index 99c3523..d81f542 100644
--- a/test/TEX/variant_dir.py
+++ b/test/TEX/variant_dir.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test creation of a fully-featured TeX document (with bibliography
and index) in a variant_dir.
@@ -122,7 +122,7 @@ $F2psBegin
0.06299 0.06299 sc
%
% Fig objects follow
-%
+%
7.500 slw
% Ellipse
n 1170 945 766 766 0 360 DrawEllipse gs col0 s gr
@@ -156,10 +156,10 @@ test.write(['docs', 'test.bib'], """\
%% http://bibdesk.sourceforge.net/
-%% Created for Rob Managan at 2006-11-15 12:53:16 -0800
+%% Created for Rob Managan at 2006-11-15 12:53:16 -0800
-%% Saved with string encoding Western (ASCII)
+%% Saved with string encoding Western (ASCII)
@@ -184,13 +184,13 @@ r"""\documentclass{report}
\makeindex
\begin{document}
-
+
\title{Report Title}
\author{A. N. Author}
-
-\maketitle
-
+
+\maketitle
+
\begin{abstract}
there is no abstract
\end{abstract}
@@ -206,7 +206,7 @@ The introduction is short.
\section{Acknowledgements}
-The Acknowledgements are show as well \cite{Managan:2006fk}.
+The Acknowledgements are show as well \cite{Managan:2006fk}.
\index{Getting the Report}
diff --git a/test/TEX/variant_dir_bibunit.py b/test/TEX/variant_dir_bibunit.py
index ce2c24e..cd3409e 100644
--- a/test/TEX/variant_dir_bibunit.py
+++ b/test/TEX/variant_dir_bibunit.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test creation of a fully-featured TeX document (with bibunit
driven bibliographies) in a variant_dir.
diff --git a/test/TEX/variant_dir_dup0.py b/test/TEX/variant_dir_dup0.py
index 25205f8..8f4334f 100644
--- a/test/TEX/variant_dir_dup0.py
+++ b/test/TEX/variant_dir_dup0.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test creation of a fully-featured TeX document (with bibliography
and index) in a variant_dir.
@@ -129,7 +129,7 @@ $F2psBegin
0.06299 0.06299 sc
%
% Fig objects follow
-%
+%
7.500 slw
% Ellipse
n 1170 945 766 766 0 360 DrawEllipse gs col0 s gr
@@ -162,7 +162,7 @@ test.write(['docs', 'test.bib'], """\
%% This BibTeX bibliography file was created using BibDesk.
%% http://bibdesk.sourceforge.net/
-%% Saved with string encoding Western (ASCII)
+%% Saved with string encoding Western (ASCII)
@techreport{AnAuthor:2006fk,
Author = {A. N. Author},
@@ -185,13 +185,13 @@ r"""\documentclass{report}
\makeindex
\begin{document}
-
+
\title{Report Title}
\author{A. N. Author}
-
-\maketitle
-
+
+\maketitle
+
\begin{abstract}
there is no abstract
\end{abstract}
@@ -207,7 +207,7 @@ The introduction is short.
\section{Acknowledgements}
-The Acknowledgements are show as well \cite{AnAuthor:2006fk}.
+The Acknowledgements are show as well \cite{AnAuthor:2006fk}.
\index{Getting the Report}
@@ -242,13 +242,13 @@ r"""\documentclass{report}
\makeindex
\begin{document}
-
+
\title{Report Title}
\author{A. N. Author}
-
-\maketitle
-
+
+\maketitle
+
\begin{abstract}
there is no abstract
\end{abstract}
@@ -264,7 +264,7 @@ The introduction is short.
\section{Acknowledgements}
-The Acknowledgements are show as well \cite{AnAuthor:2006fk}.
+The Acknowledgements are show as well \cite{AnAuthor:2006fk}.
\index{Getting the Report}
diff --git a/test/TEX/variant_dir_newglossary.py b/test/TEX/variant_dir_newglossary.py
index 5a28ed4..1e6ab43 100644
--- a/test/TEX/variant_dir_newglossary.py
+++ b/test/TEX/variant_dir_newglossary.py
@@ -24,9 +24,9 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Validate the use of \newglossary in TeX source files in conjunction
-with variant_dir.
+with variant_dir.
Test configuration contributed by Kendrick Boyd.
"""
@@ -104,6 +104,6 @@ files = [
for f in files:
test.must_exist(['build',f])
test.must_not_exist(['src',f])
-
+
test.pass_test()
diff --git a/test/TEX/variant_dir_style_dup0.py b/test/TEX/variant_dir_style_dup0.py
index 711086f..a9649b0 100644
--- a/test/TEX/variant_dir_style_dup0.py
+++ b/test/TEX/variant_dir_style_dup0.py
@@ -24,7 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-"""
+r"""
Test creation of a fully-featured TeX document (with bibliography
and index) in a variant_dir.
@@ -117,13 +117,13 @@ r"""
\makeindex
\begin{document}
-
+
\title{Report Title}
\author{A. N. Author}
-
-\maketitle
-
+
+\maketitle
+
\begin{abstract}
there is no abstract
\end{abstract}
@@ -139,7 +139,7 @@ The introduction is short.
\section{Acknowledgements}
-The Acknowledgements are show as well \cite{AnAuthor:2006fk}.
+The Acknowledgements are show as well \cite{AnAuthor:2006fk}.
\index{Getting the Report}
diff --git a/test/ToolSurrogate.py b/test/ToolSurrogate.py
index 0d3c6e7..0674db1 100644
--- a/test/ToolSurrogate.py
+++ b/test/ToolSurrogate.py
@@ -68,10 +68,10 @@ class ToolSurrogate(object):
def Cat(target, source, env):
target = str(target[0])
- f = open(target, "wb")
- for src in map(str, source):
- f.write(open(src, "rb").read())
- f.close()
+ with open(target, "wb") as ofp:
+ for src in map(str, source):
+ with open(src, "rb") as ifp:
+ ofp.write(ifp.read())
ToolList = {
'posix' : [('cc', 'CCCOM', Cat),
diff --git a/test/Touch.py b/test/Touch.py
index 7c1817a..431cd6c 100644
--- a/test/Touch.py
+++ b/test/Touch.py
@@ -39,10 +39,10 @@ Execute(Touch('f1'))
Execute(Touch(File('f1-File')))
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as f:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ f.write(ifp.read())
Cat = Action(cat)
env = Environment()
env.Command('f2.out', 'f2.in', [Cat, Touch("f3")])
diff --git a/test/Value.py b/test/Value.py
index 5a6a48e..c1f764a 100644
--- a/test/Value.py
+++ b/test/Value.py
@@ -63,7 +63,6 @@ def create_value (target, source, env):
target[0].write(source[0].get_contents())
def create_value_file (target, source, env):
- #open(str(target[0]), 'wb').write(source[0].read())
with open(str(target[0]), 'wb') as f:
f.write(source[0].read())
diff --git a/test/Variables/Variables.py b/test/Variables/Variables.py
index 0fe3745..09a17d5 100644
--- a/test/Variables/Variables.py
+++ b/test/Variables/Variables.py
@@ -231,7 +231,9 @@ opts.Save('variables.saved', env)
def checkSave(file, expected):
gdict = {}
ldict = {}
- exec(open(file, 'r').read(), gdict, ldict)
+ with open(file, 'r') as f:
+ contents = f.read()
+ exec(contents, gdict, ldict)
assert expected == ldict, "%s\n...not equal to...\n%s" % (expected, ldict)
# First test with no command line variables
diff --git a/test/Variables/chdir.py b/test/Variables/chdir.py
index b5fce2a..bdf390d 100644
--- a/test/Variables/chdir.py
+++ b/test/Variables/chdir.py
@@ -52,7 +52,9 @@ print("VARIABLE = "+repr(env['VARIABLE']))
test.write(['bin', 'opts.cfg'], """\
import os
os.chdir(os.path.split(__name__)[0])
-exec(open('opts2.cfg', 'r').read())
+with open('opts2.cfg', 'r') as f:
+ contents = f.read()
+exec(contents)
""")
test.write(['bin', 'opts2.cfg'], """\
diff --git a/test/VariantDir/Clean.py b/test/VariantDir/Clean.py
index 1287034..2e0d4c6 100644
--- a/test/VariantDir/Clean.py
+++ b/test/VariantDir/Clean.py
@@ -43,8 +43,10 @@ VariantDir('build1', '.', duplicate=1)
def build_sample(target, source, env):
targetdir = str(target[0].dir)
target = str(target[0])
- open(target, 'w').write(open(str(source[0]), 'r').read())
- open(targetdir+'/sample.junk', 'w').write('Side effect!\\n')
+ with open(target, 'w') as ofd, open(str(source[0]), 'r') as ifd:
+ ofd.write(ifd.read())
+ with open(targetdir+'/sample.junk', 'w') as f:
+ f.write('Side effect!\\n')
t0 = Command("build0/sample.out", "sample.in", build_sample)
t1 = Command("build1/sample.out", "sample.in", build_sample)
diff --git a/test/VariantDir/SConscript-variant_dir.py b/test/VariantDir/SConscript-variant_dir.py
index 068c312..1e28c47 100644
--- a/test/VariantDir/SConscript-variant_dir.py
+++ b/test/VariantDir/SConscript-variant_dir.py
@@ -59,10 +59,10 @@ var9 = Dir('../build/var9')
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as ofp:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ ofp.write(ifp.read())
env = Environment(BUILDERS={'Cat':Builder(action=cat)},
BUILD='build')
@@ -94,7 +94,7 @@ env.SConscript('src/SConscript', variant_dir='../$BUILD/var8', duplicate=0)
# VariantDir('build/var9', '.')
# SConscript('build/var9/src/SConscript')
SConscript('src/SConscript', variant_dir='build/var9', src_dir='.')
-""")
+""")
test.subdir(['test', 'src'], ['test', 'alt'])
@@ -154,12 +154,12 @@ for file in ['aaa.in', 'bbb.in', 'ccc.in']:
test.must_exist(test.workpath('test', 'build', 'var2', file))
test.fail_test(not equal_stats(test.workpath('test', 'build', 'var2', file),
test.workpath('test', 'src', file)))
-
+
# Make sure we didn't duplicate the source files in build/var3.
test.must_not_exist(test.workpath('test', 'build', 'var3', 'aaa.in'))
test.must_not_exist(test.workpath('test', 'build', 'var3', 'bbb.in'))
test.must_not_exist(test.workpath('test', 'build', 'var3', 'ccc.in'))
-
+
#XXX We can't support var4 and var5 yet, because our VariantDir linkage
#XXX is to an entire source directory. We haven't yet generalized our
#XXX infrastructure to be able to take the SConscript file from one source
@@ -186,12 +186,12 @@ for file in ['aaa.in', 'bbb.in', 'ccc.in']:
test.must_exist(test.workpath('build', 'var6', file))
test.fail_test(not equal_stats(test.workpath('build', 'var6', file),
test.workpath('test', 'src', file)))
-
+
# Make sure we didn't duplicate the source files in build/var7.
test.must_not_exist(test.workpath('build', 'var7', 'aaa.in'))
test.must_not_exist(test.workpath('build', 'var7', 'bbb.in'))
test.must_not_exist(test.workpath('build', 'var7', 'ccc.in'))
-
+
# Make sure we didn't duplicate the source files in build/var8.
test.must_not_exist(test.workpath('build', 'var8', 'aaa.in'))
test.must_not_exist(test.workpath('build', 'var8', 'bbb.in'))
diff --git a/test/WhereIs.py b/test/WhereIs.py
index c765848..bb7ac40 100644
--- a/test/WhereIs.py
+++ b/test/WhereIs.py
@@ -31,7 +31,7 @@ import TestSCons
test = TestSCons.TestSCons()
-subdir_SConscript = os.path.join('subdir', 'SConscript')
+subdir_SConscript = os.path.join('subdir/SConscript')
sub1_xxx_exe = test.workpath('sub1', 'xxx.exe')
sub2_xxx_exe = test.workpath('sub2', 'xxx.exe')
sub3_xxx_exe = test.workpath('sub3', 'xxx.exe')
diff --git a/test/Win32/bad-drive.py b/test/Win32/bad-drive.py
index 80a36c8..424732d 100644
--- a/test/Win32/bad-drive.py
+++ b/test/Win32/bad-drive.py
@@ -60,10 +60,10 @@ def cat(env, source, target):
target = str(target[0])
source = list(map(str, source))
print('cat(%%s) > %%s' %% (source, target))
- f = open(target, "wb")
- for src in source:
- f.write(open(src, "rb").read())
- f.close()
+ with open(target, "wb") as ofp:
+ for src in source:
+ with open(src, "rb") as ifp:
+ ofp.write(ifp.read())
bad_drive = '%s'
env = Environment(BUILDERS={'Build':Builder(action=cat)})
diff --git a/test/Win32/default-drive.py b/test/Win32/default-drive.py
index 31253e4..78db4be 100644
--- a/test/Win32/default-drive.py
+++ b/test/Win32/default-drive.py
@@ -47,10 +47,10 @@ test.subdir('src')
test.write(['src', 'SConstruct'], """
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as ofp:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ ofp.write(ifp.read())
env = Environment(BUILDERS={'Build':Builder(action=cat)})
env.Build('../build/file.out', 'file.in')
diff --git a/test/YACC/YACC-fixture/myyacc.py b/test/YACC/YACC-fixture/myyacc.py
index 756c98f..d0ab95e 100644
--- a/test/YACC/YACC-fixture/myyacc.py
+++ b/test/YACC/YACC-fixture/myyacc.py
@@ -1,13 +1,13 @@
import getopt
import sys
cmd_opts, args = getopt.getopt(sys.argv[1:], 'o:', [])
-output = None
opt_string = ''
for opt, arg in cmd_opts:
- if opt == '-o': output = open(arg, 'w')
+ if opt == '-o': out = arg
else: opt_string = opt_string + ' ' + opt
-for a in args:
- contents = open(a, 'r').read()
- output.write(contents.replace('YACC', 'myyacc.py'))
-output.close()
+with open(out, 'w') as ofp:
+ for a in args:
+ with open(a, 'r') as ifp:
+ contents = ifp.read()
+ ofp.write(contents.replace('YACC', 'myyacc.py'))
sys.exit(0)
diff --git a/test/YACC/YACCFLAGS-fixture/myyacc.py b/test/YACC/YACCFLAGS-fixture/myyacc.py
index ffd9031..43024f1 100644
--- a/test/YACC/YACCFLAGS-fixture/myyacc.py
+++ b/test/YACC/YACCFLAGS-fixture/myyacc.py
@@ -1,17 +1,17 @@
import getopt
import sys
cmd_opts, args = getopt.getopt(sys.argv[1:], 'o:I:x', [])
-output = None
opt_string = ''
i_arguments = ''
for opt, arg in cmd_opts:
- if opt == '-o': output = open(arg, 'wb')
+ if opt == '-o': out = arg
elif opt == '-I': i_arguments = i_arguments + ' ' + arg
else: opt_string = opt_string + ' ' + opt
-for a in args:
- contents = open(a, 'rb').read()
- contents = contents.replace(b'YACCFLAGS', opt_string.encode())
- contents = contents.replace(b'I_ARGS', i_arguments.encode())
- output.write(contents)
-output.close()
+with open(out, 'wb') as ofp:
+ for a in args:
+ with open(a, 'rb') as ifp:
+ contents = ifp.read()
+ contents = contents.replace(b'YACCFLAGS', opt_string.encode())
+ contents = contents.replace(b'I_ARGS', i_arguments.encode())
+ ofp.write(contents)
sys.exit(0)
diff --git a/test/YACC/YACCHFILESUFFIX.py b/test/YACC/YACCHFILESUFFIX.py
index f205473..6c34db1 100644
--- a/test/YACC/YACCHFILESUFFIX.py
+++ b/test/YACC/YACCHFILESUFFIX.py
@@ -46,12 +46,13 @@ for o, a in opts:
if o == '-o':
outfile = open(a, 'wb')
for f in args:
- infile = open(f, 'rb')
- for l in [l for l in infile.readlines() if l != b'/*yacc*/\\n']:
- outfile.write(l)
+ with open(f, 'rb') as infile:
+ for l in [l for l in infile.readlines() if l != b'/*yacc*/\\n']:
+ outfile.write(l)
outfile.close()
base, ext = os.path.splitext(args[0])
-open(base+'.hsuffix', 'wb').write((" ".join(sys.argv)+'\\n').encode())
+with open(base+'.hsuffix', 'wb') as outfile:
+ outfile.write((" ".join(sys.argv) + '\\n').encode())
sys.exit(0)
""")
diff --git a/test/YACC/YACCHXXFILESUFFIX.py b/test/YACC/YACCHXXFILESUFFIX.py
index 6418189..63a5358 100644
--- a/test/YACC/YACCHXXFILESUFFIX.py
+++ b/test/YACC/YACCHXXFILESUFFIX.py
@@ -46,12 +46,13 @@ for o, a in opts:
if o == '-o':
outfile = open(a, 'wb')
for f in args:
- infile = open(f, 'rb')
- for l in [l for l in infile.readlines() if l != b'/*yacc*/\\n']:
- outfile.write(l)
+ with open(f, 'rb') as infile:
+ for l in [l for l in infile.readlines() if l != b'/*yacc*/\\n']:
+ outfile.write(l)
outfile.close()
base, ext = os.path.splitext(args[0])
-open(base+'.hxxsuffix', 'wb').write((" ".join(sys.argv)+'\\n').encode())
+with open(base+'.hxxsuffix', 'wb') as outfile:
+ outfile.write((" ".join(sys.argv)+'\\n').encode())
sys.exit(0)
""")
diff --git a/test/YACC/YACCVCGFILESUFFIX.py b/test/YACC/YACCVCGFILESUFFIX.py
index 5306076..aee3265 100644
--- a/test/YACC/YACCVCGFILESUFFIX.py
+++ b/test/YACC/YACCVCGFILESUFFIX.py
@@ -48,13 +48,14 @@ for o, a in opts:
elif o == '-o':
outfile = open(a, 'wb')
for f in args:
- infile = open(f, 'rb')
- for l in [l for l in infile.readlines() if l != b'/*yacc*/\\n']:
- outfile.write(l)
+ with open(f, 'rb') as infile:
+ for l in [l for l in infile.readlines() if l != b'/*yacc*/\\n']:
+ outfile.write(l)
outfile.close()
if vcg:
base, ext = os.path.splitext(args[0])
- open(base+'.vcgsuffix', 'wb').write((" ".join(sys.argv)+'\\n').encode())
+ with open(base+'.vcgsuffix', 'wb') as outfile:
+ outfile.write((" ".join(sys.argv)+'\\n').encode())
sys.exit(0)
""")
diff --git a/test/builderrors.py b/test/builderrors.py
index a3e2f4d..f5cbccf 100644
--- a/test/builderrors.py
+++ b/test/builderrors.py
@@ -38,10 +38,8 @@ test.write('build.py', r"""
import sys
exitval = int(sys.argv[1])
if exitval == 0:
- contents = open(sys.argv[3], 'r').read()
- file = open(sys.argv[2], 'w')
- file.write(contents)
- file.close()
+ with open(sys.argv[2], 'w') as f, open(sys.argv[3], 'r') as infp:
+ f.write(infp.read())
sys.exit(exitval)
""")
@@ -198,8 +196,8 @@ env = Environment()
env.Default("all")
env.Alias("all", env.Install("dir", "file.txt"))
""")
-test.run(status=2, match=TestSCons.match_re, stderr="""\
-scons: \*\*\* Do not know how to make File target `all' \(.*all\). Stop.
+test.run(status=2, match=TestSCons.match_re, stderr=\
+r"""scons: \*\*\* Do not know how to make File target `all' \(.*all\). Stop.
""")
# No tests failed; OK.
diff --git a/test/chdir.py b/test/chdir.py
index c4d392e..696488b 100644
--- a/test/chdir.py
+++ b/test/chdir.py
@@ -91,11 +91,10 @@ other9_f19_in = test.workpath('other9', 'f19.in')
test.write(cat_py, """\
import sys
-ofp = open(sys.argv[1], 'wb')
-for f in sys.argv[2:]:
- ifp = open(f, 'rb')
- ofp.write(ifp.read())
-ofp.close
+with open(sys.argv[1], 'wb') as ofp:
+ for f in sys.argv[2:]:
+ with open(f, 'rb') as ifp:
+ ofp.write(ifp.read())
""")
test.write(['work1', 'SConstruct'], """
diff --git a/test/duplicate-sources.py b/test/duplicate-sources.py
index 03b5686..3ad2928 100644
--- a/test/duplicate-sources.py
+++ b/test/duplicate-sources.py
@@ -35,10 +35,10 @@ test = TestSCons.TestSCons()
test.write('SConstruct', """\
def cat(target, source, env):
- t = open(str(target[0]), 'wb')
- for s in source:
- t.write(open(str(s), 'rb').read())
- t.close()
+ with open(str(target[0]), 'wb') as t:
+ for s in source:
+ with open(str(s), 'rb') as s:
+ t.write(s.read())
env = Environment(BUILDERS = {'Cat' : Builder(action = cat)})
env.Cat('out.txt', ['f1.in', 'f2.in', 'f1.in'])
""")
diff --git a/test/emitter.py b/test/emitter.py
index 78de13e..7712d3a 100644
--- a/test/emitter.py
+++ b/test/emitter.py
@@ -42,7 +42,8 @@ SConscript('var2/SConscript')
test.write('src/SConscript',"""
def build(target, source, env):
for t in target:
- open(str(t), "wt").write(str(t))
+ with open(str(t), "wt") as f:
+ f.write(str(t))
def emitter(target, source, env):
target.append(str(target[0])+".foo")
diff --git a/test/explain/basic.py b/test/explain/basic.py
index 99942cd..160d632 100644
--- a/test/explain/basic.py
+++ b/test/explain/basic.py
@@ -67,13 +67,15 @@ def process(outfp, infp):
print("os.getcwd() =", os.getcwd())
raise
process(outfp, fp)
+ fp.close()
else:
outfp.write(line)
-outfp = open(sys.argv[1], 'w')
-for f in sys.argv[2:]:
- if f != '-':
- process(outfp, open(f, 'r'))
+with open(sys.argv[1], 'w') as ofp:
+ for f in sys.argv[2:]:
+ if f != '-':
+ with open(f, 'r') as ifp:
+ process(ofp, ifp)
sys.exit(0)
""")
diff --git a/test/explain/save-info.py b/test/explain/save-info.py
index 08255e0..383822c 100644
--- a/test/explain/save-info.py
+++ b/test/explain/save-info.py
@@ -57,13 +57,15 @@ def process(outfp, infp):
print("os.getcwd() =", os.getcwd())
raise
process(outfp, fp)
+ fp.close()
else:
outfp.write(line)
-outfp = open(sys.argv[1], 'w')
-for f in sys.argv[2:]:
- if f != '-':
- process(outfp, open(f, 'r'))
+with open(sys.argv[1], 'w') as ofp:
+ for f in sys.argv[2:]:
+ if f != '-':
+ with open(f, 'r') as ifp:
+ process(ofp, ifp)
sys.exit(0)
""")
diff --git a/test/fixture/mycompile.py b/test/fixture/mycompile.py
index 313e4b5..275f7be 100644
--- a/test/fixture/mycompile.py
+++ b/test/fixture/mycompile.py
@@ -9,10 +9,10 @@ has made a modification.
import sys
if __name__ == '__main__':
- line = '/*' + sys.argv[1] + '*/\n'
- with open(sys.argv[2], 'w') as ofp:
+ line = ('/*' + sys.argv[1] + '*/\n').encode()
+ with open(sys.argv[2], 'wb') as ofp:
for f in sys.argv[3:]:
- with open(f, 'r') as ifp:
+ with open(f, 'rb') as ifp:
lines = [l for l in ifp.readlines() if l != line]
for l in lines:
ofp.write(l)
diff --git a/test/fixture/mylink.py b/test/fixture/mylink.py
index 5006f22..b567118 100644
--- a/test/fixture/mylink.py
+++ b/test/fixture/mylink.py
@@ -22,9 +22,9 @@ if __name__ == '__main__':
break
args = args[1:]
if a[:5].lower() == '/out:': out = a[5:]
- with open(args[0], 'r') as ifp, open(out, 'w') as ofp:
+ with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp:
for l in ifp.readlines():
- if not l.startswith('#link'):
+ if not l.startswith(b'#link'):
ofp.write(l)
sys.exit(0)
else:
@@ -32,8 +32,8 @@ if __name__ == '__main__':
opts, args = getopt.getopt(sys.argv[1:], 'o:')
for opt, arg in opts:
if opt == '-o': out = arg
- with open(args[0], 'r') as ifp, open(out, 'w') as ofp:
+ with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp:
for l in ifp.readlines():
- if not l.startswith('#link'):
+ if not l.startswith(b'#link'):
ofp.write(l)
sys.exit(0)
diff --git a/test/fixture/myrewrite.py b/test/fixture/myrewrite.py
index bd90a68..95272b6 100644
--- a/test/fixture/myrewrite.py
+++ b/test/fixture/myrewrite.py
@@ -8,9 +8,10 @@ ranlib-related behavior without invoking ranlib.
import sys
if __name__ == '__main__':
- line = ('/*' + sys.argv[1] + '*/\n')
- with open(sys.argv[2], 'w') as ofp, open(sys.argv[2], 'r') as ifp:
+ line = ('/*' + sys.argv[1] + '*/\n').encode()
+ with open(sys.argv[2], 'rb') as ifp:
lines = [l for l in ifp.readlines() if l != line]
+ with open(sys.argv[2], 'wb') as ofp:
for l in lines:
ofp.write(l)
sys.exit(0)
diff --git a/test/fixture/wrapper.py b/test/fixture/wrapper.py
index 8791390..a023689 100644
--- a/test/fixture/wrapper.py
+++ b/test/fixture/wrapper.py
@@ -5,6 +5,6 @@ import subprocess
if __name__ == '__main__':
path = os.path.join(os.path.dirname(os.path.relpath(__file__)), 'wrapper.out')
if '--version' not in sys.argv and '-dumpversion' not in sys.argv:
- with open(path, 'w') as f:
- f.write("wrapper.py\n")
+ with open(path, 'wb') as f:
+ f.write(b"wrapper.py\n")
subprocess.call(sys.argv[1:])
diff --git a/test/gnutools.py b/test/gnutools.py
index 65d699b..bd8e366 100644
--- a/test/gnutools.py
+++ b/test/gnutools.py
@@ -46,16 +46,16 @@ test.write(['gnutools','mygcc.py'], """
import getopt
import sys
cmd_opts, args = getopt.getopt(sys.argv[1:], 'f:s:co:', [])
-output = None
+out = None
opt_string = ''
for opt, arg in cmd_opts:
- if opt == '-o': output = open(arg, 'w')
+ if opt == '-o': out = arg
else: opt_string = opt_string + ' ' + opt + arg
-output.write('gcc ' + opt_string + '\\n')
-for a in args:
- contents = open(a, 'r').read()
- output.write(contents)
-output.close()
+with open(out, 'w') as ofp:
+ ofp.write('gcc ' + opt_string + '\\n')
+ for a in args:
+ with open(a, 'r') as ifp:
+ ofp.write(ifp.read())
sys.exit(0)
""")
@@ -63,16 +63,16 @@ test.write(['gnutools','myg++.py'], """
import getopt
import sys
cmd_opts, args = getopt.getopt(sys.argv[1:], 'f:s:co:', [])
-output = None
+out = None
opt_string = ''
for opt, arg in cmd_opts:
- if opt == '-o': output = open(arg, 'w')
+ if opt == '-o': out = arg
else: opt_string = opt_string + ' ' + opt + arg
-output.write('g++ ' + opt_string + '\\n')
-for a in args:
- contents = open(a, 'r').read()
- output.write(contents)
-output.close()
+with open(out, 'w') as ofp:
+ ofp.write('g++ ' + opt_string + '\\n')
+ for a in args:
+ with open(a, 'r') as ifp:
+ ofp.write(ifp.read())
sys.exit(0)
""")
diff --git a/test/ignore-command.py b/test/ignore-command.py
index 9fd24ab..d5c18a5 100644
--- a/test/ignore-command.py
+++ b/test/ignore-command.py
@@ -40,10 +40,10 @@ test.subdir('build', 'src')
test.write('build.py', r"""
import sys
-fp = open(sys.argv[1], 'wb')
-for f in sys.argv[2:]:
- fp.write(open(f, 'rb').read())
-fp.close()
+with open(sys.argv[1], 'wb') as fp:
+ for f in sys.argv[2:]:
+ with open(f, 'rb') as ifp:
+ fp.write(ifp.read())
sys.exit(1)
""")
diff --git a/test/implicit/IMPLICIT_COMMAND_DEPENDENCIES.py b/test/implicit/IMPLICIT_COMMAND_DEPENDENCIES.py
index 3d05fe3..2431a61 100644
--- a/test/implicit/IMPLICIT_COMMAND_DEPENDENCIES.py
+++ b/test/implicit/IMPLICIT_COMMAND_DEPENDENCIES.py
@@ -45,16 +45,17 @@ generate_build_py_py_contents = """\
import os
import sys
-open(sys.argv[1], 'w').write('''\
+with open(sys.argv[1], 'w') as f:
+ f.write('''\
#!/usr/bin/env %(python)s
import os
import sys
-fp = open(sys.argv[1], 'w')
-args = [os.path.split(sys.argv[0])[1]] + sys.argv[1:]
-fp.write(" ".join(args) + '\\\\n' + '%(extra)s')
-for infile in sys.argv[2:]:
- fp.write(open(infile, 'r').read())
-fp.close()
+with open(sys.argv[1], 'w') as fp:
+ args = [os.path.split(sys.argv[0])[1]] + sys.argv[1:]
+ fp.write(" ".join(args) + '\\\\n' + '%(extra)s')
+ for infile in sys.argv[2:]:
+ with open(infile, 'r') as ifp:
+ fp.write(ifp.read())
''')
os.chmod(sys.argv[1], 0o755)
diff --git a/test/implicit/asynchronous-modification.py b/test/implicit/asynchronous-modification.py
index 90a6392..1a409ae 100644
--- a/test/implicit/asynchronous-modification.py
+++ b/test/implicit/asynchronous-modification.py
@@ -55,8 +55,10 @@ test.write(['hdr.h'], """\
""")
test.write(['mod.py'], """\
-open('mod', 'w').write(open('mod.py', 'r').read())
-open('hdr.h', 'w').write("/* modified */\\n")
+with open('mod', 'w') as f, open('mod.py', 'r') as ifp:
+ f.write(ifp.read())
+with open('hdr.h', 'w') as f:
+ f.write("/* modified */\\n")
""")
test.write(['one.c'], """\
diff --git a/test/implicit/changed-node.py b/test/implicit/changed-node.py
index 8b818ba..c8c5a01 100644
--- a/test/implicit/changed-node.py
+++ b/test/implicit/changed-node.py
@@ -46,14 +46,13 @@ SetOption('max_drift', 1)
def lister(target, source, env):
import os
- fp = open(str(target[0]), 'w')
- s = str(source[0])
- if os.path.isdir(s):
- for l in os.listdir(str(source[0])):
- fp.write(l + '\\n')
- else:
- fp.write(s + '\\n')
- fp.close()
+ with open(str(target[0]), 'w') as ofp:
+ s = str(source[0])
+ if os.path.isdir(s):
+ for l in os.listdir(str(source[0])):
+ ofp.write(l + '\\n')
+ else:
+ ofp.write(s + '\\n')
builder = Builder(action=lister,
source_factory=Dir,
@@ -83,14 +82,13 @@ SetOption('max_drift', 1)
def lister(target, source, env):
import os.path
- fp = open(str(target[0]), 'w')
- s = str(source[0])
- if os.path.isdir(s):
- for l in os.listdir(str(source[0])):
- fp.write(l + '\\n')
- else:
- fp.write(s + '\\n')
- fp.close()
+ with open(str(target[0]), 'w') as ofp:
+ s = str(source[0])
+ if os.path.isdir(s):
+ for l in os.listdir(str(source[0])):
+ ofp.write(l + '\\n')
+ else:
+ ofp.write(s + '\\n')
builder = Builder(action=lister,
source_factory=File)
@@ -111,12 +109,12 @@ test.pass_test()
#
#
#def setfile(f, content):
-# f = open(f, 'w')
-# try: f.write(content)
-# finally: f.close()
+# with open(f, 'w') as ofp:
+# ofp.write(content)
#
#def checkfile(f, content):
-# assert open(f).read().strip() == content
+# with open(f) as fp:
+# assert fp.read().strip() == content
#
#def rm(f):
# if exists(f):
diff --git a/test/long-lines/signature.py b/test/long-lines/signature.py
index 64214b4..082a13b 100644
--- a/test/long-lines/signature.py
+++ b/test/long-lines/signature.py
@@ -42,14 +42,14 @@ test.write(build_py, """\
#!%(_python_)s
import sys
if sys.argv[1][0] == '@':
- args = open(sys.argv[1][1:], 'r').read()
- args = args.split()
+ with open(sys.argv[1][1:], 'r') as f:
+ args = f.read().split()
else:
args = sys.argv[1:]
-fp = open(args[0], 'w')
-fp.write(open(args[1], 'r').read())
-fp.write('FILEFLAG=%%s\\n' %% args[2])
-fp.write('TIMESTAMP=%%s\\n' %% args[3])
+with open(args[0], 'w') as fp, open(args[1], 'r') as ifp:
+ fp.write(ifp.read())
+ fp.write('FILEFLAG=%%s\\n' %% args[2])
+ fp.write('TIMESTAMP=%%s\\n' %% args[3])
""" % locals())
os.chmod(build_py, 0o755)
diff --git a/test/multiline.py b/test/multiline.py
index 4537eae..c2fabf8 100644
--- a/test/multiline.py
+++ b/test/multiline.py
@@ -35,10 +35,8 @@ test = TestSCons.TestSCons()
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as ifp:
+ f.write(ifp.read())
sys.exit(0)
""")
diff --git a/test/no-arguments.py b/test/no-arguments.py
index 953d827..8925c48 100644
--- a/test/no-arguments.py
+++ b/test/no-arguments.py
@@ -41,10 +41,10 @@ def cat(env, source, target):
target = str(target[0])
source = list(map(str, source))
print('cat(%s) > %s' % (source, target))
- f = open(target, "wb")
- for src in source:
- f.write(open(src, "rb").read())
- f.close()
+ with open(target, "wb") as f:
+ for src in source:
+ with open(src, "rb") as ifp:
+ f.write(ifp.read())
env = Environment(BUILDERS={'Build':Builder(action=cat)})
env.Build('aaa.out', 'aaa.in')
diff --git a/test/no-target.py b/test/no-target.py
index bce5632..bf5b94a 100644
--- a/test/no-target.py
+++ b/test/no-target.py
@@ -42,10 +42,10 @@ SConscript(r'%s')
test.write(subdir_SConscript, r"""
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as f:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ f.write(ifp.read())
b = Builder(action=cat, suffix='.out', src_suffix='.in')
env = Environment(BUILDERS={'Build':b})
diff --git a/test/option--max-drift.py b/test/option--max-drift.py
index 4e063c9..b90ecdf 100644
--- a/test/option--max-drift.py
+++ b/test/option--max-drift.py
@@ -34,10 +34,8 @@ test = TestSCons.TestSCons()
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as ifp:
+ f.write(ifp.read())
""")
test.write('SConstruct', """
diff --git a/test/option--random.py b/test/option--random.py
index 357cf2e..2944ad8 100644
--- a/test/option--random.py
+++ b/test/option--random.py
@@ -38,10 +38,10 @@ test = TestSCons.TestSCons()
test.write('SConscript', """\
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as f:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ f.write(ifp.read())
env = Environment(BUILDERS={'Cat':Builder(action=cat)})
env.Cat('aaa.out', 'aaa.in')
env.Cat('bbb.out', 'bbb.in')
diff --git a/test/option-n.py b/test/option-n.py
index 0fd7bfe..f952428 100644
--- a/test/option-n.py
+++ b/test/option-n.py
@@ -52,9 +52,8 @@ test.subdir('build', 'src')
test.write('build.py', r"""
import sys
-file = open(sys.argv[1], 'w')
-file.write("build.py: %s\n" % sys.argv[1])
-file.close()
+with open(sys.argv[1], 'w') as ofp:
+ ofp.write("build.py: %s\n" % sys.argv[1])
""")
test.write('SConstruct', """
diff --git a/test/option/debug-count.py b/test/option/debug-count.py
index 2b5b745..0234bfa 100644
--- a/test/option/debug-count.py
+++ b/test/option/debug-count.py
@@ -46,7 +46,8 @@ except ImportError:
test.write('SConstruct', """
DefaultEnvironment(tools=[])
def cat(target, source, env):
- open(str(target[0]), 'wb').write(open(str(source[0]), 'rb').read())
+ with open(str(target[0]), 'wb') as f, open(str(source[0]), 'rb') as infp:
+ f.write(infp.read())
env = Environment(BUILDERS={'Cat':Builder(action=Action(cat))})
env.Cat('file.out', 'file.in')
""")
@@ -57,7 +58,7 @@ test.write('file.in', "file.in\n")
# show up in the output.
def find_object_count(s, stdout):
- re_string = '\d+ +\d+ %s' % re.escape(s)
+ re_string = r'\d+ +\d+ %s' % re.escape(s)
return re.search(re_string, stdout)
objects = [
diff --git a/test/option/debug-findlibs.py b/test/option/debug-findlibs.py
index 78ecee9..8d9974c 100644
--- a/test/option/debug-findlibs.py
+++ b/test/option/debug-findlibs.py
@@ -34,11 +34,10 @@ test.subdir('sub1', 'sub2')
test.write('cat.py', """\
import sys
-ofp = open(sys.argv[1], 'wb')
-for f in sys.argv[2:]:
- ifp = open(f, 'rb')
- ofp.write(ifp.read())
-ofp.close()
+with open(sys.argv[1], 'wb') as ofp:
+ for f in sys.argv[2:]:
+ with open(f, 'rb') as ifp:
+ ofp.write(ifp.read())
""")
test.write('SConstruct', """\
diff --git a/test/option/debug-memoizer.py b/test/option/debug-memoizer.py
index f65bcb8..01af561 100644
--- a/test/option/debug-memoizer.py
+++ b/test/option/debug-memoizer.py
@@ -38,7 +38,8 @@ test = TestSCons.TestSCons(match = TestSCons.match_re_dotall)
test.write('SConstruct', """
DefaultEnvironment(tools=[])
def cat(target, source, env):
- open(str(target[0]), 'wb').write(open(str(source[0]), 'rb').read())
+ with open(str(target[0]), 'wb') as f, open(str(source[0]), 'rb') as infp:
+ f.write(infp.read())
env = Environment(tools=[], BUILDERS={'Cat':Builder(action=Action(cat))})
env.Cat('file.out', 'file.in')
""")
diff --git a/test/option/debug-memory.py b/test/option/debug-memory.py
index 6d395d6..bf720cc 100644
--- a/test/option/debug-memory.py
+++ b/test/option/debug-memory.py
@@ -49,7 +49,8 @@ except ImportError:
test.write('SConstruct', """
DefaultEnvironment(tools=[])
def cat(target, source, env):
- open(str(target[0]), 'wb').write(open(str(source[0]), 'rb').read())
+ with open(str(target[0]), 'wb') as f, open(str(source[0]), 'rb') as ifp:
+ f.write(ifp.read())
env = Environment(tools=[], BUILDERS={'Cat':Builder(action=Action(cat))})
env.Cat('file.out', 'file.in')
""")
diff --git a/test/option/debug-multiple.py b/test/option/debug-multiple.py
index 23af13b..020aa85 100644
--- a/test/option/debug-multiple.py
+++ b/test/option/debug-multiple.py
@@ -38,7 +38,8 @@ test = TestSCons.TestSCons()
test.write('SConstruct', """
DefaultEnvironment(tools=[])
def cat(target, source, env):
- open(str(target[0]), 'wb').write(open(str(source[0]), 'rb').read())
+ with open(str(target[0]), 'wb') as f, open(str(source[0]), 'rb') as infp:
+ f.write(infp.read())
env = Environment(BUILDERS={'Cat':Builder(action=Action(cat))})
env.Cat('file.out', 'file.in')
""")
@@ -49,7 +50,7 @@ test.write('file.in', "file.in\n")
# show up in the output.
def find_object_count(s, stdout):
- re_string = '\d+ +\d+ %s' % re.escape(s)
+ re_string = r'\d+ +\d+ %s' % re.escape(s)
return re.search(re_string, stdout)
objects = [
diff --git a/test/option/debug-objects.py b/test/option/debug-objects.py
index e86684a..beec4b7 100644
--- a/test/option/debug-objects.py
+++ b/test/option/debug-objects.py
@@ -43,7 +43,8 @@ except ImportError:
test.write('SConstruct', """
DefaultEnvironment(tools=[])
def cat(target, source, env):
- open(str(target[0]), 'wb').write(open(str(source[0]), 'rb').read())
+ with open(str(target[0]), 'wb') as f, open(str(source[0]), 'rb') as infp:
+ f.write(infp.read())
env = Environment(tools=[], BUILDERS={'Cat':Builder(action=Action(cat))})
env.Cat('file.out', 'file.in')
""")
diff --git a/test/option/debug-presub.py b/test/option/debug-presub.py
index 0b0555a..cbd5242 100644
--- a/test/option/debug-presub.py
+++ b/test/option/debug-presub.py
@@ -32,7 +32,8 @@ test = TestSCons.TestSCons()
test.write('cat.py', """\
import sys
-open(sys.argv[2], "wb").write(open(sys.argv[1], "rb").read())
+with open(sys.argv[2], "wb") as f, open(sys.argv[1], "rb") as infp:
+ f.write(infp.read())
sys.exit(0)
""")
@@ -40,10 +41,10 @@ test.write('SConstruct', """\
DefaultEnvironment(tools=[])
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as f:
+ for src in source:
+ with open(str(src), "rb") as infp:
+ f.write(infp.read())
FILE = Builder(action="$FILECOM")
TEMP = Builder(action="$TEMPCOM")
LIST = Builder(action="$LISTCOM")
diff --git a/test/option/debug-time.py b/test/option/debug-time.py
index 987e49f..3ed7555 100644
--- a/test/option/debug-time.py
+++ b/test/option/debug-time.py
@@ -36,10 +36,10 @@ test.write('sleep_cat.py', """\
import sys
import time
time.sleep(int(sys.argv[1]))
-fp = open(sys.argv[2], 'wb')
-for arg in sys.argv[3:]:
- fp.write(open(arg, 'rb').read())
-fp.close()
+with open(sys.argv[2], 'wb') as fp:
+ for arg in sys.argv[3:]:
+ with open(arg, 'rb') as infp:
+ fp.write(infp.read())
sys.exit(0)
""")
diff --git a/test/option/md5-chunksize.py b/test/option/md5-chunksize.py
index 708143f..4f1d495 100644
--- a/test/option/md5-chunksize.py
+++ b/test/option/md5-chunksize.py
@@ -32,10 +32,8 @@ test = TestSCons.TestSCons()
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as infp:
+ f.write(infp.read())
""")
test.write('SConstruct', """
@@ -107,9 +105,8 @@ DefaultEnvironment(tools=[])
import os
def get_stat(target, source, env):
stat = os.stat(source[0].get_abspath())
- dest = open(target[0].get_abspath(),'w')
- dest.write(str(stat))
- dest.close()
+ with open(target[0].get_abspath(),'w') as dest:
+ dest.write(str(stat))
env = Environment(tools=[])
env.Command('test.big', 'SConstruct', 'dd if=/dev/zero of=test.big seek=100 bs=1M count=0 2>/dev/null')
env.AlwaysBuild('test.big')
diff --git a/test/option/stack-size.py b/test/option/stack-size.py
index febec5a..53faa9e 100644
--- a/test/option/stack-size.py
+++ b/test/option/stack-size.py
@@ -41,10 +41,8 @@ test.subdir('work1', 'work2')
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as infp:
+ f.write(infp.read())
""")
diff --git a/test/option/warn-duplicate-environment.py b/test/option/warn-duplicate-environment.py
index 1509e41..1000647 100644
--- a/test/option/warn-duplicate-environment.py
+++ b/test/option/warn-duplicate-environment.py
@@ -36,9 +36,10 @@ test = TestSCons.TestSCons(match = TestSCons.match_re_dotall)
test.write('SConstruct', """
DefaultEnvironment(tools=[])
def build(env, target, source):
- file = open(str(target[0]), 'wb')
- for s in source:
- file.write(open(str(s), 'rb').read())
+ with open(str(target[0]), 'wb') as f:
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ f.write(infp.read())
WARN = ARGUMENTS.get('WARN')
if WARN:
diff --git a/test/option/warn-misleading-keywords.py b/test/option/warn-misleading-keywords.py
index ca934e5..45236bb 100644
--- a/test/option/warn-misleading-keywords.py
+++ b/test/option/warn-misleading-keywords.py
@@ -36,9 +36,10 @@ test = TestSCons.TestSCons(match = TestSCons.match_re_dotall)
test.write('SConstruct', """
DefaultEnvironment(tools=[])
def build(env, target, source):
- file = open(str(target[0]), 'wb')
- for s in source:
- file.write(open(str(s), 'rb').read())
+ with open(str(target[0]), 'wb') as f:
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ f.write(infp.read())
WARN = ARGUMENTS.get('WARN')
if WARN:
diff --git a/test/overrides.py b/test/overrides.py
index cca8dc7..54a174b 100644
--- a/test/overrides.py
+++ b/test/overrides.py
@@ -77,11 +77,13 @@ env.Program('hello', 'hello.c',
test.write('hello.c',"this ain't no c file!\n")
test.write('mycc.py',"""
-open('hello.not_obj', 'w').write('this is no object file!')
+with open('hello.not_obj', 'w') as f:
+ f.write('this is no object file!')
""")
test.write('mylink.py',"""
-open('hello.not_exe', 'w').write('this is not a program!')
+with open('hello.not_exe', 'w') as f:
+ f.write('this is not a program!')
""")
test.run(arguments='hello.not_exe')
@@ -107,11 +109,13 @@ env.Program('goodbye', 'goodbye.c',
test.write('goodbye.c',"this ain't no c file!\n")
test.write('mycc.py',"""
-open('goodbye.not_obj', 'wt').write('this is no object file!')
+with open('goodbye.not_obj', 'wt') as f:
+ f.write('this is no object file!')
""")
test.write('mylink.py',"""
-open('goodbye.not_exe', 'wt').write('this is not a program!')
+with open('goodbye.not_exe', 'wt') as f:
+ f.write('this is not a program!')
""")
test.run(arguments='goodbye.not_exe', stderr=None)
diff --git a/test/packaging/convenience-functions/convenience-functions.py b/test/packaging/convenience-functions/convenience-functions.py
index a1be041..fb9acb3 100644
--- a/test/packaging/convenience-functions/convenience-functions.py
+++ b/test/packaging/convenience-functions/convenience-functions.py
@@ -33,7 +33,7 @@ import TestSCons
test = TestSCons.TestSCons()
-test.dir_fixture( "image" )
+test.dir_fixture("image")
bin_f1 = os.path.join('bin', 'f1')
bin_f2 = os.path.join('bin', 'f2')
diff --git a/test/packaging/ipkg.py b/test/packaging/ipkg.py
index 08889a9..99c31e5 100644
--- a/test/packaging/ipkg.py
+++ b/test/packaging/ipkg.py
@@ -73,6 +73,11 @@ Maintainer, Depends, and Description fields.''',
X_IPK_DEPENDS = 'libc6, grep', )
""")
+with os.popen('id -un') as p:
+ IPKGUSER = p.read().strip()
+with os.popen('id -gn') as p:
+ IPKGGROUP = p.read().strip()
+
expected="""scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
@@ -84,7 +89,7 @@ build_specfiles(["foo-0.0/CONTROL/control", "foo-0.0/CONTROL/conffiles", "foo-0.
ipkg-build -o %s -g %s foo-0.0
Packaged contents of foo-0.0 into %s/foo_0.0_arm.ipk
scons: done building targets.
-"""%(os.popen('id -un').read().strip(), os.popen('id -gn').read().strip(), test.workpath())
+"""%(IPKGUSER, IPKGGROUP, test.workpath())
test.run(arguments="--debug=stacktrace foo_0.0_arm.ipk", stdout=expected)
test.must_exist( 'foo-0.0/CONTROL/control' )
diff --git a/test/packaging/place-files-in-subdirectory.py b/test/packaging/place-files-in-subdirectory.py
index 0eb791f..23ff543 100644
--- a/test/packaging/place-files-in-subdirectory.py
+++ b/test/packaging/place-files-in-subdirectory.py
@@ -102,8 +102,9 @@ env.Package( NAME = 'libfoo',
test.run(stderr = None)
-str = os.popen( 'tar -tzf %s'%test.workpath('libfoo-1.2.3.tar.gz') ).read()
-test.fail_test( str != "libfoo-1.2.3/src/main.c\nlibfoo-1.2.3/SConstruct\n" )
+with os.popen('tar -tzf %s'%test.workpath('libfoo-1.2.3.tar.gz')) as p:
+ str = p.read()
+test.fail_test(str != "libfoo-1.2.3/src/main.c\nlibfoo-1.2.3/SConstruct\n")
test.pass_test()
diff --git a/test/packaging/rpm/internationalization.py b/test/packaging/rpm/internationalization.py
index ad77f40..eea30ca 100644
--- a/test/packaging/rpm/internationalization.py
+++ b/test/packaging/rpm/internationalization.py
@@ -94,25 +94,29 @@ machine_rpm = 'foo-1.2.3-0.%s.rpm' % SCons.Tool.rpmutils.defaultMachine()
test.must_exist( src_rpm )
test.must_exist( machine_rpm )
-test.must_not_exist( 'bin/main' )
+test.must_not_exist('bin/main')
cmd = 'rpm -qp --queryformat \'%%{GROUP}-%%{SUMMARY}-%%{DESCRIPTION}\' %s'
os.environ['LANGUAGE'] = 'de'
-out = os.popen( cmd % test.workpath(machine_rpm) ).read()
-test.fail_test( out != 'Applikation/büro-hallo-das sollte wirklich lang sein' )
+with os.popen(cmd % test.workpath(machine_rpm)) as p:
+ out = p.read()
+test.fail_test(out != 'Applikation/büro-hallo-das sollte wirklich lang sein')
os.environ['LANGUAGE'] = 'fr'
-out = os.popen( cmd % test.workpath(machine_rpm) ).read()
-test.fail_test( out != 'Application/bureau-bonjour-ceci devrait être vraiment long' )
+with os.popen(cmd % test.workpath(machine_rpm)) as p:
+ out = p.read()
+test.fail_test(out != 'Application/bureau-bonjour-ceci devrait être vraiment long')
os.environ['LANGUAGE'] = 'en'
-out = os.popen( cmd % test.workpath(machine_rpm) ).read()
-test.fail_test( out != 'Application/office-hello-this should be really long' )
+with os.popen(cmd % test.workpath(machine_rpm)) as p:
+ out = p.read()
+test.fail_test(out != 'Application/office-hello-this should be really long')
os.environ['LC_ALL'] = 'ae'
-out = os.popen( cmd % test.workpath(machine_rpm) ).read()
-test.fail_test( out != 'Application/office-hello-this should be really long' )
+with os.popen(cmd % test.workpath(machine_rpm)) as p:
+ out = p.read()
+test.fail_test(out != 'Application/office-hello-this should be really long')
#
# test INTERNATIONAL PACKAGE TAGS
diff --git a/test/packaging/rpm/multipackage.py b/test/packaging/rpm/multipackage.py
index fd67a09..2f106f4 100644
--- a/test/packaging/rpm/multipackage.py
+++ b/test/packaging/rpm/multipackage.py
@@ -104,9 +104,11 @@ test.must_exist( machine_rpm2 )
test.must_exist( src_rpm2 )
test.must_not_exist( 'bin/main' )
-out = os.popen( 'rpm -qpl %s' % machine_rpm).read()
+with os.popen('rpm -qpl %s' % machine_rpm) as p:
+ out = p.read()
test.must_contain_all_lines( out, '/bin/main')
-out = os.popen( 'rpm -qpl %s' % src_rpm).read()
+with os.popen('rpm -qpl %s' % src_rpm) as p:
+ out = p.read()
test.fail_test( not out == 'foo-1.2.3.spec\nfoo-1.2.3.tar.gz\n')
test.pass_test()
diff --git a/test/packaging/rpm/package.py b/test/packaging/rpm/package.py
index 2ba66b9..ddd3c89 100644
--- a/test/packaging/rpm/package.py
+++ b/test/packaging/rpm/package.py
@@ -83,9 +83,11 @@ machine_rpm = 'foo-1.2.3-0.%s.rpm' % SCons.Tool.rpmutils.defaultMachine()
test.must_exist( machine_rpm )
test.must_exist( src_rpm )
test.must_not_exist( 'bin/main' )
-out = os.popen( 'rpm -qpl %s' % machine_rpm).read()
-test.must_contain_all_lines( out, '/bin/main')
-out = os.popen( 'rpm -qpl %s' % src_rpm).read()
+with os.popen('rpm -qpl %s' % machine_rpm) as p:
+ out = p.read()
+test.must_contain_all_lines(out, '/bin/main')
+with os.popen('rpm -qpl %s' % machine_rpm) as p:
+ out = p.read()
test.fail_test( not out == 'foo-1.2.3.spec\nfoo-1.2.3.tar.gz\n')
test.pass_test()
diff --git a/test/packaging/rpm/tagging.py b/test/packaging/rpm/tagging.py
index b685c91..c730e14 100644
--- a/test/packaging/rpm/tagging.py
+++ b/test/packaging/rpm/tagging.py
@@ -85,11 +85,13 @@ src_rpm = 'foo-1.2.3-0.src.rpm'
machine_rpm = 'foo-1.2.3-0.%s.rpm' % SCons.Tool.rpmutils.defaultMachine()
test.must_exist( machine_rpm )
-out = os.popen('rpm -qpl %s' % machine_rpm).read()
+with os.popen('rpm -qpl %s' % machine_rpm) as p:
+ out = p.read()
test.must_contain_all_lines( out, '/bin/main')
test.must_exist( src_rpm )
-out = os.popen('rpm -qpl %s' % src_rpm).read()
+with os.popen('rpm -qpl %s' % src_rpm) as p:
+ out = p.read()
test.fail_test( not out == 'foo-1.2.3.spec\nfoo-1.2.3.tar.gz\n')
expect = '(0755, root, users) /bin/main'
diff --git a/test/preserve-source.py b/test/preserve-source.py
index 74fbed5..b7444da 100644
--- a/test/preserve-source.py
+++ b/test/preserve-source.py
@@ -36,10 +36,10 @@ def cat(env, source, target):
target = str(target[0])
source = list(map(str, source))
print('cat(%s) > %s' % (source, target))
- f = open(target, "wb")
- for src in source:
- f.write(open(src, "rb").read())
- f.close()
+ with open(target, "wb") as f:
+ for src in source:
+ with open(src, "rb") as ifp:
+ f.write(ifp.read())
env = Environment(BUILDERS={'Build':Builder(action=cat)})
env.Build('aaa.out', 'aaa.in')
diff --git a/test/python-version.py b/test/python-version.py
index 3cc3395..9cfd2bd 100644
--- a/test/python-version.py
+++ b/test/python-version.py
@@ -45,7 +45,7 @@ test.write('SetOption-python', "SetOption('warn', ['no-python-version'])\n")
if TestSCons.unsupported_python_version():
- error = "scons: \*\*\* SCons version \S+ does not run under Python version %s."
+ error = r"scons: \*\*\* SCons version \S+ does not run under Python version %s."
error = error % re.escape(TestSCons.python_version_string()) + "\n"
test.run(arguments = '-Q', status = 1, stderr = error)
diff --git a/test/question/basic.py b/test/question/basic.py
index 21e6206..968c4f7 100644
--- a/test/question/basic.py
+++ b/test/question/basic.py
@@ -36,10 +36,8 @@ _python_ = TestSCons._python_
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as ifp:
+ f.write(ifp.read())
""")
test.write('SConstruct', """
diff --git a/test/redirection.py b/test/redirection.py
index 3394523..0960dfd 100644
--- a/test/redirection.py
+++ b/test/redirection.py
@@ -42,18 +42,19 @@ if sys.platform == "win32":
try:
- input = open(sys.argv[1], 'rb').read()
+ with open(sys.argv[1], 'rb') as f:
+ indata = f.read()
except IndexError:
if PY3K:
source = sys.stdin.buffer
else:
source = sys.stdin
- input = source.read()
+ indata = source.read()
if PY3K:
- sys.stdout.buffer.write(input)
+ sys.stdout.buffer.write(indata)
else:
- sys.stdout.write(input)
+ sys.stdout.write(indata)
sys.exit(0)
""")
diff --git a/test/runtest/python.py b/test/runtest/python.py
index 14156e0..da62378 100644
--- a/test/runtest/python.py
+++ b/test/runtest/python.py
@@ -55,7 +55,7 @@ mypython = os.path.normpath(os.path.join(head, dir, os.path.pardir, dir, python)
def escape(s):
return s.replace('\\', '\\\\')
-if re.search('\s', mypython):
+if re.search(r'\s', mypython):
mypythonstring = '"%s"' % escape(mypython)
else:
mypythonstring = escape(mypython)
diff --git a/test/sconsign/corrupt.py b/test/sconsign/corrupt.py
index cab4d75..25b48e2 100644
--- a/test/sconsign/corrupt.py
+++ b/test/sconsign/corrupt.py
@@ -41,7 +41,8 @@ work2_sub__sconsign = test.workpath('work2', 'sub', '.sconsign')
SConstruct_contents = """\
def build1(target, source, env):
- open(str(target[0]), 'wb').write(open(str(source[0]), 'rb').read())
+ with open(str(target[0]), 'wb') as ofp, open(str(source[0]), 'rb') as ifp:
+ ofp.write(ifp.read())
return None
B1 = Builder(action = build1)
@@ -55,12 +56,12 @@ test.write(['work1', 'SConstruct'], SConstruct_contents)
test.write(['work1', 'foo.in'], "work1/foo.in\n")
-stderr = '''
+stderr = r'''
scons: warning: Ignoring corrupt .sconsign file: \.sconsign\.dblite
.*
'''
-stdout = test.wrap_stdout('build1\(\["sub.foo\.out"\], \["foo\.in"\]\)\n')
+stdout = test.wrap_stdout(r'build1\(\["sub.foo\.out"\], \["foo\.in"\]\)' + '\n')
test.write(work1__sconsign_dblite, 'not:a:sconsign:file')
test.run(chdir='work1', arguments='.', stderr=stderr, stdout=stdout)
@@ -80,12 +81,12 @@ test.write(['work2', 'SConstruct'], SConstruct_contents)
test.write(['work2', 'foo.in'], "work2/foo.in\n")
-stderr = '''
+stderr = r'''
scons: warning: Ignoring corrupt .sconsign file: sub.\.sconsign
.*
'''
-stdout = test.wrap_stdout('build1\(\["sub.foo\.out"\], \["foo\.in"\]\)\n')
+stdout = test.wrap_stdout(r'build1\(\["sub.foo\.out"\], \["foo\.in"\]\)' + '\n')
test.write(work2_sub__sconsign, 'not:a:sconsign:file')
test.run(chdir='work2', arguments='.', stderr=stderr, stdout=stdout)
diff --git a/test/sconsign/ghost-entries.py b/test/sconsign/ghost-entries.py
index 46916ca..59a1ec2 100644
--- a/test/sconsign/ghost-entries.py
+++ b/test/sconsign/ghost-entries.py
@@ -51,10 +51,10 @@ test = TestSCons.TestSCons()
test.write('SConstruct', """\
def cat(target, source, env):
- fp = open(str(target[0]), 'wb')
- for s in source:
- fp.write(open(str(s), 'rb').read())
- fp.close()
+ with open(str(target[0]), 'wb') as fp:
+ for s in source:
+ with open(str(s), 'rb') as infp:
+ fp.write(infp.read())
env=Environment()
Export('env')
env['BUILDERS']['Cat']=Builder(action=cat, multi=1)
diff --git a/test/sconsign/script/SConsignFile.py b/test/sconsign/script/SConsignFile.py
index 5e56624..8055b68 100644
--- a/test/sconsign/script/SConsignFile.py
+++ b/test/sconsign/script/SConsignFile.py
@@ -48,10 +48,6 @@ import re
import sys
path = sys.argv[1].split()
-output = open(sys.argv[2], 'w')
-input = open(sys.argv[3], 'r')
-
-output.write('fake_cc.py: %%s\n' %% sys.argv)
def find_file(f):
for dir in path:
@@ -62,14 +58,19 @@ def find_file(f):
def process(infp, outfp):
for line in infp.readlines():
- m = re.match('#include <(.*)>', line)
+ m = re.match(r'#include <(.*)>', line)
if m:
file = m.group(1)
- process(find_file(file), outfp)
+ found = find_file(file)
+ process(found, outfp)
+ if found:
+ found.close()
else:
outfp.write(line)
-process(input, output)
+with open(sys.argv[2], 'w') as outf, open(sys.argv[3], 'r') as ifp:
+ outf.write('fake_cc.py: %%s\n' %% sys.argv)
+ process(ifp, outf)
sys.exit(0)
""" % locals())
@@ -77,12 +78,9 @@ sys.exit(0)
test.write(fake_link_py, r"""#!%(_python_)s
import sys
-output = open(sys.argv[1], 'w')
-input = open(sys.argv[2], 'r')
-
-output.write('fake_link.py: %%s\n' %% sys.argv)
-
-output.write(input.read())
+with open(sys.argv[1], 'w') as outf, open(sys.argv[2], 'r') as ifp:
+ outf.write('fake_link.py: %%s\n' %% sys.argv)
+ outf.write(ifp.read())
sys.exit(0)
""" % locals())
diff --git a/test/sconsign/script/Signatures.py b/test/sconsign/script/Signatures.py
index 7797bce..24ffaf7 100644
--- a/test/sconsign/script/Signatures.py
+++ b/test/sconsign/script/Signatures.py
@@ -68,10 +68,6 @@ import re
import sys
path = sys.argv[1].split()
-output = open(sys.argv[2], 'w')
-input = open(sys.argv[3], 'r')
-
-output.write('fake_cc.py: %%s\n' %% sys.argv)
def find_file(f):
for dir in path:
@@ -85,11 +81,16 @@ def process(infp, outfp):
m = re.match('#include <(.*)>', line)
if m:
file = m.group(1)
- process(find_file(file), outfp)
+ found = find_file(file)
+ process(found, outfp)
+ if found:
+ found.close()
else:
outfp.write(line)
-process(input, output)
+with open(sys.argv[2], 'w') as outf, open(sys.argv[3], 'r') as ifp:
+ outf.write('fake_cc.py: %%s\n' %% sys.argv)
+ process(ifp, outf)
sys.exit(0)
""" % locals())
@@ -97,12 +98,9 @@ sys.exit(0)
test.write(fake_link_py, r"""#!%(_python_)s
import sys
-output = open(sys.argv[1], 'w')
-input = open(sys.argv[2], 'r')
-
-output.write('fake_link.py: %%s\n' %% sys.argv)
-
-output.write(input.read())
+with open(sys.argv[1], 'w') as outf, open(sys.argv[2], 'r') as ifp:
+ outf.write('fake_link.py: %%s\n' %% sys.argv)
+ outf.write(ifp.read())
sys.exit(0)
""" % locals())
diff --git a/test/sconsign/script/bad.py b/test/sconsign/script/bad.py
index a384748..5be42b9 100644
--- a/test/sconsign/script/bad.py
+++ b/test/sconsign/script/bad.py
@@ -38,13 +38,13 @@ test.write('bad2.dblite', "bad2.dblite\n")
test.write('bad3', "bad3\n")
test.run_sconsign(arguments = "-f dblite no_sconsign",
- stderr = "sconsign: \[Errno 2\] No such file or directory: 'no_sconsign'\n")
+ stderr = "sconsign: \\[Errno 2\\] No such file or directory: 'no_sconsign'\n")
test.run_sconsign(arguments = "-f dblite bad1",
- stderr = "sconsign: \[Errno 2\] No such file or directory: 'bad1.dblite'\n")
+ stderr = "sconsign: \\[Errno 2\\] No such file or directory: 'bad1.dblite'\n")
test.run_sconsign(arguments = "-f dblite bad1.dblite",
- stderr = "sconsign: \[Errno 2\] No such file or directory: 'bad1.dblite'\n")
+ stderr = "sconsign: \\[Errno 2\\] No such file or directory: 'bad1.dblite'\n")
test.run_sconsign(arguments = "-f dblite bad2",
stderr = "sconsign: ignoring invalid `dblite' file `bad2'.*\n")
@@ -53,7 +53,7 @@ test.run_sconsign(arguments = "-f dblite bad2.dblite",
stderr = "sconsign: ignoring invalid `dblite' file `bad2.dblite'.*\n")
test.run_sconsign(arguments = "-f sconsign no_sconsign",
- stderr = "sconsign: \[Errno 2\] No such file or directory: 'no_sconsign'\n")
+ stderr = "sconsign: \\[Errno 2\\] No such file or directory: 'no_sconsign'\n")
test.run_sconsign(arguments = "-f sconsign bad3",
stderr = "sconsign: ignoring invalid .sconsign file `bad3'.*\n")
diff --git a/test/sconsign/script/dblite.py b/test/sconsign/script/dblite.py
index 0daf8bf..41cf7e2 100644
--- a/test/sconsign/script/dblite.py
+++ b/test/sconsign/script/dblite.py
@@ -43,7 +43,7 @@ LINK = test.detect('LINK', norm=1)
if LINK is None: LINK = CC
def escape_drive_case(s):
- """Turn c\: into [cC]\:"""
+ r"""Turn c\: into [cC]\:"""
if re.match(r'^(.)[\\]?:', s):
drive=s[0]
return '['+drive.lower()+drive.upper()+']'+s[1:]
@@ -133,7 +133,7 @@ hello%(_obj)s: %(sig_re)s \d+ \d+
%(sig_re)s \[.*\]
""" % locals()
-expect_r = """=== sub1:
+expect_r = r"""=== sub1:
hello%(_exe)s: %(sig_re)s '%(date_re)s' \d+
%(sub1_hello_obj)s: %(sig_re)s '%(date_re)s' \d+
%(LINK)s: None '%(date_re)s' \d+
diff --git a/test/sconsign/script/no-SConsignFile.py b/test/sconsign/script/no-SConsignFile.py
index d9ab51f..cf5bcb2 100644
--- a/test/sconsign/script/no-SConsignFile.py
+++ b/test/sconsign/script/no-SConsignFile.py
@@ -57,10 +57,6 @@ import re
import sys
path = sys.argv[1].split()
-output = open(sys.argv[2], 'w')
-input = open(sys.argv[3], 'r')
-
-output.write('fake_cc.py: %%s\n' %% sys.argv)
def find_file(f):
for dir in path:
@@ -71,14 +67,19 @@ def find_file(f):
def process(infp, outfp):
for line in infp.readlines():
- m = re.match('#include <(.*)>', line)
+ m = re.match(r'#include <(.*)>', line)
if m:
file = m.group(1)
- process(find_file(file), outfp)
+ found = find_file(file)
+ process(found, outfp)
+ if found:
+ found.close()
else:
outfp.write(line)
-process(input, output)
+with open(sys.argv[2], 'w') as outf, open(sys.argv[3], 'r') as ifp:
+ outf.write('fake_cc.py: %%s\n' %% sys.argv)
+ process(ifp, outf)
sys.exit(0)
""" % locals())
@@ -86,12 +87,9 @@ sys.exit(0)
test.write(fake_link_py, r"""#!%(_python_)s
import sys
-output = open(sys.argv[1], 'w')
-input = open(sys.argv[2], 'r')
-
-output.write('fake_link.py: %%s\n' %% sys.argv)
-
-output.write(input.read())
+with open(sys.argv[1], 'w') as outf, open(sys.argv[2], 'r') as ifp:
+ outf.write('fake_link.py: %%s\n' %% sys.argv)
+ outf.write(ifp.read())
sys.exit(0)
""" % locals())
diff --git a/test/silent-command.py b/test/silent-command.py
index b0e4a2e..7f3b010 100644
--- a/test/silent-command.py
+++ b/test/silent-command.py
@@ -40,10 +40,10 @@ test.subdir('build', 'src')
test.write('build.py', r"""
import sys
-fp = open(sys.argv[1], 'wb')
-for f in sys.argv[2:]:
- fp.write(open(f, 'rb').read())
-fp.close()
+with open(sys.argv[1], 'wb') as fp:
+ for f in sys.argv[2:]:
+ with open(f, 'rb') as ifp:
+ fp.write(ifp.read())
""")
test.write('SConstruct', """\
diff --git a/test/site_scons/site_init.py b/test/site_scons/site_init.py
index 27768a9..e21b5f2 100644
--- a/test/site_scons/site_init.py
+++ b/test/site_scons/site_init.py
@@ -124,7 +124,7 @@ e.Foo(target='foo.out', source='SConstruct')
test.run(arguments = '-Q .',
stdout = "",
- stderr = """.*Error loading site_init file.*Huh\?.*""",
+ stderr = r".*Error loading site_init file.*Huh\?.*",
status=2,
match=TestSCons.match_re_dotall)
diff --git a/test/special-filenames.py b/test/special-filenames.py
index 798bf09..1ba764e 100644
--- a/test/special-filenames.py
+++ b/test/special-filenames.py
@@ -49,7 +49,8 @@ attempt_file_names = [
test.write("cat.py", """\
import sys
-open(sys.argv[1], 'wb').write(open(sys.argv[2], 'rb').read())
+with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as ifp:
+ f.write(ifp.read())
""")
file_names = []
diff --git a/test/srcchange.py b/test/srcchange.py
index 6916d50..e396fb8 100644
--- a/test/srcchange.py
+++ b/test/srcchange.py
@@ -44,7 +44,8 @@ test = TestSCons.TestSCons()
test.write('getrevision', """
from __future__ import print_function
-print(open('revnum.in','r').read().strip(), end='')
+with open('revnum.in','r') as f:
+ print(f.read().strip(), end='')
""")
test.write('SConstruct', """
@@ -52,12 +53,11 @@ import re
def subrevision(target, source ,env):
orig = target[0].get_text_contents()
- new = re.sub('\$REV.*?\$',
+ new = re.sub(r'\$REV.*?\$',
'$REV: %%s$'%%source[0].get_text_contents().strip(),
target[0].get_text_contents())
- outf = open(str(target[0]),'w')
- outf.write(new)
- outf.close()
+ with open(str(target[0]),'w') as outf:
+ outf.write(new)
SubRevision = Action(subrevision)
diff --git a/test/strfunction.py b/test/strfunction.py
index 8587dcb..04e23aa 100644
--- a/test/strfunction.py
+++ b/test/strfunction.py
@@ -36,7 +36,8 @@ test = TestSCons.TestSCons()
test.write('cat.py', """\
import sys
-open(sys.argv[2], "wb").write(open(sys.argv[1], "rb").read())
+with open(sys.argv[2], "wb") as f, open(sys.argv[1], "rb") as ifp:
+ f.write(ifp.read())
sys.exit(0)
""")
@@ -49,7 +50,8 @@ def strfunction(target, source, env):
def func(target, source, env):
t = str(target[0])
s = str(source[0])
- open(t, 'w').write(open(s, 'r').read())
+ with open(t, 'w') as f, open(s, 'r') as ifp:
+ f.write(ifp.read())
func1action = Action(func, strfunction)
func2action = Action(func, strfunction=strfunction)
diff --git a/test/subclassing.py b/test/subclassing.py
index b621bf5..ab4c7d5 100644
--- a/test/subclassing.py
+++ b/test/subclassing.py
@@ -54,7 +54,7 @@ env.Command('f0.out', 'f0.in', copy_action)
try:
from collections import UserString
except ImportError:
- exec('from UserString import UserString')
+ from UserString import UserString
try:
class mystr(str):
pass
diff --git a/test/subdir.py b/test/subdir.py
index 9a8b762..363d44c 100644
--- a/test/subdir.py
+++ b/test/subdir.py
@@ -35,10 +35,8 @@ test.subdir('subdir')
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'r').read()
-file = open(sys.argv[1], 'w')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'w') as f, open(sys.argv[2], 'r') as ifp:
+ f.write(ifp.read())
""")
test.write('SConstruct', """
diff --git a/test/subdivide.py b/test/subdivide.py
index 7ddc2e9..a4a128e 100644
--- a/test/subdivide.py
+++ b/test/subdivide.py
@@ -59,18 +59,20 @@ fake_link_py = test.workpath('fake_link.py')
test.write(fake_cc_py, """\
import sys
-ofp = open(sys.argv[1], 'w')
-ofp.write('fake_cc.py: %s\\n' % sys.argv)
-for s in sys.argv[2:]:
- ofp.write(open(s, 'r').read())
+with open(sys.argv[1], 'w') as ofp:
+ ofp.write('fake_cc.py: %s\\n' % sys.argv)
+ for s in sys.argv[2:]:
+ with open(s, 'r') as ifp:
+ ofp.write(ifp.read())
""")
test.write(fake_link_py, """\
import sys
-ofp = open(sys.argv[1], 'w')
-ofp.write('fake_link.py: %s\\n' % sys.argv)
-for s in sys.argv[2:]:
- ofp.write(open(s, 'r').read())
+with open(sys.argv[1], 'w') as ofp:
+ ofp.write('fake_link.py: %s\\n' % sys.argv)
+ for s in sys.argv[2:]:
+ with open(s, 'r') as ifp:
+ ofp.write(ifp.read())
""")
test.chmod(fake_cc_py, 0o755)
diff --git a/test/suffixes.py b/test/suffixes.py
index 74655ec..7684ee8 100644
--- a/test/suffixes.py
+++ b/test/suffixes.py
@@ -35,10 +35,10 @@ test = TestSCons.TestSCons()
test.write('SConstruct', """
def cat(env, source, target):
target = str(target[0])
- f = open(target, "wb")
- for src in source:
- f.write(open(str(src), "rb").read())
- f.close()
+ with open(target, "wb") as f:
+ for src in source:
+ with open(str(src), "rb") as ifp:
+ f.write(ifp.read())
Cat = Builder(action=cat, suffix='.out')
env = Environment(BUILDERS = {'Cat':Cat})
env.Cat('file1', 'file1.in')
diff --git a/test/timestamp-fallback.py b/test/timestamp-fallback.py
index 6b10033..f4e2e4d 100644
--- a/test/timestamp-fallback.py
+++ b/test/timestamp-fallback.py
@@ -63,8 +63,11 @@ os.environ['PYTHONPATH'] = test.workpath('.')
test.write('SConstruct', """
DefaultEnvironment(tools=[])
+
def build(env, target, source):
- open(str(target[0]), 'wt').write(open(str(source[0]), 'rt').read())
+ with open(str(target[0]), 'wt') as ofp, open(str(source[0]), 'rt') as ifp:
+ opf.write(ifp.read())
+
B = Builder(action = build)
env = Environment(tools = [], BUILDERS = { 'B' : B })
env.B(target = 'f1.out', source = 'f1.in')
@@ -90,10 +93,10 @@ build(["f4.out"], ["f4.in"])
"""),
stderr = None)
-os.utime(test.workpath('f1.in'),
+os.utime(test.workpath('f1.in'),
(os.path.getatime(test.workpath('f1.in')),
os.path.getmtime(test.workpath('f1.in'))+10))
-os.utime(test.workpath('f3.in'),
+os.utime(test.workpath('f3.in'),
(os.path.getatime(test.workpath('f3.in')),
os.path.getmtime(test.workpath('f3.in'))+10))
diff --git a/test/toolpath/VariantDir.py b/test/toolpath/VariantDir.py
index 4177550..652dde5 100644
--- a/test/toolpath/VariantDir.py
+++ b/test/toolpath/VariantDir.py
@@ -50,8 +50,8 @@ test.write(['subdir', 'src', 'tools', 'MyBuilder.py'], """\
from SCons.Script import Builder
def generate(env):
def my_copy(target, source, env):
- content = open(str(source[0]), 'rb').read()
- open(str(target[0]), 'wb').write(content)
+ with open(str(target[0]), 'wb') as f, open(str(source[0]), 'rb') as ifp:
+ f.write(ifp.read())
env['BUILDERS']['MyCopy'] = Builder(action = my_copy)
def exists(env):
diff --git a/test/up-to-date.py b/test/up-to-date.py
index d7381bd..12ea604 100644
--- a/test/up-to-date.py
+++ b/test/up-to-date.py
@@ -36,10 +36,8 @@ test = TestSCons.TestSCons()
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'rb').read()
-file = open(sys.argv[1], 'wb')
-file.write(contents)
-file.close()
+with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as ifp:
+ f.write(ifp.read())
""")
test.write('SConstruct', """