From d6823296e39adc6f147ae64f9be6ce64b8bb4a3e Mon Sep 17 00:00:00 2001 From: Craig Rodrigues Date: Sun, 12 Mar 2017 16:21:07 -0700 Subject: Fix some bytes/str issues to fix py2/3. --- test/DSUFFIXES.py | 4 ++-- test/DVIPDF/DVIPDFFLAGS.py | 4 ++-- test/DVIPS/DVIPSFLAGS.py | 4 ++-- test/Dir/source.py | 2 +- test/Ghostscript/GS.py | 6 +++--- test/Ghostscript/GSFLAGS.py | 6 +++--- test/HeaderGen.py | 6 +++--- test/Install/Install.py | 4 ++-- test/Repository/LIBPATH.py | 2 +- test/Value.py | 4 ++-- test/VariantDir/Clean.py | 2 +- test/VariantDir/File-create.py | 4 ++-- test/VariantDir/errors.py | 2 +- test/explain/get_csig.py | 2 +- test/gnutools.py | 46 +++++++++++++++++++++--------------------- 15 files changed, 49 insertions(+), 49 deletions(-) diff --git a/test/DSUFFIXES.py b/test/DSUFFIXES.py index bc441a5..46bdf83 100644 --- a/test/DSUFFIXES.py +++ b/test/DSUFFIXES.py @@ -38,8 +38,8 @@ test.write('mydc.py', r""" import sys def do_file(outf, inf): for line in open(inf, 'rb').readlines(): - if line[:7] == 'import ': - do_file(outf, line[7:-2]+'.d') + if line[:7] == b'import ': + do_file(outf, line[7:-2] + b'.d') else: outf.write(line) outf = open(sys.argv[1], 'wb') diff --git a/test/DVIPDF/DVIPDFFLAGS.py b/test/DVIPDF/DVIPDFFLAGS.py index 51a4c42..3704d60 100644 --- a/test/DVIPDF/DVIPDFFLAGS.py +++ b/test/DVIPDF/DVIPDFFLAGS.py @@ -55,7 +55,7 @@ base_name = os.path.splitext(arg[0])[0] infile = open(arg[0], 'r') out_file = open(base_name+'.dvi', 'w') for l in infile.readlines(): - if l[:6] != '#latex': + if l[:6] != b'#latex': out_file.write(l) sys.exit(0) """) @@ -114,7 +114,7 @@ if dvipdf and tex: test.write("wrapper.py", """import os import sys cmd = " ".join(sys.argv[1:]) -open('%s', 'ab').write("%%s\\n" %% cmd) +open('%s', 'a').write("%%s\\n" %% cmd) os.system(cmd) """ % test.workpath('wrapper.out').replace('\\', '\\\\')) diff --git a/test/DVIPS/DVIPSFLAGS.py b/test/DVIPS/DVIPSFLAGS.py index 7aedf24..43b5be5 100644 --- a/test/DVIPS/DVIPSFLAGS.py +++ b/test/DVIPS/DVIPSFLAGS.py @@ -41,7 +41,7 @@ base_name = os.path.splitext(arg[0])[0] infile = open(arg[0], 'r') out_file = open(base_name+'.dvi', 'w') for l in infile.readlines(): - if l[:4] != '#tex': + if l[:4] != b'#tex': out_file.write(l) sys.exit(0) """) @@ -55,7 +55,7 @@ base_name = os.path.splitext(arg[0])[0] infile = open(arg[0], 'r') out_file = open(base_name+'.dvi', 'w') for l in infile.readlines(): - if l[:6] != '#latex': + if l[:6] != b'#latex': out_file.write(l) sys.exit(0) """) diff --git a/test/Dir/source.py b/test/Dir/source.py index 8dbee1a..8e3bea6 100644 --- a/test/Dir/source.py +++ b/test/Dir/source.py @@ -44,7 +44,7 @@ test.subdir('tstamp', [ 'tstamp', 'subdir' ], test.write('SConstruct', """\ def writeTarget(target, source, env): f=open(str(target[0]), 'wb') - f.write("stuff\\n") + f.write(b"stuff\\n") f.close() return 0 diff --git a/test/Ghostscript/GS.py b/test/Ghostscript/GS.py index daeea09..d7a7456 100644 --- a/test/Ghostscript/GS.py +++ b/test/Ghostscript/GS.py @@ -41,7 +41,7 @@ import sys outfile = open(sys.argv[1], 'wb') infile = open(sys.argv[2], 'rb') for l in infile.readlines(): - if l[:3] != '#ps': + if l[:3] != b'#ps': outfile.write(l) sys.exit(0) """) @@ -60,8 +60,8 @@ test.write('test1.ps', r"""This is a .ps test. test.run(arguments = '.', stderr = None) -test.fail_test(test.read('test1.pdf') != "This is a .ps test.\n") -test.fail_test(test.read('test2.pdf') != "This is a .ps test.\n") +test.fail_test(test.read('test1.pdf') != b"This is a .ps test.\n") +test.fail_test(test.read('test2.pdf') != b"This is a .ps test.\n") diff --git a/test/Ghostscript/GSFLAGS.py b/test/Ghostscript/GSFLAGS.py index c8e0668..2e58ec1 100644 --- a/test/Ghostscript/GSFLAGS.py +++ b/test/Ghostscript/GSFLAGS.py @@ -48,9 +48,9 @@ for opt, arg in cmd_opts: else: opt_string = opt_string + ' ' + opt infile = open(args[0], 'rb') -out_file.write(opt_string + "\n") +out_file.write(opt_string.encode("utf-8") + b"\n") for l in infile.readlines(): - if l[:3] != '#ps': + if l[:3] != b'#ps': out_file.write(l) sys.exit(0) """) @@ -68,7 +68,7 @@ This is a .ps test. test.run(arguments = '.', stderr = None) -test.fail_test(test.read('test1.pdf') != " -x\nThis is a .ps test.\n") +test.fail_test(test.read('test1.pdf') != b" -x\nThis is a .ps test.\n") diff --git a/test/HeaderGen.py b/test/HeaderGen.py index 5a7fdbe..2763b34 100644 --- a/test/HeaderGen.py +++ b/test/HeaderGen.py @@ -35,7 +35,7 @@ test = TestSCons.TestSCons() test.write('SConstruct', """\ def writeFile(target, contents): - file = open(str(target[0]), 'wb') + file = open(str(target[0]), 'w') file.write(contents) file.close() return 0 @@ -60,8 +60,8 @@ test.write('SConstruct', """\ env = Environment() def gen_a_h(target, source, env): - t = open(str(target[0]), 'wb') - s = open(str(source[0]), 'rb') + t = open(str(target[0]), 'w') + s = open(str(source[0]), 'r') s.readline() t.write(s.readline()[:-1] + ';\\n') diff --git a/test/Install/Install.py b/test/Install/Install.py index d66660b..8c3bccd 100644 --- a/test/Install/Install.py +++ b/test/Install/Install.py @@ -58,7 +58,7 @@ def cat(env, source, target): def my_install(dest, source, env): import shutil shutil.copy2(source, dest) - open('my_install.out', 'ab').write(dest) + open('my_install.out', 'a').write(dest) env1 = Environment() env1.Append(BUILDERS={'Cat':Builder(action=cat)}) @@ -122,7 +122,7 @@ 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, 'wb').write("xyzzy\n") +open(f2_out, 'wb').write(b"xyzzy\n") test.must_match(['work', 'f2.out'], "f2.in\n") # Verify that scons prints an error message diff --git a/test/Repository/LIBPATH.py b/test/Repository/LIBPATH.py index c95d29a..166060e 100644 --- a/test/Repository/LIBPATH.py +++ b/test/Repository/LIBPATH.py @@ -46,7 +46,7 @@ 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]), 'wb') + f = open(str(target[0]), 'w') for arg in env.subst('$_LIBDIRFLAGS', target=target).split(): if arg[:len(pre)] == pre: arg = arg[len(pre):] diff --git a/test/Value.py b/test/Value.py index 7abe758..34b036b 100644 --- a/test/Value.py +++ b/test/Value.py @@ -59,7 +59,7 @@ env.B('f3.out', Value(C)) env.S('f4.out', Value(L)) def create_value (target, source, env): - target[0].write(source[0].get_contents ()) + target[0].write(source[0].get_contents()) def create_value_file (target, source, env): open(str(target[0]), 'wb').write(source[0].read()) @@ -75,7 +75,7 @@ env.B3('f5.out', V) test.write('put.py', """\ import os import sys -open(sys.argv[-1],'wb').write(" ".join(sys.argv[1:-2])) +open(sys.argv[-1],'w').write(" ".join(sys.argv[1:-2])) """) # Run all of the tests with both types of source signature diff --git a/test/VariantDir/Clean.py b/test/VariantDir/Clean.py index d1e0bb8..ca14738 100644 --- a/test/VariantDir/Clean.py +++ b/test/VariantDir/Clean.py @@ -44,7 +44,7 @@ def build_sample(target, source, env): targetdir = str(target[0].dir) target = str(target[0]) open(target, 'wb').write(open(str(source[0]), 'rb').read()) - open(targetdir+'/sample.junk', 'wb').write('Side effect!\\n') + open(targetdir+'/sample.junk', 'wb').write(b'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/File-create.py b/test/VariantDir/File-create.py index 725404c..1386020 100644 --- a/test/VariantDir/File-create.py +++ b/test/VariantDir/File-create.py @@ -49,12 +49,12 @@ SConscript('src/SConscript', variant_dir='build1', chdir=1, duplicate=1) test.write(['src', 'SConscript'], """\ #f1_in = File('f1.in') #Command('f1.out', f1_in, Copy('$TARGET', '$SOURCE')) -#open('f1.in', 'wb').write("f1.in\\n") +#open('f1.in', 'wb').write(b"f1.in\\n") f2_in = File('f2.in') str(f2_in) Command('f2.out', f2_in, Copy('$TARGET', '$SOURCE')) -open('f2.in', 'wb').write("f2.in\\n") +open('f2.in', 'wb').write(b"f2.in\\n") """) test.run(arguments = '--tree=all .') diff --git a/test/VariantDir/errors.py b/test/VariantDir/errors.py index d1490d4..256734e 100644 --- a/test/VariantDir/errors.py +++ b/test/VariantDir/errors.py @@ -77,7 +77,7 @@ env.Build('file.out', 'file.in') # Just verify that the normal case works fine. test.run(chdir = 'normal', arguments = ".") -test.fail_test(test.read(['normal', 'build', 'file.out']) != "normal/src/file.in\n") +test.fail_test(test.read(['normal', 'build', 'file.out']) != b"normal/src/file.in\n") # Verify the error when the VariantDir itself is read-only. Don't bother # to test this on Windows, because the ACL (I think) still allows the diff --git a/test/explain/get_csig.py b/test/explain/get_csig.py index d35a315..8a0266a 100644 --- a/test/explain/get_csig.py +++ b/test/explain/get_csig.py @@ -43,7 +43,7 @@ env = Environment() def action( source, target, env ): target[0].get_csig() - f = open( str(target[0]), 'w' ) + f = open( str(target[0]), 'wb' ) for s in source: f.write( s.get_contents() ) f.close() diff --git a/test/gnutools.py b/test/gnutools.py index b0ebc1c..65d699b 100644 --- a/test/gnutools.py +++ b/test/gnutools.py @@ -49,11 +49,11 @@ cmd_opts, args = getopt.getopt(sys.argv[1:], 'f:s:co:', []) output = None opt_string = '' for opt, arg in cmd_opts: - if opt == '-o': output = open(arg, 'wb') + if opt == '-o': output = open(arg, 'w') else: opt_string = opt_string + ' ' + opt + arg output.write('gcc ' + opt_string + '\\n') for a in args: - contents = open(a, 'rb').read() + contents = open(a, 'r').read() output.write(contents) output.close() sys.exit(0) @@ -66,11 +66,11 @@ cmd_opts, args = getopt.getopt(sys.argv[1:], 'f:s:co:', []) output = None opt_string = '' for opt, arg in cmd_opts: - if opt == '-o': output = open(arg, 'wb') + if opt == '-o': output = open(arg, 'w') else: opt_string = opt_string + ' ' + opt + arg output.write('g++ ' + opt_string + '\\n') for a in args: - contents = open(a, 'rb').read() + contents = open(a, 'r').read() output.write(contents) output.close() sys.exit(0) @@ -116,31 +116,31 @@ test.run(chdir='work1') def testObject(test, obj, expect): contents = test.read(test.workpath('work1', obj)) - line1 = contents.split('\n')[0] - actual = ' '.join(line1.split()) + line1 = contents.split(b'\n')[0] + actual = b' '.join(line1.split()) if not expect == actual: print("%s: %s != %s\n" % (obj, repr(expect), repr(actual))) test.fail_test() if sys.platform in ('win32', 'cygwin'): - c_fpic = '' + c_fpic = b'' else: - c_fpic = ' -fPIC' - -testObject(test, 'cfile1.o', 'gcc -c') -testObject(test, 'cfile2.o', 'gcc -c') -testObject(test, 'cppfile1.o', 'g++ -c') -testObject(test, 'cppfile2.o', 'g++ -c') -testObject(test, 'cfile1.os', 'gcc -c' + c_fpic) -testObject(test, 'cfile2.os', 'gcc -c' + c_fpic) -testObject(test, 'cppfile1.os', 'g++ -c' + c_fpic) -testObject(test, 'cppfile2.os', 'g++ -c' + c_fpic) -testObject(test, 'c-only' + _exe, 'gcc') -testObject(test, 'cpp-only' + _exe, 'g++') -testObject(test, 'c-and-cpp' + _exe, 'g++') -testObject(test, dll('c-only'), 'gcc -shared') -testObject(test, dll('cpp-only'), 'g++ -shared') -testObject(test, dll('c-and-cpp'), 'g++ -shared') + c_fpic = b' -fPIC' + +testObject(test, 'cfile1.o', b'gcc -c') +testObject(test, 'cfile2.o', b'gcc -c') +testObject(test, 'cppfile1.o', b'g++ -c') +testObject(test, 'cppfile2.o', b'g++ -c') +testObject(test, 'cfile1.os', b'gcc -c' + c_fpic) +testObject(test, 'cfile2.os', b'gcc -c' + c_fpic) +testObject(test, 'cppfile1.os', b'g++ -c' + c_fpic) +testObject(test, 'cppfile2.os', b'g++ -c' + c_fpic) +testObject(test, 'c-only' + _exe, b'gcc') +testObject(test, 'cpp-only' + _exe, b'g++') +testObject(test, 'c-and-cpp' + _exe, b'g++') +testObject(test, dll('c-only'), b'gcc -shared') +testObject(test, dll('cpp-only'), b'g++ -shared') +testObject(test, dll('c-and-cpp'), b'g++ -shared') test.pass_test() -- cgit v0.12 From 8d600a70cdbdaf648e0ef5405cb8d321de12a4a2 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 13 Mar 2017 09:10:21 -0400 Subject: fix unicode usage for --debug=tree py2/3 --- src/engine/SCons/Util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 9d125ae..6d7b0a7 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -308,7 +308,7 @@ def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited=None): ' N = no clean\n' + ' H = no cache\n' + '\n') - sys.stdout.write(u(legend)) + sys.stdout.write(legend) tags = ['['] tags.append(' E'[IDX(root.exists())]) -- cgit v0.12 From 3b23df1f6b2135739b988a497d98d85dd8a806fa Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 13 Mar 2017 10:44:38 -0400 Subject: py2/3 fix rb/wb, switch to must_match and mode='r' --- test/Ghostscript/GS.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/Ghostscript/GS.py b/test/Ghostscript/GS.py index daeea09..3f5aa58 100644 --- a/test/Ghostscript/GS.py +++ b/test/Ghostscript/GS.py @@ -38,8 +38,8 @@ test = TestSCons.TestSCons() test.write('mygs.py', r""" import os import sys -outfile = open(sys.argv[1], 'wb') -infile = open(sys.argv[2], 'rb') +outfile = open(sys.argv[1], 'w') +infile = open(sys.argv[2], 'r') for l in infile.readlines(): if l[:3] != '#ps': outfile.write(l) @@ -60,8 +60,8 @@ test.write('test1.ps', r"""This is a .ps test. test.run(arguments = '.', stderr = None) -test.fail_test(test.read('test1.pdf') != "This is a .ps test.\n") -test.fail_test(test.read('test2.pdf') != "This is a .ps test.\n") +test.must_match('test1.pdf', "This is a .ps test.\n", mode='r') +test.must_match('test2.pdf', "This is a .ps test.\n", mode='r') @@ -79,7 +79,7 @@ if gs: import os import sys cmd = " ".join(sys.argv[1:]) -open('%s', 'ab').write("%%s\\n" %% cmd) +open('%s', 'a').write("%%s\\n" %% cmd) os.system(cmd) """ % test.workpath('wrapper.out').replace('\\', '\\\\')) @@ -110,7 +110,7 @@ bar.PDF(target = 'bar.pdf', source = 'bar.ps') test.run(arguments = 'bar.pdf', stderr = None) - test.fail_test(test.read('wrapper.out') != "%s -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=bar.pdf bar.ps\n" % gs_executable) + test.must_match('wrapper.out', "%s -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=bar.pdf bar.ps\n" % gs_executable, mode='r') test.fail_test(not os.path.exists(test.workpath('bar.pdf'))) -- cgit v0.12 -- cgit v0.12