summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--SConstruct21
-rw-r--r--bin/SConsDoc.py172
-rw-r--r--site_scons/soe_utils.py18
-rw-r--r--src/engine/SCons/Action.py28
-rw-r--r--src/engine/SCons/ActionTests.py9
-rw-r--r--src/engine/SCons/Conftest.py4
-rw-r--r--src/engine/SCons/Node/FS.py4
-rw-r--r--src/engine/SCons/Platform/PlatformTests.py3
-rw-r--r--src/engine/SCons/Platform/darwin.py11
-rw-r--r--src/engine/SCons/Platform/win32.py12
-rw-r--r--src/engine/SCons/SConsign.py5
-rw-r--r--src/engine/SCons/Scanner/RC.py6
-rw-r--r--src/engine/SCons/Tool/PharLapCommon.py3
-rw-r--r--src/engine/SCons/Tool/__init__.py9
-rw-r--r--src/engine/SCons/Tool/clang.py3
-rw-r--r--src/engine/SCons/Tool/clangxx.py3
-rw-r--r--src/engine/SCons/Tool/docbook/__init__.py182
-rw-r--r--src/engine/SCons/Tool/hpcxx.py3
-rw-r--r--src/engine/SCons/Tool/ipkg.py6
-rw-r--r--src/engine/SCons/Tool/mingw.py2
-rw-r--r--src/engine/SCons/Tool/msvs.py20
-rw-r--r--src/engine/SCons/Tool/packaging/msi.py21
-rw-r--r--src/engine/SCons/Tool/packaging/rpm.py8
-rw-r--r--src/engine/SCons/Tool/qt.py13
-rw-r--r--src/engine/SCons/Tool/rpm.py23
-rw-r--r--src/engine/SCons/Tool/rpmutils.py39
-rw-r--r--src/engine/SCons/Tool/suncxx.py12
-rw-r--r--src/engine/SCons/Util.py20
-rw-r--r--src/test_interrupts.py3
-rw-r--r--src/test_pychecker.py3
-rw-r--r--src/test_setup.py33
-rw-r--r--src/test_strings.py3
-rw-r--r--test/AS/as-live.py3
-rw-r--r--test/AS/fixture/myas.py25
-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.py33
-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/Parallel/failed-build.py9
-rw-r--r--test/ParseDepends.py6
-rw-r--r--test/QT/qt_warnings.py2
-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.py25
-rw-r--r--test/fixture/mylink.py66
-rw-r--r--test/fixture/myrewrite.py22
-rw-r--r--test/fixture/wrapper.py10
-rw-r--r--test/fixture/wrapper_with_args.py10
-rw-r--r--test/gnutools.py40
-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/leaky-handles.py9
-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/explicit-target.py4
-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
-rw-r--r--testing/framework/SConscript13
-rw-r--r--testing/framework/TestSCons.py62
-rw-r--r--testing/framework/TestSConsMSVS.py8
372 files changed, 1879 insertions, 1672 deletions
diff --git a/SConstruct b/SConstruct
index 590aedf..dc9ee5d 100644
--- a/SConstruct
+++ b/SConstruct
@@ -96,14 +96,16 @@ git_status_lines = []
if git:
cmd = "%s ls-files 2> /dev/null" % git
- git_status_lines = os.popen(cmd, "r").readlines()
+ with os.popen(cmd, "r") as p:
+ git_status_lines = p.readlines()
revision = ARGUMENTS.get('REVISION', '')
def generate_build_id(revision):
return revision
if not revision and git:
- git_hash = os.popen("%s rev-parse HEAD 2> /dev/null" % git, "r").read().strip()
+ with os.popen("%s rev-parse HEAD 2> /dev/null" % git, "r") as p:
+ git_hash = p.read().strip()
def generate_build_id(revision):
result = git_hash
if [l for l in git_status_lines if 'modified' in l]:
@@ -570,10 +572,9 @@ for p in [ scons ]:
def write_src_files(target, source, **kw):
global src_files
src_files.sort()
- f = open(str(target[0]), 'w')
- for file in src_files:
- f.write(file + "\n")
- f.close()
+ with open(str(target[0]), 'w') as f:
+ for file in src_files:
+ f.write(file + "\n")
return 0
env.Command(os.path.join(build, 'MANIFEST'),
MANIFEST_in_list,
@@ -662,14 +663,14 @@ for p in [ scons ]:
def Digestify(target, source, env):
import hashlib
src = source[0].rfile()
- contents = open(str(src),'rb').read()
+ with open(str(src),'rb') as f:
+ contents = f.read()
m = hashlib.md5()
m.update(contents)
sig = m.hexdigest()
bytes = os.stat(str(src))[6]
- open(str(target[0]), 'w').write("MD5 %s %s %d\n" % (sig,
- src.name,
- bytes))
+ with open(str(target[0]), 'w') as f:
+ f.write("MD5 %s %s %d\n" % (sig, src.name, bytes))
env.Command(digest, tar_gz, Digestify)
if not zipit:
diff --git a/bin/SConsDoc.py b/bin/SConsDoc.py
index bd9c90d..962073e 100644
--- a/bin/SConsDoc.py
+++ b/bin/SConsDoc.py
@@ -178,22 +178,21 @@ def isSConsXml(fpath):
contains the default target namespace definition.
"""
try:
- f = open(fpath,'r')
- content = f.read()
- f.close()
+ with open(fpath,'r') as f:
+ content = f.read()
if content.find('xmlns="%s"' % dbxsd) >= 0:
return True
except:
pass
-
- return False
+
+ return False
def remove_entities(content):
# Cut out entity inclusions
content = re_entity_header.sub("", content, re.M)
# Cut out entities themselves
content = re_entity.sub(lambda match: match.group(1), content)
-
+
return content
default_xsd = os.path.join('doc','xsd','scons.xsd')
@@ -201,11 +200,11 @@ default_xsd = os.path.join('doc','xsd','scons.xsd')
ARG = "dbscons"
class Libxml2ValidityHandler:
-
+
def __init__(self):
self.errors = []
self.warnings = []
-
+
def error(self, msg, data):
if data != ARG:
raise Exception("Error handler did not receive correct argument")
@@ -221,14 +220,14 @@ class DoctypeEntity:
def __init__(self, name_, uri_):
self.name = name_
self.uri = uri_
-
+
def getEntityString(self):
txt = """ <!ENTITY %(perc)s %(name)s SYSTEM "%(uri)s">
%(perc)s%(name)s;
""" % {'perc' : perc, 'name' : self.name, 'uri' : self.uri}
return txt
-
+
class DoctypeDeclaration:
def __init__(self, name_=None):
self.name = name_
@@ -241,23 +240,23 @@ class DoctypeDeclaration:
self.addEntity("functions-mod", "functions.mod")
self.addEntity("tools-mod", "tools.mod")
self.addEntity("variables-mod", "variables.mod")
-
+
def addEntity(self, name, uri):
self.entries.append(DoctypeEntity(name, uri))
-
+
def createDoctype(self):
content = '<!DOCTYPE %s [\n' % self.name
for e in self.entries:
content += e.getEntityString()
content += ']>\n'
-
+
return content
if not has_libxml2:
class TreeFactory:
def __init__(self):
pass
-
+
def newNode(self, tag):
return etree.Element(tag)
@@ -268,22 +267,22 @@ if not has_libxml2:
return etree.Element(tag, nsmap=NSMAP)
return etree.Element(tag)
-
+
def copyNode(self, node):
return copy.deepcopy(node)
-
+
def appendNode(self, parent, child):
parent.append(child)
def hasAttribute(self, node, att):
return att in node.attrib
-
+
def getAttribute(self, node, att):
return node.attrib[att]
-
+
def setAttribute(self, node, att, value):
node.attrib[att] = value
-
+
def getText(self, root):
return root.text
@@ -292,30 +291,27 @@ if not has_libxml2:
def writeGenTree(self, root, fp):
dt = DoctypeDeclaration()
- fp.write(etree.tostring(root, xml_declaration=True,
- encoding="UTF-8", pretty_print=True,
+ fp.write(etree.tostring(root, xml_declaration=True,
+ encoding="UTF-8", pretty_print=True,
doctype=dt.createDoctype()))
def writeTree(self, root, fpath):
- fp = open(fpath, 'w')
- fp.write(etree.tostring(root, xml_declaration=True,
- encoding="UTF-8", pretty_print=True))
- fp.close()
+ with open(fpath, 'w') as fp:
+ fp.write(etree.tostring(root, xml_declaration=True,
+ encoding="UTF-8", pretty_print=True))
def prettyPrintFile(self, fpath):
- fin = open(fpath,'r')
- tree = etree.parse(fin)
- pretty_content = etree.tostring(tree, pretty_print=True)
- fin.close()
-
- fout = open(fpath,'w')
- fout.write(pretty_content)
- fout.close()
+ with open(fpath,'r') as fin:
+ tree = etree.parse(fin)
+ pretty_content = etree.tostring(tree, pretty_print=True)
+
+ with open(fpath,'w') as fout:
+ fout.write(pretty_content)
def decorateWithHeader(self, root):
root.attrib["{"+xsi+"}schemaLocation"] = "%s %s/scons.xsd" % (dbxsd, dbxsd)
return root
-
+
def newXmlTree(self, root):
""" Return a XML file tree with the correct namespaces set,
the element root as top entry and the given header comment.
@@ -324,7 +320,7 @@ if not has_libxml2:
'xsi' : xsi}
t = etree.Element(root, nsmap=NSMAP)
return self.decorateWithHeader(t)
-
+
def validateXml(self, fpath, xmlschema_context):
# Use lxml
xmlschema = etree.XMLSchema(xmlschema_context)
@@ -361,21 +357,21 @@ if not has_libxml2:
current XML toolkit.
"""
return [root]
-
-else:
+
+else:
class TreeFactory:
def __init__(self):
pass
-
+
def newNode(self, tag):
return libxml2.newNode(tag)
def newEtreeNode(self, tag, init_ns=False):
return etree.Element(tag)
-
+
def copyNode(self, node):
return node.copyNode(1)
-
+
def appendNode(self, parent, child):
if hasattr(parent, 'addChild'):
parent.addChild(child)
@@ -386,7 +382,7 @@ else:
if hasattr(node, 'hasProp'):
return node.hasProp(att)
return att in node.attrib
-
+
def getAttribute(self, node, att):
if hasattr(node, 'prop'):
return node.prop(att)
@@ -397,7 +393,7 @@ else:
node.setProp(att, value)
else:
node.attrib[att] = value
-
+
def getText(self, root):
if hasattr(root, 'getContent'):
return root.getContent()
@@ -425,20 +421,18 @@ else:
doc.freeDoc()
def writeTree(self, root, fpath):
- fp = open(fpath, 'w')
- doc = libxml2.newDoc('1.0')
- doc.setRootElement(root)
- fp.write(doc.serialize("UTF-8", 1))
- doc.freeDoc()
- fp.close()
+ with open(fpath, 'w') as fp:
+ doc = libxml2.newDoc('1.0')
+ doc.setRootElement(root)
+ fp.write(doc.serialize("UTF-8", 1))
+ doc.freeDoc()
def prettyPrintFile(self, fpath):
# Read file and resolve entities
doc = libxml2.readFile(fpath, None, libxml2d.XML_PARSE_NOENT)
- fp = open(fpath, 'w')
- # Prettyprint
- fp.write(doc.serialize("UTF-8", 1))
- fp.close()
+ with open(fpath, 'w') as fp:
+ # Prettyprint
+ fp.write(doc.serialize("UTF-8", 1))
# Cleanup
doc.freeDoc()
@@ -447,9 +441,9 @@ else:
ns = root.newNs(dbxsd, None)
xi = root.newNs(xsi, 'xsi')
root.setNs(ns) #put this node in the target namespace
-
+
root.setNsProp(xi, 'schemaLocation', "%s %s/scons.xsd" % (dbxsd, dbxsd))
-
+
return root
def newXmlTree(self, root):
@@ -461,7 +455,7 @@ else:
def validateXml(self, fpath, xmlschema_context):
retval = True
-
+
# Create validation context
validation_context = xmlschema_context.schemaNewValidCtxt()
# Set error/warning handlers
@@ -471,18 +465,18 @@ else:
doc = libxml2.readFile(fpath, None, libxml2.XML_PARSE_NOENT)
doc.xincludeProcessFlags(libxml2.XML_PARSE_NOENT)
err = validation_context.schemaValidateDoc(doc)
-
+
if err or eh.errors:
for e in eh.errors:
print(e.rstrip("\n"))
# import pdb; pdb.set_trace()
print("%s fails to validate" % fpath)
retval = False
-
+
# Cleanup
doc.freeDoc()
del validation_context
-
+
return retval
def findAll(self, root, tag, ns=None, xpath_context=None, nsmap=None):
@@ -506,7 +500,7 @@ else:
expression = "./%s/node()" % tag
if ns:
expression = "./%s:%s/node()" % (ns, tag)
-
+
return xpath_context.xpathEval(expression)
else:
expression = "./{%s}%s/node()" % (nsmap[ns], tag)
@@ -536,7 +530,7 @@ else:
if child.tail:
tail = libxml2.newText(child.tail)
elements.append(tail)
-
+
return elements
def convertElementTree(self, root):
@@ -562,7 +556,7 @@ else:
if root.tail:
tail = libxml2.newText(root.tail)
elements.append(tail)
-
+
return elements
tf = TreeFactory()
@@ -603,7 +597,7 @@ class SConsDocTree:
# Register namespaces
for key, val in self.nsmap.items():
self.xpath_context.xpathRegisterNs(key, val)
-
+
def __del__(self):
if self.doc is not None:
self.doc.freeDoc()
@@ -622,7 +616,7 @@ def validate_all_xml(dpaths, xsdfile=default_xsd):
ctxt = libxml2.schemaNewParserCtxt(xsdfile)
xmlschema_context = ctxt.schemaParse()
del ctxt
-
+
fpaths = []
for dp in dpaths:
if dp.endswith('.xml') and isSConsXml(dp):
@@ -635,13 +629,13 @@ def validate_all_xml(dpaths, xsdfile=default_xsd):
fp = os.path.join(path, f)
if isSConsXml(fp):
fpaths.append(fp)
-
+
fails = []
for idx, fp in enumerate(fpaths):
fpath = os.path.join(path, fp)
print("%.2f%s (%d/%d) %s" % (float(idx+1)*100.0/float(len(fpaths)),
perc, idx+1, len(fpaths),fp))
-
+
if not tf.validateXml(fp, xmlschema_context):
fails.append(fp)
continue
@@ -652,7 +646,7 @@ def validate_all_xml(dpaths, xsdfile=default_xsd):
if fails:
return False
-
+
return True
class Item(object):
@@ -733,10 +727,10 @@ class SConsDocHandler(object):
uses.extend(self.parseItems(u, xpath_context, nsmap))
for s in tf.findAll(domelem, "sets", dbxid, xpath_context, nsmap):
sets.extend(self.parseItems(s, xpath_context, nsmap))
-
+
return sorted(uses), sorted(sets)
- def parseInstance(self, domelem, map, Class,
+ def parseInstance(self, domelem, map, Class,
xpath_context, nsmap, include_entities=True):
name = 'unknown'
if tf.hasAttribute(domelem, 'name'):
@@ -760,24 +754,24 @@ class SConsDocHandler(object):
instance.arguments = []
instance.arguments.append(tf.copyNode(a))
- def parseDomtree(self, root, xpath_context=None, nsmap=None, include_entities=True):
+ def parseDomtree(self, root, xpath_context=None, nsmap=None, include_entities=True):
# Process Builders
for b in tf.findAll(root, "builder", dbxid, xpath_context, nsmap):
- self.parseInstance(b, self.builders, Builder,
+ self.parseInstance(b, self.builders, Builder,
xpath_context, nsmap, include_entities)
# Process Functions
for f in tf.findAll(root, "scons_function", dbxid, xpath_context, nsmap):
- self.parseInstance(f, self.functions, Function,
+ self.parseInstance(f, self.functions, Function,
xpath_context, nsmap, include_entities)
# Process Tools
for t in tf.findAll(root, "tool", dbxid, xpath_context, nsmap):
- self.parseInstance(t, self.tools, Tool,
+ self.parseInstance(t, self.tools, Tool,
xpath_context, nsmap, include_entities)
# Process CVars
for c in tf.findAll(root, "cvar", dbxid, xpath_context, nsmap):
- self.parseInstance(c, self.cvars, ConstructionVariable,
+ self.parseInstance(c, self.cvars, ConstructionVariable,
xpath_context, nsmap, include_entities)
-
+
def parseContent(self, content, include_entities=True):
""" Parses the given content as XML file. This method
is used when we generate the basic lists of entities
@@ -798,28 +792,26 @@ class SConsDocHandler(object):
t.parseXmlFile(fpath)
# Parse it
self.parseDomtree(t.root, t.xpath_context, t.nsmap)
-
+
# lifted from Ka-Ping Yee's way cool pydoc module.
if sys.version_info[0] == 2:
def importfile(path):
"""Import a Python source file or compiled file given its path."""
import imp
magic = imp.get_magic()
- file = open(path, 'r')
- if file.read(len(magic)) == magic:
- kind = imp.PY_COMPILED
- else:
- kind = imp.PY_SOURCE
- file.close()
+ with open(path, 'r') as ifp:
+ if ifp.read(len(magic)) == magic:
+ kind = imp.PY_COMPILED
+ else:
+ kind = imp.PY_SOURCE
filename = os.path.basename(path)
name, ext = os.path.splitext(filename)
- file = open(path, 'r')
- try:
- module = imp.load_module(name, file, path, (ext, 'r', kind))
- except ImportError as e:
- sys.stderr.write("Could not import %s: %s\n" % (path, e))
- return None
- file.close()
+ with open(path, 'r') as ifp:
+ try:
+ module = imp.load_module(name, ifp, path, (ext, 'r', kind))
+ except ImportError as e:
+ sys.stderr.write("Could not import %s: %s\n" % (path, e))
+ return None
return module
else: # PY3 version, from newer pydoc
@@ -828,8 +820,8 @@ else: # PY3 version, from newer pydoc
import importlib
from pydoc import ErrorDuringImport
magic = importlib.util.MAGIC_NUMBER
- with open(path, 'rb') as file:
- is_bytecode = magic == file.read(len(magic))
+ with open(path, 'rb') as ifp:
+ is_bytecode = magic == ifp.read(len(magic))
filename = os.path.basename(path)
name, ext = os.path.splitext(filename)
if is_bytecode:
diff --git a/site_scons/soe_utils.py b/site_scons/soe_utils.py
index 451c7de..3b87dee 100644
--- a/site_scons/soe_utils.py
+++ b/site_scons/soe_utils.py
@@ -17,16 +17,14 @@ def soelim(target, source, env):
t = str(target[0])
s = str(source[0])
dir, f = os.path.split(s)
- tfp = open(t, 'w')
- sfp = open(s, 'r')
- for line in sfp.readlines():
- if line[:4] in ['.so ', "'so "]:
- sofile = os.path.join(dir, line[4:-1])
- tfp.write(open(sofile, 'r').read())
- else:
- tfp.write(line)
- sfp.close()
- tfp.close()
+ with open(t, 'w') as tfp, open(s, 'r') as sfp:
+ for line in sfp.readlines():
+ if line[:4] in ['.so ', "'so "]:
+ sofile = os.path.join(dir, line[4:-1])
+ with open(sofile, 'r') as f:
+ tfp.write(f.read())
+ else:
+ tfp.write(line)
def soscan(node, env, path):
c = node.get_text_contents()
diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py
index 1257309..d1ab362 100644
--- a/src/engine/SCons/Action.py
+++ b/src/engine/SCons/Action.py
@@ -211,7 +211,7 @@ def _object_contents(obj):
def _code_contents(code, docstring=None):
- """Return the signature contents of a code object.
+ r"""Return the signature contents of a code object.
By providing direct access to the code object of the
function, Python makes this extremely easy. Hooray!
@@ -767,16 +767,22 @@ def _subproc(scons_env, cmd, error = 'ignore', **kw):
it'll have to be tweaked to get the full desired functionality.
one special arg (so far?), 'error', to tell what to do with exceptions.
"""
- # allow std{in,out,err} to be "'devnull'"
- io = kw.get('stdin')
- if is_String(io) and io == 'devnull':
- kw['stdin'] = open(os.devnull)
- io = kw.get('stdout')
- if is_String(io) and io == 'devnull':
- kw['stdout'] = open(os.devnull, 'w')
- io = kw.get('stderr')
- if is_String(io) and io == 'devnull':
- kw['stderr'] = open(os.devnull, 'w')
+ # allow std{in,out,err} to be "'devnull'". This is like
+ # subprocess.DEVNULL, which does not exist for Py2. Use the
+ # subprocess one if possible.
+ # Clean this up when Py2 support is dropped
+ try:
+ from subprocess import DEVNULL
+ except ImportError:
+ DEVNULL = None
+
+ for stream in 'stdin', 'stdout', 'stderr':
+ io = kw.get(stream)
+ if is_String(io) and io == 'devnull':
+ if DEVNULL:
+ kw[stream] = DEVNULL
+ else:
+ kw[stream] = open(os.devnull, "r+")
# Figure out what shell environment to use
ENV = kw.get('env', None)
diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py
index 042d3dd..34fea45 100644
--- a/src/engine/SCons/ActionTests.py
+++ b/src/engine/SCons/ActionTests.py
@@ -1529,6 +1529,7 @@ class CommandGeneratorActionTestCase(unittest.TestCase):
(3, 5): bytearray(b'0, 0, 0, 0,(),(),(d\x00\x00S),(),()'),
(3, 6): bytearray(b'0, 0, 0, 0,(),(),(d\x00S\x00),(),()'),
(3, 7): bytearray(b'0, 0, 0, 0,(),(),(d\x00S\x00),(),()'),
+ (3, 8): bytearray(b'0, 0, 0, 0,(),(),(d\x00S\x00),(),()'),
}
meth_matches = [
@@ -1707,6 +1708,7 @@ class FunctionActionTestCase(unittest.TestCase):
(3, 5): bytearray(b'0, 0, 0, 0,(),(),(d\x00\x00S),(),()'),
(3, 6): bytearray(b'0, 0, 0, 0,(),(),(d\x00S\x00),(),()'),
(3, 7): bytearray(b'0, 0, 0, 0,(),(),(d\x00S\x00),(),()'),
+ (3, 8): bytearray(b'0, 0, 0, 0,(),(),(d\x00S\x00),(),()'),
}
@@ -1715,6 +1717,7 @@ class FunctionActionTestCase(unittest.TestCase):
(3, 5): bytearray(b'1, 1, 0, 0,(),(),(d\x00\x00S),(),()'),
(3, 6): bytearray(b'1, 1, 0, 0,(),(),(d\x00S\x00),(),()'),
(3, 7): bytearray(b'1, 1, 0, 0,(),(),(d\x00S\x00),(),()'),
+ (3, 8): bytearray(b'1, 1, 0, 0,(),(),(d\x00S\x00),(),()'),
}
def factory(act, **kw):
@@ -1959,6 +1962,7 @@ class LazyActionTestCase(unittest.TestCase):
(3, 5): bytearray(b'0, 0, 0, 0,(),(),(d\x00\x00S),(),()'),
(3, 6): bytearray(b'0, 0, 0, 0,(),(),(d\x00S\x00),(),()'),
(3, 7): bytearray(b'0, 0, 0, 0,(),(),(d\x00S\x00),(),()'),
+ (3, 8): bytearray(b'0, 0, 0, 0,(),(),(d\x00S\x00),(),()'),
}
meth_matches = [
@@ -2017,6 +2021,7 @@ class ActionCallerTestCase(unittest.TestCase):
(3, 5): b'd\x00\x00S',
(3, 6): b'd\x00S\x00',
(3, 7): b'd\x00S\x00',
+ (3, 8): b'd\x00S\x00',
}
@@ -2217,6 +2222,7 @@ class ObjectContentsTestCase(unittest.TestCase):
(3, 5): bytearray(b'3, 3, 0, 0,(),(),(|\x00\x00S),(),()'),
(3, 6): bytearray(b'3, 3, 0, 0,(),(),(|\x00S\x00),(),()'),
(3, 7): bytearray(b'3, 3, 0, 0,(),(),(|\x00S\x00),(),()'),
+ (3, 8): bytearray(b'3, 3, 0, 0,(),(),(|\x00S\x00),(),()'),
}
c = SCons.Action._function_contents(func1)
@@ -2242,6 +2248,8 @@ class ObjectContentsTestCase(unittest.TestCase):
b"{TestClass:__main__}[[[(<class \'object\'>, ()), [(<class \'__main__.TestClass\'>, (<class \'object\'>,))]]]]{{1, 1, 0, 0,(a,b),(a,b),(d\x01|\x00_\x00d\x02|\x00_\x01d\x00S\x00),(),(),2, 2, 0, 0,(),(),(d\x00S\x00),(),()}}{{{a=a,b=b}}}"),
(3, 7): bytearray(
b"{TestClass:__main__}[[[(<class \'object\'>, ()), [(<class \'__main__.TestClass\'>, (<class \'object\'>,))]]]]{{1, 1, 0, 0,(a,b),(a,b),(d\x01|\x00_\x00d\x02|\x00_\x01d\x00S\x00),(),(),2, 2, 0, 0,(),(),(d\x00S\x00),(),()}}{{{a=a,b=b}}}"),
+ (3, 8): bytearray(
+ b"{TestClass:__main__}[[[(<class \'object\'>, ()), [(<class \'__main__.TestClass\'>, (<class \'object\'>,))]]]]{{1, 1, 0, 0,(a,b),(a,b),(d\x01|\x00_\x00d\x02|\x00_\x01d\x00S\x00),(),(),2, 2, 0, 0,(),(),(d\x00S\x00),(),()}}{{{a=a,b=b}}}"),
}
assert c == expected[sys.version_info[:2]], "Got\n" + repr(c) + "\nExpected \n" + "\n" + repr(
@@ -2259,6 +2267,7 @@ class ObjectContentsTestCase(unittest.TestCase):
(3, 5): bytearray(b'0, 0, 0, 0,(Hello, World!),(print),(e\x00\x00d\x00\x00\x83\x01\x00\x01d\x01\x00S)'),
(3, 6): bytearray(b'0, 0, 0, 0,(Hello, World!),(print),(e\x00d\x00\x83\x01\x01\x00d\x01S\x00)'),
(3, 7): bytearray(b'0, 0, 0, 0,(Hello, World!),(print),(e\x00d\x00\x83\x01\x01\x00d\x01S\x00)'),
+ (3, 8): bytearray(b'0, 0, 0, 0,(Hello, World!),(print),(e\x00d\x00\x83\x01\x01\x00d\x01S\x00)'),
}
assert c == expected[sys.version_info[:2]], "Got\n" + repr(c) + "\nExpected \n" + "\n" + repr(expected[
diff --git a/src/engine/SCons/Conftest.py b/src/engine/SCons/Conftest.py
index 6b7e810..1163aa3 100644
--- a/src/engine/SCons/Conftest.py
+++ b/src/engine/SCons/Conftest.py
@@ -704,7 +704,7 @@ def CheckProg(context, prog_name):
#
def _YesNoResult(context, ret, key, text, comment = None):
- """
+ r"""
Handle the result of a test with a "yes" or "no" result.
:Parameters:
@@ -723,7 +723,7 @@ def _YesNoResult(context, ret, key, text, comment = None):
def _Have(context, key, have, comment = None):
- """
+ r"""
Store result of a test in context.havedict and context.headerfilename.
:Parameters:
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py
index 44c6f83..91d349d 100644
--- a/src/engine/SCons/Node/FS.py
+++ b/src/engine/SCons/Node/FS.py
@@ -480,7 +480,7 @@ class EntryProxy(SCons.Util.Proxy):
return SCons.Subst.SpecialAttrWrapper(r, entry.name + "_posix")
def __get_windows_path(self):
- """Return the path with \ as the path separator,
+ r"""Return the path with \ as the path separator,
regardless of platform."""
if OS_SEP == '\\':
return self
@@ -1418,7 +1418,7 @@ class FS(LocalFS):
self.Top.addRepository(d)
def PyPackageDir(self, modulename):
- """Locate the directory of a given python module name
+ r"""Locate the directory of a given python module name
For example scons might resolve to
Windows: C:\Python27\Lib\site-packages\scons-2.5.1
diff --git a/src/engine/SCons/Platform/PlatformTests.py b/src/engine/SCons/Platform/PlatformTests.py
index ae070f8..c89610f 100644
--- a/src/engine/SCons/Platform/PlatformTests.py
+++ b/src/engine/SCons/Platform/PlatformTests.py
@@ -186,7 +186,8 @@ class TempFileMungeTestCase(unittest.TestCase):
cmd = t(None, None, env, 0)
# print("CMD is:%s"%cmd)
- file_content = open(cmd[-1],'rb').read()
+ with open(cmd[-1],'rb') as f:
+ file_content = f.read()
# print("Content is:[%s]"%file_content)
# ...and restoring its setting.
SCons.Action.print_actions = old_actions
diff --git a/src/engine/SCons/Platform/darwin.py b/src/engine/SCons/Platform/darwin.py
index c85b75b..fd697f6 100644
--- a/src/engine/SCons/Platform/darwin.py
+++ b/src/engine/SCons/Platform/darwin.py
@@ -56,12 +56,11 @@ def generate(env):
for file in filelist:
if os.path.isfile(file):
- f = open(file, 'r')
- lines = f.readlines()
- for line in lines:
- if line:
- env.AppendENVPath('PATHOSX', line.strip('\n'))
- f.close()
+ with open(file, 'r') as f:
+ lines = f.readlines()
+ for line in lines:
+ if line:
+ env.AppendENVPath('PATHOSX', line.strip('\n'))
# Not sure why this wasn't the case all along?
if env['ENV'].get('PATHOSX', False) and os.environ.get('SCONS_USE_MAC_PATHS', False):
diff --git a/src/engine/SCons/Platform/win32.py b/src/engine/SCons/Platform/win32.py
index be30546..0a3b199 100644
--- a/src/engine/SCons/Platform/win32.py
+++ b/src/engine/SCons/Platform/win32.py
@@ -193,7 +193,7 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr):
# actually do the spawn
try:
- args = [sh, '/C', escape(' '.join(args)) ]
+ args = [sh, '/C', escape(' '.join(args))]
ret = spawnve(os.P_WAIT, sh, args, env)
except OSError as e:
# catch any error
@@ -207,15 +207,17 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr):
# and do clean up stuff
if stdout is not None and stdoutRedirected == 0:
try:
- stdout.write(open( tmpFileStdout, "r" ).read())
- os.remove( tmpFileStdout )
+ with open(tmpFileStdout, "r" ) as tmp:
+ stdout.write(tmp.read())
+ os.remove(tmpFileStdout)
except (IOError, OSError):
pass
if stderr is not None and stderrRedirected == 0:
try:
- stderr.write(open( tmpFileStderr, "r" ).read())
- os.remove( tmpFileStderr )
+ with open(tmpFileStderr, "r" ) as tmp:
+ stderr.write(tmp.read())
+ os.remove(tmpFileStderr)
except (IOError, OSError):
pass
return ret
diff --git a/src/engine/SCons/SConsign.py b/src/engine/SCons/SConsign.py
index 8b2dc61..1115f2a 100644
--- a/src/engine/SCons/SConsign.py
+++ b/src/engine/SCons/SConsign.py
@@ -339,6 +339,11 @@ class DirFile(Dir):
SCons.Warnings.warn(SCons.Warnings.CorruptSConsignWarning,
"Ignoring corrupt .sconsign file: %s"%self.sconsign)
+ try:
+ fp.close()
+ except AttributeError:
+ pass
+
global sig_files
sig_files.append(self)
diff --git a/src/engine/SCons/Scanner/RC.py b/src/engine/SCons/Scanner/RC.py
index 82f8ddc..abaaef7 100644
--- a/src/engine/SCons/Scanner/RC.py
+++ b/src/engine/SCons/Scanner/RC.py
@@ -48,9 +48,9 @@ def RCScan():
"""Return a prototype Scanner instance for scanning RC source files"""
res_re= r'^(?:\s*#\s*(?:include)|' \
- '.*?\s+(?:ICON|BITMAP|CURSOR|HTML|FONT|MESSAGETABLE|TYPELIB|REGISTRY|D3DFX)' \
- '\s*.*?)' \
- '\s*(<|"| )([^>"\s]+)(?:[>"\s])*$'
+ r'.*?\s+(?:ICON|BITMAP|CURSOR|HTML|FONT|MESSAGETABLE|TYPELIB|REGISTRY|D3DFX)' \
+ r'\s*.*?)' \
+ r'\s*(<|"| )([^>"\s]+)(?:[>"\s])*$'
resScanner = SCons.Scanner.ClassicCPP("ResourceScanner",
"$RCSUFFIXES",
"CPPPATH",
diff --git a/src/engine/SCons/Tool/PharLapCommon.py b/src/engine/SCons/Tool/PharLapCommon.py
index 864a185..9ffafa9 100644
--- a/src/engine/SCons/Tool/PharLapCommon.py
+++ b/src/engine/SCons/Tool/PharLapCommon.py
@@ -79,7 +79,8 @@ def getPharLapVersion():
include_path = os.path.join(getPharLapPath(), os.path.normpath("include/embkern.h"))
if not os.path.exists(include_path):
raise SCons.Errors.UserError("Cannot find embkern.h in ETS include directory.\nIs Phar Lap ETS installed properly?")
- mo = REGEX_ETS_VER.search(open(include_path, 'r').read())
+ with open(include_path, 'r') as f:
+ mo = REGEX_ETS_VER.search(f.read())
if mo:
return int(mo.group(1))
# Default return for Phar Lap 9.1
diff --git a/src/engine/SCons/Tool/__init__.py b/src/engine/SCons/Tool/__init__.py
index cc935d1..c8fb389 100644
--- a/src/engine/SCons/Tool/__init__.py
+++ b/src/engine/SCons/Tool/__init__.py
@@ -51,7 +51,12 @@ import SCons.Scanner.D
import SCons.Scanner.LaTeX
import SCons.Scanner.Prog
import SCons.Scanner.SWIG
-import collections
+try:
+ # Python 3
+ from collections.abc import Callable
+except ImportError:
+ # Python 2.7
+ from collections import Callable
DefaultToolpath = []
@@ -378,7 +383,7 @@ def _call_linker_cb(env, callback, args, result=None):
if Verbose:
print('_call_linker_cb: env["LINKCALLBACKS"][%r] found' % callback)
print('_call_linker_cb: env["LINKCALLBACKS"][%r]=%r' % (callback, cbfun))
- if isinstance(cbfun, collections.Callable):
+ if isinstance(cbfun, Callable):
if Verbose:
print('_call_linker_cb: env["LINKCALLBACKS"][%r] is callable' % callback)
result = cbfun(env, *args)
diff --git a/src/engine/SCons/Tool/clang.py b/src/engine/SCons/Tool/clang.py
index cbb48cb..081ab67 100644
--- a/src/engine/SCons/Tool/clang.py
+++ b/src/engine/SCons/Tool/clang.py
@@ -77,7 +77,8 @@ def generate(env):
stdout=subprocess.PIPE)
if pipe.wait() != 0: return
# clang -dumpversion is of no use
- line = pipe.stdout.readline()
+ with pipe.stdout:
+ line = pipe.stdout.readline()
if sys.version_info[0] > 2:
line = line.decode()
match = re.search(r'clang +version +([0-9]+(?:\.[0-9]+)+)', line)
diff --git a/src/engine/SCons/Tool/clangxx.py b/src/engine/SCons/Tool/clangxx.py
index 7194d9e..a29cf79 100644
--- a/src/engine/SCons/Tool/clangxx.py
+++ b/src/engine/SCons/Tool/clangxx.py
@@ -85,7 +85,8 @@ def generate(env):
return
# clang -dumpversion is of no use
- line = pipe.stdout.readline()
+ with pipe.stdout:
+ line = pipe.stdout.readline()
if sys.version_info[0] > 2:
line = line.decode()
match = re.search(r'clang +version +([0-9]+(?:\.[0-9]+)+)', line)
diff --git a/src/engine/SCons/Tool/docbook/__init__.py b/src/engine/SCons/Tool/docbook/__init__.py
index 5b98db2..ee8e4d6 100644
--- a/src/engine/SCons/Tool/docbook/__init__.py
+++ b/src/engine/SCons/Tool/docbook/__init__.py
@@ -84,7 +84,7 @@ def __extend_targets_sources(target, source):
source = [source]
if len(target) < len(source):
target.extend(source[len(target):])
-
+
return target, source
def __init_xsl_stylesheet(kw, env, user_xsl_var, default_path):
@@ -94,12 +94,12 @@ def __init_xsl_stylesheet(kw, env, user_xsl_var, default_path):
path_args = [scriptpath, db_xsl_folder] + default_path
xsl_style = os.path.join(*path_args)
kw['DOCBOOK_XSL'] = xsl_style
-
+
def __select_builder(lxml_builder, libxml2_builder, cmdline_builder):
""" Selects a builder, based on which Python modules are present. """
if prefer_xsltproc:
return cmdline_builder
-
+
if not has_libxml2:
# At the moment we prefer libxml2 over lxml, the latter can lead
# to conflicts when installed together with libxml2.
@@ -115,7 +115,7 @@ def __ensure_suffix(t, suffix):
tpath = str(t)
if not tpath.endswith(suffix):
return tpath+suffix
-
+
return t
def __ensure_suffix_stem(t, suffix):
@@ -124,11 +124,11 @@ def __ensure_suffix_stem(t, suffix):
if not tpath.endswith(suffix):
stem = tpath
tpath += suffix
-
+
return tpath, stem
else:
stem, ext = os.path.splitext(tpath)
-
+
return t, stem
def __get_xml_text(root):
@@ -151,7 +151,7 @@ def __create_output_dir(base_dir):
else:
if base_dir.endswith('/'):
dir = base_dir
-
+
if dir and not os.path.isdir(dir):
os.makedirs(dir)
@@ -203,10 +203,10 @@ def _detect(env):
the requested output formats.
"""
global prefer_xsltproc
-
+
if env.get('DOCBOOK_PREFER_XSLTPROC',''):
prefer_xsltproc = True
-
+
if ((not has_libxml2 and not has_lxml) or (prefer_xsltproc)):
# Try to find the XSLT processors
__detect_cl_tool(env, 'DOCBOOK_XSLTPROC', xsltproc_com, xsltproc_com_priority)
@@ -219,15 +219,15 @@ def _detect(env):
#
include_re = re.compile('fileref\\s*=\\s*["|\']([^\\n]*)["|\']')
sentity_re = re.compile('<!ENTITY\\s+%*\\s*[^\\s]+\\s+SYSTEM\\s+["|\']([^\\n]*)["|\']>')
-
+
def __xml_scan(node, env, path, arg):
""" Simple XML file scanner, detecting local images and XIncludes as implicit dependencies. """
# Does the node exist yet?
if not os.path.isfile(str(node)):
return []
-
+
if env.get('DOCBOOK_SCANENT',''):
- # Use simple pattern matching for system entities..., no support
+ # Use simple pattern matching for system entities..., no support
# for recursion yet.
contents = node.get_text_contents()
return sentity_re.findall(contents)
@@ -235,9 +235,9 @@ def __xml_scan(node, env, path, arg):
xsl_file = os.path.join(scriptpath,'utils','xmldepend.xsl')
if not has_libxml2 or prefer_xsltproc:
if has_lxml and not prefer_xsltproc:
-
+
from lxml import etree
-
+
xsl_tree = etree.parse(xsl_file)
doc = etree.parse(str(node))
result = doc.xslt(xsl_tree)
@@ -266,7 +266,7 @@ def __xml_scan(node, env, path, arg):
for x in str(result).splitlines():
if x.strip() != "" and not x.startswith("<?xml "):
depfiles.extend(x.strip().split())
-
+
style.freeStylesheet()
doc.freeDoc()
result.freeDoc()
@@ -282,7 +282,7 @@ docbook_xml_scanner = SCons.Script.Scanner(function = __xml_scan,
# Action generators
#
def __generate_xsltproc_action(source, target, env, for_signature):
- cmd = env['DOCBOOK_XSLTPROCCOM']
+ cmd = env['DOCBOOK_XSLTPROCCOM']
# Does the environment have a base_dir defined?
base_dir = env.subst('$base_dir')
if base_dir:
@@ -300,7 +300,7 @@ def __emit_xsl_basedir(target, source, env):
if base_dir:
# Yes, so prepend it to each target
return [os.path.join(base_dir, str(t)) for t in target], source
-
+
# No, so simply pass target and source names through
return target, source
@@ -334,11 +334,11 @@ def __build_lxml(target, source, env):
General XSLT builder (HTML/FO), using the lxml module.
"""
from lxml import etree
-
- xslt_ac = etree.XSLTAccessControl(read_file=True,
- write_file=True,
- create_dir=True,
- read_network=False,
+
+ xslt_ac = etree.XSLTAccessControl(read_file=True,
+ write_file=True,
+ create_dir=True,
+ read_network=False,
write_network=False)
xsl_style = env.subst('$DOCBOOK_XSL')
xsl_tree = etree.parse(xsl_style)
@@ -350,11 +350,10 @@ def __build_lxml(target, source, env):
result = transform(doc, **parampass)
else:
result = transform(doc)
-
+
try:
- of = open(str(target[0]), "wb")
- of.write(of.write(etree.tostring(result, pretty_print=True)))
- of.close()
+ with open(str(target[0]), "wb") as of:
+ of.write(of.write(etree.tostring(result, pretty_print=True)))
except:
pass
@@ -376,11 +375,11 @@ def __xinclude_lxml(target, source, env):
Resolving XIncludes, using the lxml module.
"""
from lxml import etree
-
+
doc = etree.parse(str(source[0]))
doc.xinclude()
try:
- doc.write(str(target[0]), xml_declaration=True,
+ doc.write(str(target[0]), xml_declaration=True,
encoding="UTF-8", pretty_print=True)
except:
pass
@@ -432,33 +431,31 @@ def DocbookEpub(env, target, source=None, *args, **kw):
"""
import zipfile
import shutil
-
+
def build_open_container(target, source, env):
"""Generate the *.epub file from intermediate outputs
- Constructs the epub file according to the Open Container Format. This
+ Constructs the epub file according to the Open Container Format. This
function could be replaced by a call to the SCons Zip builder if support
was added for different compression formats for separate source nodes.
"""
- zf = zipfile.ZipFile(str(target[0]), 'w')
- mime_file = open('mimetype', 'w')
- mime_file.write('application/epub+zip')
- mime_file.close()
- zf.write(mime_file.name, compress_type = zipfile.ZIP_STORED)
- for s in source:
- if os.path.isfile(str(s)):
- head, tail = os.path.split(str(s))
- if not head:
- continue
- s = head
- for dirpath, dirnames, filenames in os.walk(str(s)):
- for fname in filenames:
- path = os.path.join(dirpath, fname)
- if os.path.isfile(path):
- zf.write(path, os.path.relpath(path, str(env.get('ZIPROOT', ''))),
- zipfile.ZIP_DEFLATED)
- zf.close()
-
+ with zipfile.ZipFile(str(target[0]), 'w') as zf:
+ with open('mimetype', 'w') as mime_file:
+ mime_file.write('application/epub+zip')
+ zf.write(mime_file.name, compress_type = zipfile.ZIP_STORED)
+ for s in source:
+ if os.path.isfile(str(s)):
+ head, tail = os.path.split(str(s))
+ if not head:
+ continue
+ s = head
+ for dirpath, dirnames, filenames in os.walk(str(s)):
+ for fname in filenames:
+ path = os.path.join(dirpath, fname)
+ if os.path.isfile(path):
+ zf.write(path, os.path.relpath(path, str(env.get('ZIPROOT', ''))),
+ zipfile.ZIP_DEFLATED)
+
def add_resources(target, source, env):
"""Add missing resources to the OEBPS directory
@@ -468,7 +465,7 @@ def DocbookEpub(env, target, source=None, *args, **kw):
content_file = os.path.join(source[0].get_abspath(), 'content.opf')
if not os.path.isfile(content_file):
return
-
+
hrefs = []
if has_libxml2:
nsmap = {'opf' : 'http://www.idpf.org/2007/opf'}
@@ -495,51 +492,51 @@ def DocbookEpub(env, target, source=None, *args, **kw):
hrefs.append(item.attrib['href'])
doc.freeDoc()
- xpath_context.xpathFreeContext()
+ xpath_context.xpathFreeContext()
elif has_lxml:
from lxml import etree
-
+
opf = etree.parse(content_file)
# All the opf:item elements are resources
- for item in opf.xpath('//opf:item',
+ for item in opf.xpath('//opf:item',
namespaces= { 'opf': 'http://www.idpf.org/2007/opf' }):
hrefs.append(item.attrib['href'])
-
+
for href in hrefs:
- # If the resource was not already created by DocBook XSL itself,
+ # If the resource was not already created by DocBook XSL itself,
# copy it into the OEBPS folder
referenced_file = os.path.join(source[0].get_abspath(), href)
if not os.path.exists(referenced_file):
shutil.copy(href, os.path.join(source[0].get_abspath(), href))
-
+
# Init list of targets/sources
target, source = __extend_targets_sources(target, source)
-
+
# Init XSL stylesheet
__init_xsl_stylesheet(kw, env, '$DOCBOOK_DEFAULT_XSL_EPUB', ['epub','docbook.xsl'])
# Setup builder
__builder = __select_builder(__lxml_builder, __libxml2_builder, __xsltproc_builder)
-
+
# Create targets
result = []
- if not env.GetOption('clean'):
+ if not env.GetOption('clean'):
# Ensure that the folders OEBPS and META-INF exist
__create_output_dir('OEBPS/')
__create_output_dir('META-INF/')
dirs = env.Dir(['OEBPS', 'META-INF'])
-
+
# Set the fixed base_dir
kw['base_dir'] = 'OEBPS/'
tocncx = __builder.__call__(env, 'toc.ncx', source[0], **kw)
cxml = env.File('META-INF/container.xml')
env.SideEffect(cxml, tocncx)
-
+
env.Depends(tocncx, kw['DOCBOOK_XSL'])
result.extend(tocncx+[cxml])
- container = env.Command(__ensure_suffix(str(target[0]), '.epub'),
- tocncx+[cxml], [add_resources, build_open_container])
+ container = env.Command(__ensure_suffix(str(target[0]), '.epub'),
+ tocncx+[cxml], [add_resources, build_open_container])
mimetype = env.File('mimetype')
env.SideEffect(mimetype, container)
@@ -555,13 +552,13 @@ def DocbookHtml(env, target, source=None, *args, **kw):
"""
# Init list of targets/sources
target, source = __extend_targets_sources(target, source)
-
+
# Init XSL stylesheet
__init_xsl_stylesheet(kw, env, '$DOCBOOK_DEFAULT_XSL_HTML', ['html','docbook.xsl'])
# Setup builder
__builder = __select_builder(__lxml_builder, __libxml2_builder, __xsltproc_builder)
-
+
# Create targets
result = []
for t,s in zip(target,source):
@@ -583,18 +580,18 @@ def DocbookHtmlChunked(env, target, source=None, *args, **kw):
target = ['index.html']
elif not SCons.Util.is_List(source):
source = [source]
-
+
# Init XSL stylesheet
__init_xsl_stylesheet(kw, env, '$DOCBOOK_DEFAULT_XSL_HTMLCHUNKED', ['html','chunkfast.xsl'])
# Setup builder
__builder = __select_builder(__lxml_builder, __libxml2_builder, __xsltproc_builder)
-
+
# Detect base dir
base_dir = kw.get('base_dir', '')
if base_dir:
__create_output_dir(base_dir)
-
+
# Create targets
result = []
r = __builder.__call__(env, __ensure_suffix(str(target[0]), '.html'), source[0], **kw)
@@ -617,8 +614,8 @@ def DocbookHtmlhelp(env, target, source=None, *args, **kw):
source = target
target = ['index.html']
elif not SCons.Util.is_List(source):
- source = [source]
-
+ source = [source]
+
# Init XSL stylesheet
__init_xsl_stylesheet(kw, env, '$DOCBOOK_DEFAULT_XSL_HTMLHELP', ['htmlhelp','htmlhelp.xsl'])
@@ -629,7 +626,7 @@ def DocbookHtmlhelp(env, target, source=None, *args, **kw):
base_dir = kw.get('base_dir', '')
if base_dir:
__create_output_dir(base_dir)
-
+
# Create targets
result = []
r = __builder.__call__(env, __ensure_suffix(str(target[0]), '.html'), source[0], **kw)
@@ -687,30 +684,29 @@ def DocbookMan(env, target, source=None, *args, **kw):
if os.path.isfile(srcfile):
try:
import xml.dom.minidom
-
+
dom = xml.dom.minidom.parse(__ensure_suffix(str(s),'.xml'))
# Extract volume number, default is 1
for node in dom.getElementsByTagName('refmeta'):
for vol in node.getElementsByTagName('manvolnum'):
volnum = __get_xml_text(vol)
-
+
# Extract output filenames
for node in dom.getElementsByTagName('refnamediv'):
for ref in node.getElementsByTagName('refname'):
outfiles.append(__get_xml_text(ref)+'.'+volnum)
-
+
except:
- # Use simple regex parsing
- f = open(__ensure_suffix(str(s),'.xml'), 'r')
- content = f.read()
- f.close()
-
+ # Use simple regex parsing
+ with open(__ensure_suffix(str(s),'.xml'), 'r') as f:
+ content = f.read()
+
for m in re_manvolnum.finditer(content):
volnum = m.group(1)
-
+
for m in re_refname.finditer(content):
outfiles.append(m.group(1)+'.'+volnum)
-
+
if not outfiles:
# Use stem of the source file
spath = str(s)
@@ -722,14 +718,14 @@ def DocbookMan(env, target, source=None, *args, **kw):
else:
# We have to completely rely on the given target name
outfiles.append(t)
-
+
__builder.__call__(env, outfiles[0], s, **kw)
env.Depends(outfiles[0], kw['DOCBOOK_XSL'])
result.append(outfiles[0])
if len(outfiles) > 1:
env.Clean(outfiles[0], outfiles[1:])
-
+
return result
def DocbookSlidesPdf(env, target, source=None, *args, **kw):
@@ -750,7 +746,7 @@ def DocbookSlidesPdf(env, target, source=None, *args, **kw):
for t,s in zip(target,source):
t, stem = __ensure_suffix_stem(t, '.pdf')
xsl = __builder.__call__(env, stem+'.fo', s, **kw)
- env.Depends(xsl, kw['DOCBOOK_XSL'])
+ env.Depends(xsl, kw['DOCBOOK_XSL'])
result.extend(xsl)
result.extend(__fop_builder.__call__(env, t, xsl, **kw))
@@ -767,7 +763,7 @@ def DocbookSlidesHtml(env, target, source=None, *args, **kw):
source = target
target = ['index.html']
elif not SCons.Util.is_List(source):
- source = [source]
+ source = [source]
# Init XSL stylesheet
__init_xsl_stylesheet(kw, env, '$DOCBOOK_DEFAULT_XSL_SLIDESHTML', ['slides','html','plain.xsl'])
@@ -800,12 +796,12 @@ def DocbookXInclude(env, target, source, *args, **kw):
# Setup builder
__builder = __select_builder(__xinclude_lxml_builder,__xinclude_libxml2_builder,__xmllint_builder)
-
+
# Create targets
result = []
for t,s in zip(target,source):
result.extend(__builder.__call__(env, t, s, **kw))
-
+
return result
def DocbookXslt(env, target, source=None, *args, **kw):
@@ -814,13 +810,13 @@ def DocbookXslt(env, target, source=None, *args, **kw):
"""
# Init list of targets/sources
target, source = __extend_targets_sources(target, source)
-
+
# Init XSL stylesheet
kw['DOCBOOK_XSL'] = kw.get('xsl', 'transform.xsl')
# Setup builder
__builder = __select_builder(__lxml_builder, __libxml2_builder, __xsltproc_builder)
-
+
# Create targets
result = []
for t,s in zip(target,source):
@@ -844,18 +840,18 @@ def generate(env):
DOCBOOK_DEFAULT_XSL_MAN = '',
DOCBOOK_DEFAULT_XSL_SLIDESPDF = '',
DOCBOOK_DEFAULT_XSL_SLIDESHTML = '',
-
+
# Paths to the detected executables
DOCBOOK_XSLTPROC = '',
DOCBOOK_XMLLINT = '',
DOCBOOK_FOP = '',
-
+
# Additional flags for the text processors
DOCBOOK_XSLTPROCFLAGS = SCons.Util.CLVar(''),
DOCBOOK_XMLLINTFLAGS = SCons.Util.CLVar(''),
DOCBOOK_FOPFLAGS = SCons.Util.CLVar(''),
DOCBOOK_XSLTPROCPARAMS = SCons.Util.CLVar(''),
-
+
# Default command lines for the detected executables
DOCBOOK_XSLTPROCCOM = xsltproc_com['xsltproc'],
DOCBOOK_XMLLINTCOM = xmllint_com['xmllint'],
@@ -865,7 +861,7 @@ def generate(env):
DOCBOOK_XSLTPROCCOMSTR = None,
DOCBOOK_XMLLINTCOMSTR = None,
DOCBOOK_FOPCOMSTR = None,
-
+
)
_detect(env)
diff --git a/src/engine/SCons/Tool/hpcxx.py b/src/engine/SCons/Tool/hpcxx.py
index 1ba9198..7113fa2 100644
--- a/src/engine/SCons/Tool/hpcxx.py
+++ b/src/engine/SCons/Tool/hpcxx.py
@@ -68,7 +68,8 @@ def generate(env):
env['CXX'] = acc or 'aCC'
env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS +Z')
# determine version of aCC
- line = os.popen(acc + ' -V 2>&1').readline().rstrip()
+ with os.popen(acc + ' -V 2>&1') as p:
+ line = p.readline().rstrip()
if line.find('aCC: HP ANSI C++') == 0:
env['CXXVERSION'] = line.split()[-1]
diff --git a/src/engine/SCons/Tool/ipkg.py b/src/engine/SCons/Tool/ipkg.py
index df77eea..8e01dd2 100644
--- a/src/engine/SCons/Tool/ipkg.py
+++ b/src/engine/SCons/Tool/ipkg.py
@@ -55,8 +55,10 @@ def generate(env):
env['IPKGCOM'] = '$IPKG $IPKGFLAGS ${SOURCE}'
if env.WhereIs('id'):
- env['IPKGUSER'] = os.popen('id -un').read().strip()
- env['IPKGGROUP'] = os.popen('id -gn').read().strip()
+ with os.popen('id -un') as p:
+ env['IPKGUSER'] = p.read().strip()
+ with os.popen('id -gn') as p:
+ env['IPKGGROUP'] = p.read().strip()
env['IPKGFLAGS'] = SCons.Util.CLVar('-o $IPKGUSER -g $IPKGGROUP')
env['IPKGSUFFIX'] = '.ipk'
diff --git a/src/engine/SCons/Tool/mingw.py b/src/engine/SCons/Tool/mingw.py
index ebc3fbf..e5f472a 100644
--- a/src/engine/SCons/Tool/mingw.py
+++ b/src/engine/SCons/Tool/mingw.py
@@ -123,7 +123,7 @@ key_program = 'mingw32-make'
def find_version_specific_mingw_paths():
- """
+ r"""
One example of default mingw install paths is:
C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev2\mingw64\bin
diff --git a/src/engine/SCons/Tool/msvs.py b/src/engine/SCons/Tool/msvs.py
index c80dac3..62a01fa 100644
--- a/src/engine/SCons/Tool/msvs.py
+++ b/src/engine/SCons/Tool/msvs.py
@@ -645,10 +645,10 @@ class _GenerateV6DSP(_DSPGenerator):
if self.nokeep == 0:
# now we pickle some data and add it to the file -- MSDEV will ignore it.
pdata = pickle.dumps(self.configs,PICKLE_PROTOCOL)
- pdata = base64.encodestring(pdata).decode()
+ pdata = base64.b64encode(pdata).decode()
self.file.write(pdata + '\n')
pdata = pickle.dumps(self.sources,PICKLE_PROTOCOL)
- pdata = base64.encodestring(pdata).decode()
+ pdata = base64.b64encode(pdata).decode()
self.file.write(pdata + '\n')
def PrintSourceFiles(self):
@@ -695,6 +695,7 @@ class _GenerateV6DSP(_DSPGenerator):
while line and line != '\n':
line = dspfile.readline()
datas = datas + line
+ dspfile.close()
# OK, we've found our little pickled cache of data.
try:
@@ -713,6 +714,7 @@ class _GenerateV6DSP(_DSPGenerator):
while line and line != '\n':
line = dspfile.readline()
datas = datas + line
+ dspfile.close()
# OK, we've found our little pickled cache of data.
# it has a "# " in front of it, so we strip that.
@@ -917,10 +919,10 @@ class _GenerateV7DSP(_DSPGenerator, _GenerateV7User):
if self.nokeep == 0:
# now we pickle some data and add it to the file -- MSDEV will ignore it.
pdata = pickle.dumps(self.configs,PICKLE_PROTOCOL)
- pdata = base64.encodestring(pdata).decode()
+ pdata = base64.b64encode(pdata).decode()
self.file.write('<!-- SCons Data:\n' + pdata + '\n')
pdata = pickle.dumps(self.sources,PICKLE_PROTOCOL)
- pdata = base64.encodestring(pdata).decode()
+ pdata = base64.b64encode(pdata).decode()
self.file.write(pdata + '-->\n')
def printSources(self, hierarchy, commonprefix):
@@ -1008,6 +1010,7 @@ class _GenerateV7DSP(_DSPGenerator, _GenerateV7User):
while line and line != '\n':
line = dspfile.readline()
datas = datas + line
+ dspfile.close()
# OK, we've found our little pickled cache of data.
try:
@@ -1241,10 +1244,10 @@ class _GenerateV10DSP(_DSPGenerator, _GenerateV10User):
if self.nokeep == 0:
# now we pickle some data and add it to the file -- MSDEV will ignore it.
pdata = pickle.dumps(self.configs,PICKLE_PROTOCOL)
- pdata = base64.encodestring(pdata).decode()
+ pdata = base64.b64encode(pdata).decode()
self.file.write('<!-- SCons Data:\n' + pdata + '\n')
pdata = pickle.dumps(self.sources,PICKLE_PROTOCOL)
- pdata = base64.encodestring(pdata).decode()
+ pdata = base64.b64encode(pdata).decode()
self.file.write(pdata + '-->\n')
def printFilters(self, hierarchy, name):
@@ -1491,6 +1494,7 @@ class _GenerateV7DSW(_DSWGenerator):
while line:
line = dswfile.readline()
datas = datas + line
+ dswfile.close()
# OK, we've found our little pickled cache of data.
try:
@@ -1617,7 +1621,7 @@ class _GenerateV7DSW(_DSWGenerator):
self.file.write('EndGlobal\n')
if self.nokeep == 0:
pdata = pickle.dumps(self.configs,PICKLE_PROTOCOL)
- pdata = base64.encodestring(pdata).decode()
+ pdata = base64.b64encode(pdata).decode()
self.file.write(pdata)
self.file.write('\n')
@@ -1738,6 +1742,7 @@ def GenerateProject(target, source, env):
raise
bdsp.write("This is just a placeholder file.\nThe real project file is here:\n%s\n" % dspfile.get_abspath())
+ bdsp.close()
GenerateDSP(dspfile, source, env)
@@ -1754,6 +1759,7 @@ def GenerateProject(target, source, env):
raise
bdsw.write("This is just a placeholder file.\nThe real workspace file is here:\n%s\n" % dswfile.get_abspath())
+ bdsw.close()
GenerateDSW(dswfile, source, env)
diff --git a/src/engine/SCons/Tool/packaging/msi.py b/src/engine/SCons/Tool/packaging/msi.py
index 052d7d8..0ef18ec 100644
--- a/src/engine/SCons/Tool/packaging/msi.py
+++ b/src/engine/SCons/Tool/packaging/msi.py
@@ -188,7 +188,7 @@ def build_wxsfile(target, source, env):
""" Compiles a .wxs file from the keywords given in env['msi_spec'] and
by analyzing the tree of source nodes and their tags.
"""
- file = open(target[0].get_abspath(), 'w')
+ f = open(target[0].get_abspath(), 'w')
try:
# Create a document with the Wix root tag
@@ -209,7 +209,7 @@ def build_wxsfile(target, source, env):
build_license_file(target[0].get_dir(), env)
# write the xml to a file
- file.write( doc.toprettyxml() )
+ f.write( doc.toprettyxml() )
# call a user specified function
if 'CHANGE_SPECFILE' in env:
@@ -217,6 +217,8 @@ def build_wxsfile(target, source, env):
except KeyError as e:
raise SCons.Errors.UserError( '"%s" package field for MSI is missing.' % e.args[0] )
+ finally:
+ f.close()
#
# setup function
@@ -440,14 +442,13 @@ def build_license_file(directory, spec):
pass # ignore this as X_MSI_LICENSE_TEXT is optional
if name!='' or text!='':
- file = open( os.path.join(directory.get_path(), 'License.rtf'), 'w' )
- file.write('{\\rtf')
- if text!='':
- file.write(text.replace('\n', '\\par '))
- else:
- file.write(name+'\\par\\par')
- file.write('}')
- file.close()
+ with open(os.path.join(directory.get_path(), 'License.rtf'), 'w') as f:
+ f.write('{\\rtf')
+ if text!='':
+ f.write(text.replace('\n', '\\par '))
+ else:
+ f.write(name+'\\par\\par')
+ f.write('}')
#
# mandatory and optional package tags
diff --git a/src/engine/SCons/Tool/packaging/rpm.py b/src/engine/SCons/Tool/packaging/rpm.py
index 0a4db6c..ebaa701 100644
--- a/src/engine/SCons/Tool/packaging/rpm.py
+++ b/src/engine/SCons/Tool/packaging/rpm.py
@@ -125,11 +125,11 @@ def build_specfile(target, source, env):
""" Builds a RPM specfile from a dictionary with string metadata and
by analyzing a tree of nodes.
"""
- with open(target[0].get_abspath(), 'w') as file:
+ with open(target[0].get_abspath(), 'w') as ofp:
try:
- file.write(build_specfile_header(env))
- file.write(build_specfile_sections(env))
- file.write(build_specfile_filesection(env, source))
+ ofp.write(build_specfile_header(env))
+ ofp.write(build_specfile_sections(env))
+ ofp.write(build_specfile_filesection(env, source))
# call a user specified function
if 'CHANGE_SPECFILE' in env:
diff --git a/src/engine/SCons/Tool/qt.py b/src/engine/SCons/Tool/qt.py
index aeb04ee..0c471f9 100644
--- a/src/engine/SCons/Tool/qt.py
+++ b/src/engine/SCons/Tool/qt.py
@@ -66,11 +66,17 @@ if SCons.Util.case_sensitive_suffixes('.h', '.H'):
cxx_suffixes = cplusplus.CXXSuffixes
-#
def find_platform_specific_qt_paths():
"""
- If the platform has non-standard paths which it installs QT in,return the likely default path
- :return:
+ find non-standard QT paths
+
+ If the platform does not put QT tools in standard search paths,
+ the path is expected to be set using QTDIR. SCons violates
+ the normal rule of not pulling from the user's environment
+ in this case. However, some test cases try to validate what
+ happens when QTDIR is unset, so we need to try to make a guess.
+
+ :return: a guess at a path
"""
# qt_bin_dirs = []
@@ -83,6 +89,7 @@ def find_platform_specific_qt_paths():
# Centos installs QT under /usr/{lib,lib64}/qt{4,5,-3.3}/bin
# so we need to handle this differently
# qt_bin_dirs = glob.glob('/usr/lib64/qt*/bin')
+ # TODO: all current Fedoras do the same, need to look deeper here.
qt_bin_dir = '/usr/lib64/qt-3.3/bin'
return qt_bin_dir
diff --git a/src/engine/SCons/Tool/rpm.py b/src/engine/SCons/Tool/rpm.py
index 5198f84..2fd802a 100644
--- a/src/engine/SCons/Tool/rpm.py
+++ b/src/engine/SCons/Tool/rpm.py
@@ -51,43 +51,44 @@ def get_cmd(source, env):
if SCons.Util.is_List(source):
tar_file_with_included_specfile = source[0]
return "%s %s %s"%(env['RPM'], env['RPMFLAGS'],
- tar_file_with_included_specfile.get_abspath() )
+ tar_file_with_included_specfile.get_abspath())
def build_rpm(target, source, env):
# create a temporary rpm build root.
- tmpdir = os.path.join( os.path.dirname( target[0].get_abspath() ), 'rpmtemp' )
+ tmpdir = os.path.join(os.path.dirname(target[0].get_abspath()), 'rpmtemp')
if os.path.exists(tmpdir):
shutil.rmtree(tmpdir)
# now create the mandatory rpm directory structure.
for d in ['RPMS', 'SRPMS', 'SPECS', 'BUILD']:
- os.makedirs( os.path.join( tmpdir, d ) )
+ os.makedirs(os.path.join(tmpdir, d))
# set the topdir as an rpmflag.
- env.Prepend( RPMFLAGS = '--define \'_topdir %s\'' % tmpdir )
+ env.Prepend(RPMFLAGS = '--define \'_topdir %s\'' % tmpdir)
# now call rpmbuild to create the rpm package.
handle = subprocess.Popen(get_cmd(source, env),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True)
- output = SCons.Util.to_str(handle.stdout.read())
+ with handle.stdout:
+ output = SCons.Util.to_str(handle.stdout.read())
status = handle.wait()
if status:
- raise SCons.Errors.BuildError( node=target[0],
- errstr=output,
- filename=str(target[0]) )
+ raise SCons.Errors.BuildError(node=target[0],
+ errstr=output,
+ filename=str(target[0]))
else:
# XXX: assume that LC_ALL=C is set while running rpmbuild
- output_files = re.compile( 'Wrote: (.*)' ).findall( output )
+ output_files = re.compile('Wrote: (.*)').findall(output)
- for output, input in zip( output_files, target ):
+ for output, input in zip(output_files, target):
rpm_output = os.path.basename(output)
expected = os.path.basename(input.get_path())
assert expected == rpm_output, "got %s but expected %s" % (rpm_output, expected)
- shutil.copy( output, input.get_abspath() )
+ shutil.copy(output, input.get_abspath())
# cleanup before leaving.
diff --git a/src/engine/SCons/Tool/rpmutils.py b/src/engine/SCons/Tool/rpmutils.py
index e2d6997..566f8e1 100644
--- a/src/engine/SCons/Tool/rpmutils.py
+++ b/src/engine/SCons/Tool/rpmutils.py
@@ -482,9 +482,11 @@ def updateRpmDicts(rpmrc, pyfile):
"""
try:
# Read old rpmutils.py file
- oldpy = open(pyfile,"r").readlines()
+ with open(pyfile,"r") as f:
+ oldpy = f.readlines()
# Read current rpmrc.in file
- rpm = open(rpmrc,"r").readlines()
+ with open(rpmrc,"r") as f:
+ rpm = f.readlines()
# Parse for data
data = {}
# Allowed section names that get parsed
@@ -511,24 +513,23 @@ def updateRpmDicts(rpmrc, pyfile):
# Insert data
data[key][tokens[1]] = tokens[2:]
# Write new rpmutils.py file
- out = open(pyfile,"w")
- pm = 0
- for l in oldpy:
- if pm:
- if l.startswith('# End of rpmrc dictionaries'):
- pm = 0
+ with open(pyfile,"w") as out:
+ pm = 0
+ for l in oldpy:
+ if pm:
+ if l.startswith('# End of rpmrc dictionaries'):
+ pm = 0
+ out.write(l)
+ else:
out.write(l)
- else:
- out.write(l)
- if l.startswith('# Start of rpmrc dictionaries'):
- pm = 1
- # Write data sections to single dictionaries
- for key, entries in data.items():
- out.write("%s = {\n" % key)
- for arch in sorted(entries.keys()):
- out.write(" '%s' : ['%s'],\n" % (arch, "','".join(entries[arch])))
- out.write("}\n\n")
- out.close()
+ if l.startswith('# Start of rpmrc dictionaries'):
+ pm = 1
+ # Write data sections to single dictionaries
+ for key, entries in data.items():
+ out.write("%s = {\n" % key)
+ for arch in sorted(entries.keys()):
+ out.write(" '%s' : ['%s'],\n" % (arch, "','".join(entries[arch])))
+ out.write("}\n\n")
except:
pass
diff --git a/src/engine/SCons/Tool/suncxx.py b/src/engine/SCons/Tool/suncxx.py
index d526d86..9ac8d32 100644
--- a/src/engine/SCons/Tool/suncxx.py
+++ b/src/engine/SCons/Tool/suncxx.py
@@ -52,7 +52,13 @@ def get_package_info(package_name, pkginfo, pkgchk):
version = None
pathname = None
try:
- sadm_contents = open('/var/sadm/install/contents', 'r').read()
+ from subprocess import DEVNULL # py3k
+ except ImportError:
+ DEVNULL = open(os.devnull, 'wb')
+
+ try:
+ with open('/var/sadm/install/contents', 'r') as f:
+ sadm_contents = f.read()
except EnvironmentError:
pass
else:
@@ -64,7 +70,7 @@ def get_package_info(package_name, pkginfo, pkgchk):
try:
p = subprocess.Popen([pkginfo, '-l', package_name],
stdout=subprocess.PIPE,
- stderr=open('/dev/null', 'w'))
+ stderr=DEVNULL)
except EnvironmentError:
pass
else:
@@ -78,7 +84,7 @@ def get_package_info(package_name, pkginfo, pkgchk):
try:
p = subprocess.Popen([pkgchk, '-l', package_name],
stdout=subprocess.PIPE,
- stderr=open('/dev/null', 'w'))
+ stderr=DEVNULL)
except EnvironmentError:
pass
else:
diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py
index 69427ed..8519a98 100644
--- a/src/engine/SCons/Util.py
+++ b/src/engine/SCons/Util.py
@@ -679,7 +679,7 @@ if can_read_reg:
HKEY_USERS = hkey_mod.HKEY_USERS
def RegGetValue(root, key):
- """This utility function returns a value in the registry
+ r"""This utility function returns a value in the registry
without having to open the key first. Only available on
Windows platforms with a version of Python that can read the
registry. Returns the same thing as
@@ -1002,7 +1002,9 @@ if sys.platform == 'cygwin':
def get_native_path(path):
"""Transforms an absolute path into a native path for the system. In
Cygwin, this converts from a Cygwin path to a Windows one."""
- return os.popen('cygpath -w ' + path).read().replace('\n', '')
+ with os.popen('cygpath -w ' + path) as p:
+ npath = p.read().replace('\n', '')
+ return npath
else:
def get_native_path(path):
"""Transforms an absolute path into a native path for the system.
@@ -1478,13 +1480,12 @@ if hasattr(hashlib, 'md5'):
:return: String of Hex digits representing the signature
"""
m = hashlib.md5()
- f = open(fname, "rb")
- while True:
- blck = f.read(chunksize)
- if not blck:
- break
- m.update(to_bytes(blck))
- f.close()
+ with open(fname, "rb") as f:
+ while True:
+ blck = f.read(chunksize)
+ if not blck:
+ break
+ m.update(to_bytes(blck))
return m.hexdigest()
else:
# if md5 algorithm not available, just return data unmodified
@@ -1513,7 +1514,6 @@ def MD5collect(signatures):
return MD5signature(', '.join(signatures))
-
def silent_intern(x):
"""
Perform sys.intern() on the passed argument and return the result.
diff --git a/src/test_interrupts.py b/src/test_interrupts.py
index 0fd8ba7..de18a54 100644
--- a/src/test_interrupts.py
+++ b/src/test_interrupts.py
@@ -87,7 +87,8 @@ exceptall_pat = re.compile(r' *except(?: *| +Exception *, *[^: ]+):[^\n]*')
uncaughtKeyboardInterrupt = 0
for f in files:
- contents = open(os.path.join(scons_lib_dir, f)).read()
+ with open(os.path.join(scons_lib_dir, f)) as ifp:
+ contents = ifp.read()
try_except_lines = {}
lastend = 0
while True:
diff --git a/src/test_pychecker.py b/src/test_pychecker.py
index 54d78fb..56233c2 100644
--- a/src/test_pychecker.py
+++ b/src/test_pychecker.py
@@ -63,7 +63,8 @@ else:
src_engine_ = os.path.join(src_engine, '')
MANIFEST = os.path.join(src_engine, 'MANIFEST.in')
-files = open(MANIFEST).read().split()
+with open(MANIFEST) as f:
+ files = f.read().split()
files = [f for f in files if f[-3:] == '.py']
diff --git a/src/test_setup.py b/src/test_setup.py
index edf0de5..09865f5 100644
--- a/src/test_setup.py
+++ b/src/test_setup.py
@@ -176,21 +176,26 @@ tar_gz = os.path.join(cwd, 'build', 'dist', '%s.tar.gz' % scons_version)
zip = os.path.join(cwd, 'build', 'dist', '%s.zip' % scons_version)
if os.path.isfile(zip):
- try: import zipfile
- except ImportError: pass
+ try:
+ import zipfile
+ except ImportError:
+ pass
else:
- zf = zipfile.ZipFile(zip, 'r')
-
- for name in zf.namelist():
- dir = os.path.dirname(name)
- try: os.makedirs(dir)
- except: pass
- # if the file exists, then delete it before writing
- # to it so that we don't end up trying to write to a symlink:
- if os.path.isfile(name) or os.path.islink(name):
- os.unlink(name)
- if not os.path.isdir(name):
- open(name, 'w').write(zf.read(name))
+ with zipfile.ZipFile(zip, 'r') as zf:
+
+ for name in zf.namelist():
+ dname = os.path.dirname(name)
+ try:
+ os.makedirs(dname)
+ except FileExistsError:
+ pass
+ # if the file exists, then delete it before writing
+ # to it so that we don't end up trying to write to a symlink:
+ if os.path.isfile(name) or os.path.islink(name):
+ os.unlink(name)
+ if not os.path.isdir(name):
+ with open(name, 'w') as ofp:
+ ofp.write(zf.read(name))
if not os.path.isdir(scons_version) and os.path.isfile(tar_gz):
# Unpack the .tar.gz file. This should create the scons_version/
diff --git a/src/test_strings.py b/src/test_strings.py
index e9f0abf..a8a5000 100644
--- a/src/test_strings.py
+++ b/src/test_strings.py
@@ -98,7 +98,8 @@ class Checker(object):
for fname in filenames:
fpath = os.path.join(dirpath, fname)
if self.search_this(fpath) and not self.remove_this(fname, fpath):
- body = open(fpath, 'r').read()
+ with open(fpath, 'r') as f:
+ body = f.read()
for expr in self.expressions:
if not expr.search(body):
msg = '%s: missing %s' % (fpath, repr(expr.pattern))
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..3d05c79 100644
--- a/test/AS/fixture/myas.py
+++ b/test/AS/fixture/myas.py
@@ -15,21 +15,24 @@ 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:
import getopt
- opts, args = getopt.getopt(sys.argv[1:], 'co:')
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], 'co:')
+ except getopt.GetoptError:
+ # we may be called with --version, just quit if so
+ sys.exit(0)
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)
+ if args:
+ 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..22d9081 100644
--- a/test/Fortran/link-with-cxx.py
+++ b/test/Fortran/link-with-cxx.py
@@ -39,28 +39,28 @@ _python_ = TestSCons._python_
test = TestSCons.TestSCons(match = TestSCons.match_re)
-test.write('test_linker.py', r"""
+test.write('test_linker.py', """\
import sys
if sys.argv[1] == '-o':
- outfile = open(sys.argv[2], 'wb')
- infiles = sys.argv[3:]
+ with open(sys.argv[2], 'wb') as ofp:
+ for infile in sys.argv[3:]:
+ with open(infile, 'rb') as ifp:
+ ofp.write(ifp.read())
elif sys.argv[1][:5] == '/OUT:':
- outfile = 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(sys.argv[1][5:], 'wb') as ofp:
+ for infile in sys.argv[2:]:
+ with open(infile, 'rb') as ifp:
+ ofp.write(ifp.read())
sys.exit(0)
""")
-test.write('test_fortran.py', r"""
+test.write('test_fortran.py', """\
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/Parallel/failed-build.py b/test/Parallel/failed-build.py
index bfdc01d..12a8f04 100644
--- a/test/Parallel/failed-build.py
+++ b/test/Parallel/failed-build.py
@@ -77,7 +77,14 @@ test.write('mycopy.py', r"""\
import os
import sys
import time
-os.mkdir('mycopy.started')
+try:
+ os.makedirs('mycopy.started', exist_ok=True)
+except TypeError: # Python 2 has no exist_ok
+ try:
+ os.mkdir('mycopy.started')
+ except FileExistsError:
+ pass
+
with open(sys.argv[1], 'wb') as ofp, open(sys.argv[2], 'rb') as ifp:
ofp.write(ifp.read())
for i in [1, 2, 3, 4, 5]:
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..020333e 100644
--- a/test/QT/qt_warnings.py
+++ b/test/QT/qt_warnings.py
@@ -84,7 +84,7 @@ if moc:
qtdir = os.path.dirname(os.path.dirname(moc))
qtdir = qtdir.replace('\\', '\\\\' )
- expect = """
+ 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))
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 0d4f0ef..1e42d33 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 555c2c8..27bf840 100644
--- a/test/fixture/mycompile.py
+++ b/test/fixture/mycompile.py
@@ -1,8 +1,19 @@
+r"""
+Phony "compiler" for testing SCons.
+
+Copies its source files to the target file, dropping lines
+that match a pattern, so we can recognize the tool
+has made a modification.
+"""
+
import sys
-line = ('/*' + sys.argv[1] + '*/\n').encode()
-outfile = open(sys.argv[2], 'wb')
-for f in sys.argv[3:]:
- infile = open(f, 'rb')
- for l in [l for l in infile.readlines() if l != line]:
- outfile.write(l)
-sys.exit(0)
+
+if __name__ == '__main__':
+ line = ('/*' + sys.argv[1] + '*/\n').encode()
+ with open(sys.argv[2], 'wb') as ofp:
+ for f in sys.argv[3:]:
+ with open(f, 'rb') as ifp:
+ lines = [ln for ln in ifp.readlines() if ln != line]
+ for ln in lines:
+ ofp.write(ln)
+ sys.exit(0)
diff --git a/test/fixture/mylink.py b/test/fixture/mylink.py
index 7c03f00..b567118 100644
--- a/test/fixture/mylink.py
+++ b/test/fixture/mylink.py
@@ -1,31 +1,39 @@
+r"""
+Phony "linker" for testing SCons.
+
+Recognizes the option to specify an output file, ignoring
+all others; copies input lines to the output file except
+ones that contain a pattern, so we can recognize the tool
+has made a modification.
+"""
+
import sys
-if sys.platform == 'win32':
- args = sys.argv[1:]
- while args:
- a = args[0]
- if a == '-o':
- out = args[1]
- args = args[2:]
- continue
- if not a[0] in '/-':
- break
- args = args[1:]
- if a[:5].lower() == '/out:': out = a[5:]
- infile = open(args[0], 'rb')
- outfile = open(out, 'wb')
- for l in infile.readlines():
- if l[:5] != b'#link':
- outfile.write(l)
- sys.exit(0)
-else:
- import getopt
- opts, args = getopt.getopt(sys.argv[1:], 'o:')
- 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[:5] != b'#link':
- outfile.write(l)
- sys.exit(0)
+if __name__ == '__main__':
+ if sys.platform == 'win32':
+ args = sys.argv[1:]
+ while args:
+ a = args[0]
+ if a == '-o':
+ out = args[1]
+ args = args[2:]
+ continue
+ if not a[0] in '/-':
+ break
+ args = args[1:]
+ if a[:5].lower() == '/out:': out = a[5:]
+ with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp:
+ for l in ifp.readlines():
+ if not l.startswith(b'#link'):
+ ofp.write(l)
+ sys.exit(0)
+ else:
+ import getopt
+ opts, args = getopt.getopt(sys.argv[1:], 'o:')
+ for opt, arg in opts:
+ if opt == '-o': out = arg
+ with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp:
+ for l in ifp.readlines():
+ 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 40bf830..ad46091 100644
--- a/test/fixture/myrewrite.py
+++ b/test/fixture/myrewrite.py
@@ -1,7 +1,17 @@
+r"""
+Phony tool to modify a file in place for testing SCons.
+
+Drops lines that match a pattern. Currently used to test
+ranlib-related behavior without invoking ranlib.
+"""
+
import sys
-line = ('/*' + sys.argv[1] + '*/\n').encode()
-lines = open(sys.argv[2], 'rb').readlines()
-outfile = open(sys.argv[2], 'wb')
-for l in [l for l in lines if l != line]:
- outfile.write(l)
-sys.exit(0)
+
+if __name__ == '__main__':
+ line = ('/*' + sys.argv[1] + '*/\n').encode()
+ with open(sys.argv[2], 'rb') as ifp:
+ lines = [ln for ln in ifp.readlines() if ln != line]
+ with open(sys.argv[2], 'wb') as ofp:
+ for ln in lines:
+ ofp.write(ln)
+ sys.exit(0)
diff --git a/test/fixture/wrapper.py b/test/fixture/wrapper.py
index f02ea03..a023689 100644
--- a/test/fixture/wrapper.py
+++ b/test/fixture/wrapper.py
@@ -1,6 +1,10 @@
import os
import sys
-if '--version' not in sys.argv and '-dumpversion' not in sys.argv:
+import subprocess
+
+if __name__ == '__main__':
path = os.path.join(os.path.dirname(os.path.relpath(__file__)), 'wrapper.out')
- open(path, 'wb').write(b"wrapper.py\n")
-os.system(" ".join(sys.argv[1:]))
+ if '--version' not in sys.argv and '-dumpversion' not in sys.argv:
+ with open(path, 'wb') as f:
+ f.write(b"wrapper.py\n")
+ subprocess.call(sys.argv[1:])
diff --git a/test/fixture/wrapper_with_args.py b/test/fixture/wrapper_with_args.py
index fccab72..f9e4d22 100644
--- a/test/fixture/wrapper_with_args.py
+++ b/test/fixture/wrapper_with_args.py
@@ -1,7 +1,9 @@
import os
import sys
+import subprocess
-path = os.path.join(os.path.dirname(os.path.relpath(__file__)), 'wrapper.out')
-
-open(path, 'a').write("wrapper_with_args.py %s\n" % " ".join(sys.argv[1:]))
-os.system(" ".join(sys.argv[1:]))
+if __name__ == '__main__':
+ path = os.path.join(os.path.dirname(os.path.relpath(__file__)), 'wrapper.out')
+ with open(path, 'a') as f:
+ f.write("wrapper_with_args.py %s\n" % " ".join(sys.argv[1:]))
+ subprocess.call(sys.argv[1:])
diff --git a/test/gnutools.py b/test/gnutools.py
index 65d699b..040de2a 100644
--- a/test/gnutools.py
+++ b/test/gnutools.py
@@ -45,34 +45,42 @@ test.subdir('gnutools')
test.write(['gnutools','mygcc.py'], """
import getopt
import sys
-cmd_opts, args = getopt.getopt(sys.argv[1:], 'f:s:co:', [])
-output = None
+try:
+ cmd_opts, args = getopt.getopt(sys.argv[1:], 'f:s:co:', [])
+except getopt.GetoptError:
+ # we may be called with --version, just quit if so
+ sys.exit(0)
+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)
""")
test.write(['gnutools','myg++.py'], """
import getopt
import sys
-cmd_opts, args = getopt.getopt(sys.argv[1:], 'f:s:co:', [])
-output = None
+try:
+ cmd_opts, args = getopt.getopt(sys.argv[1:], 'f:s:co:', [])
+except getopt.GetoptError:
+ # we may be called with --version, just quit if so
+ sys.exit(0)
+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/leaky-handles.py b/test/leaky-handles.py
index 3787ee2..e64053c 100644
--- a/test/leaky-handles.py
+++ b/test/leaky-handles.py
@@ -41,11 +41,10 @@ if os.name != 'posix' or sys.platform == 'darwin':
test.write('SConstruct', """
-#Leak a file handle
-open('/dev/null')
-
-#Check it gets closed
-test2 = Command('test2', [], '@ls /proc/$$$$/fd|wc -l')
+# Leave a file handle open when invoking a command
+with open('/dev/null'):
+ # Check it gets closed when an external command is forked off:
+ test2 = Command('test2', [], '@ls /proc/$$$$/fd|wc -l')
""")
# In theory that should have 3 lines (handles 0/1/2). This is v. unix specific
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/explicit-target.py b/test/packaging/rpm/explicit-target.py
index e8fbd39..553ce27 100644
--- a/test/packaging/rpm/explicit-target.py
+++ b/test/packaging/rpm/explicit-target.py
@@ -48,7 +48,7 @@ test.subdir('src')
mainpath = os.path.join('src', 'main.c')
test.file_fixture(mainpath, mainpath)
-test.write('SConstruct', """
+test.write('SConstruct', """\
import os
env=Environment(tools=['default', 'packaging'])
@@ -77,7 +77,7 @@ env.Package( NAME = 'foo',
expect = """
scons: *** Setting target is not supported for rpm.
-""" + test.python_file_line(test.workpath('SConstruct'), 24)
+""" + test.python_file_line(test.workpath('SConstruct'), 12)
test.run(arguments='', status=2, stderr=expect)
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..23ebe05 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' % 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/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', """
diff --git a/testing/framework/SConscript b/testing/framework/SConscript
index 0d3832e..bb81d8e 100644
--- a/testing/framework/SConscript
+++ b/testing/framework/SConscript
@@ -41,12 +41,13 @@ files = [
def copy(target, source, env):
t = str(target[0])
s = str(source[0])
- c = open(s, 'r').read()
- # Note: We construct the __ VERSION __ substitution string at
- # run-time so it doesn't get replaced when this file gets copied
- # into the tree for packaging.
- c = c.replace('__' + 'VERSION' + '__', env['VERSION'])
- open(t, 'w').write(c)
+ with open(s, 'r') as i, open(t, 'w') as o:
+ c = i.read()
+ # Note: We construct the __ VERSION __ substitution string at
+ # run-time so it doesn't get replaced when this file gets copied
+ # into the tree for packaging.
+ c = c.replace('__' + 'VERSION' + '__', env['VERSION'])
+ o.write(c)
for file in files:
# Guarantee that real copies of these files always exist in
diff --git a/testing/framework/TestSCons.py b/testing/framework/TestSCons.py
index 23e8753..907eac7 100644
--- a/testing/framework/TestSCons.py
+++ b/testing/framework/TestSCons.py
@@ -949,7 +949,7 @@ class TestSCons(TestCommon):
def Qt_dummy_installation(self, dir='qt'):
# create a dummy qt installation
- self.subdir( dir, [dir, 'bin'], [dir, 'include'], [dir, 'lib'] )
+ self.subdir(dir, [dir, 'bin'], [dir, 'include'], [dir, 'lib'])
self.write([dir, 'bin', 'mymoc.py'], """\
import getopt
@@ -957,23 +957,23 @@ import sys
import re
# -w and -z are fake options used in test/QT/QTFLAGS.py
cmd_opts, args = getopt.getopt(sys.argv[1:], 'io:wz', [])
-output = None
impl = 0
opt_string = ''
for opt, arg in cmd_opts:
- if opt == '-o': output = open(arg, 'w')
+ if opt == '-o': outfile = arg
elif opt == '-i': impl = 1
else: opt_string = opt_string + ' ' + opt
-output.write("/* mymoc.py%s */\\n" % opt_string)
-for a in args:
- with open(a, 'r') as f:
- contents = f.read()
- a = a.replace('\\\\', '\\\\\\\\')
- subst = r'{ my_qt_symbol( "' + a + '\\\\n" ); }'
- if impl:
- contents = re.sub( r'#include.*', '', contents )
- output.write(contents.replace('Q_OBJECT', subst))
-output.close()
+
+with open(outfile, 'w') as ofp:
+ ofp.write("/* mymoc.py%s */\\n" % opt_string)
+ for a in args:
+ with open(a, 'r') as ifp:
+ contents = ifp.read()
+ a = a.replace('\\\\', '\\\\\\\\')
+ subst = r'{ my_qt_symbol( "' + a + '\\\\n" ); }'
+ if impl:
+ contents = re.sub(r'#include.*', '', contents)
+ ofp.write(contents.replace('Q_OBJECT', subst))
sys.exit(0)
""")
@@ -988,7 +988,7 @@ source = None
opt_string = ''
for arg in sys.argv[1:]:
if output_arg:
- output = open(arg, 'w')
+ outfile = arg
output_arg = 0
elif impl_arg:
impl = arg
@@ -1002,19 +1002,19 @@ for arg in sys.argv[1:]:
else:
if source:
sys.exit(1)
- source = open(arg, 'r')
- sourceFile = arg
-output.write("/* myuic.py%s */\\n" % opt_string)
-if impl:
- output.write( '#include "' + impl + '"\\n' )
- includes = re.findall('<include.*?>(.*?)</include>', source.read())
- for incFile in includes:
- # this is valid for ui.h files, at least
- if os.path.exists(incFile):
- output.write('#include "' + incFile + '"\\n')
-else:
- output.write( '#include "my_qobject.h"\\n' + source.read() + " Q_OBJECT \\n" )
-output.close()
+ source = sourceFile = arg
+
+with open(outfile, 'w') as ofp, open(source, 'r') as ifp:
+ ofp.write("/* myuic.py%s */\\n" % opt_string)
+ if impl:
+ ofp.write('#include "' + impl + '"\\n')
+ includes = re.findall('<include.*?>(.*?)</include>', ifp.read())
+ for incFile in includes:
+ # this is valid for ui.h files, at least
+ if os.path.exists(incFile):
+ ofp.write('#include "' + incFile + '"\\n')
+ else:
+ ofp.write('#include "my_qobject.h"\\n' + ifp.read() + " Q_OBJECT \\n")
sys.exit(0)
""" )
@@ -1027,7 +1027,7 @@ void my_qt_symbol(const char *arg);
#include "../include/my_qobject.h"
#include <stdio.h>
void my_qt_symbol(const char *arg) {
- fputs( arg, stdout );
+ fputs(arg, stdout);
}
""")
@@ -1035,9 +1035,9 @@ void my_qt_symbol(const char *arg) {
env = Environment()
import sys
if sys.platform == 'win32':
- env.StaticLibrary( 'myqt', 'my_qobject.cpp' )
+ env.StaticLibrary('myqt', 'my_qobject.cpp')
else:
- env.SharedLibrary( 'myqt', 'my_qobject.cpp' )
+ env.SharedLibrary('myqt', 'my_qobject.cpp')
""")
self.run(chdir = self.workpath(dir, 'lib'),
@@ -1080,7 +1080,7 @@ if ARGUMENTS.get('variant_dir', 0):
else:
sconscript = File('SConscript')
Export("env dup")
-SConscript( sconscript )
+SConscript(sconscript)
""" % (self.QT, self.QT_LIB, self.QT_MOC, self.QT_UIC))
diff --git a/testing/framework/TestSConsMSVS.py b/testing/framework/TestSConsMSVS.py
index 4c853dc..348d7ed 100644
--- a/testing/framework/TestSConsMSVS.py
+++ b/testing/framework/TestSConsMSVS.py
@@ -1045,7 +1045,7 @@ env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='10.0',
HOST_ARCH='%(HOST_ARCH)s')
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']
@@ -1068,7 +1068,7 @@ env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='11.0',
HOST_ARCH='%(HOST_ARCH)s')
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']
@@ -1091,7 +1091,7 @@ env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='14.0',
HOST_ARCH='%(HOST_ARCH)s')
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']
@@ -1114,7 +1114,7 @@ env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='14.1',
HOST_ARCH='%(HOST_ARCH)s')
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']