summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGreg Noel <GregNoel@tigris.org>2010-03-27 07:39:52 (GMT)
committerGreg Noel <GregNoel@tigris.org>2010-03-27 07:39:52 (GMT)
commit59ed0a109bf5add2efcef459080837b11066c6fb (patch)
treefff879b4f9676a72e16c0f7b4dd969f050038b4f /test
parent00a3188193ba1feef927cf18e7f5fc20ad71b848 (diff)
downloadSCons-59ed0a109bf5add2efcef459080837b11066c6fb.zip
SCons-59ed0a109bf5add2efcef459080837b11066c6fb.tar.gz
SCons-59ed0a109bf5add2efcef459080837b11066c6fb.tar.bz2
http://scons.tigris.org/issues/show_bug.cgi?id=2329
Applied a number of idiomatic changes. Uses of the 'sort()' method were converted into calls of 'sorted()' when possible and the sorted() expression was inserted into a subsequent statement whenever that made sense. The statement 'while 1:' was changed to 'while True:'. Names from the 'types' module (e.g., 'types.FooType') were converted to the equivalent build-in type (e.g., 'foo'). Comparisons between types were changed to use 'isinstance()'.
Diffstat (limited to 'test')
-rw-r--r--test/ARGUMENTS.py4
-rw-r--r--test/Builder-factories.py4
-rw-r--r--test/Command.py4
-rw-r--r--test/Copy-Action.py4
-rw-r--r--test/GetBuildFailures/option-k.py5
-rw-r--r--test/GetBuildFailures/parallel.py4
-rw-r--r--test/GetBuildFailures/serial.py4
-rw-r--r--test/Glob/Repository.py4
-rw-r--r--test/Glob/VariantDir.py4
-rw-r--r--test/Glob/basic.py4
-rw-r--r--test/Glob/source.py8
-rw-r--r--test/Glob/strings.py4
-rw-r--r--test/Glob/subdir.py4
-rw-r--r--test/Glob/subst.py4
-rw-r--r--test/Mkdir.py4
-rw-r--r--test/Scanner/generated.py4
-rw-r--r--test/Scanner/no-Dir-node.py4
-rw-r--r--test/TAR/TAR.py2
-rw-r--r--test/TAR/TARFLAGS.py2
-rw-r--r--test/ZIP/ZIP.py5
-rw-r--r--test/option--C.py5
-rw-r--r--test/option/help-options.py7
-rw-r--r--test/packaging/convenience-functions.py6
23 files changed, 35 insertions, 65 deletions
diff --git a/test/ARGUMENTS.py b/test/ARGUMENTS.py
index c028372..801d83a 100644
--- a/test/ARGUMENTS.py
+++ b/test/ARGUMENTS.py
@@ -30,9 +30,7 @@ test = TestSCons.TestSCons()
test.write('SConstruct', """
foo = open('foo.out', 'wb')
-keys = ARGUMENTS.keys()
-keys.sort()
-for k in keys:
+for k in sorted(list(ARGUMENTS.keys())):
foo.write(k + " = " + ARGUMENTS[k] + "\\n")
foo.close()
""")
diff --git a/test/Builder-factories.py b/test/Builder-factories.py
index fec9077..673920c 100644
--- a/test/Builder-factories.py
+++ b/test/Builder-factories.py
@@ -48,9 +48,7 @@ MakeDirectory = Builder(action=mkdir, target_factory=Dir)
def collect(env, source, target):
out = open(str(target[0]), 'wb')
dir = str(source[0])
- files = os.listdir(dir)
- files.sort()
- for f in files:
+ for f in sorted(os.listdir(dir)):
f = os.path.join(dir, f)
out.write(open(f, 'r').read())
out.close()
diff --git a/test/Command.py b/test/Command.py
index f3be46a..74046b1 100644
--- a/test/Command.py
+++ b/test/Command.py
@@ -58,9 +58,7 @@ def sub(env, target, source):
target = str(target[0])
source = str(source[0])
t = open(target, 'wb')
- files = os.listdir(source)
- files.sort()
- for f in files:
+ for f in sorted(os.listdir(source)):
t.write(open(os.path.join(source, f), 'rb').read())
t.close()
return 0
diff --git a/test/Copy-Action.py b/test/Copy-Action.py
index f64defe..51635c5 100644
--- a/test/Copy-Action.py
+++ b/test/Copy-Action.py
@@ -153,9 +153,9 @@ errors = 0
def must_be_same(f1, f2):
global errors
- if type(f1) is type([]):
+ if isinstance(f1, list):
f1 = os.path.join(*f1)
- if type(f2) is type([]):
+ if isinstance(f2, list):
f2 = os.path.join(*f2)
s1 = os.stat(f1)
s2 = os.stat(f2)
diff --git a/test/GetBuildFailures/option-k.py b/test/GetBuildFailures/option-k.py
index 532c379..53b57ff 100644
--- a/test/GetBuildFailures/option-k.py
+++ b/test/GetBuildFailures/option-k.py
@@ -64,9 +64,8 @@ Command('f6', 'f6.in', r'@%(_python_)s mypass.py f5 - $TARGET $SOURCE')
def print_build_failures():
from SCons.Script import GetBuildFailures
- bf_list = GetBuildFailures()
- bf_list.sort(lambda a,b: cmp(a.filename, b.filename))
- for bf in bf_list:
+ for bf in sorted(GetBuildFailures(),
+ cmp=lambda a,b: cmp(a.filename, b.filename)):
print "%%s failed: %%s" %% (bf.node, bf.errstr)
try:
diff --git a/test/GetBuildFailures/parallel.py b/test/GetBuildFailures/parallel.py
index 6ee5cc3..e250486 100644
--- a/test/GetBuildFailures/parallel.py
+++ b/test/GetBuildFailures/parallel.py
@@ -79,9 +79,7 @@ Command('f6', 'f6.in', r'@%(_python_)s mypass.py f5 - $TARGET $SOURCE')
def print_build_failures():
from SCons.Script import GetBuildFailures
- bf_list = GetBuildFailures()
- bf_list.sort(lambda a,b: cmp(a.filename, b.filename))
- for bf in bf_list:
+ for bf in sorted(GetBuildFailures(), key=lambda t: t.filename):
print "%%s failed: %%s" %% (bf.node, bf.errstr)
try:
diff --git a/test/GetBuildFailures/serial.py b/test/GetBuildFailures/serial.py
index a240d1e..752b348 100644
--- a/test/GetBuildFailures/serial.py
+++ b/test/GetBuildFailures/serial.py
@@ -89,9 +89,7 @@ Command('f15', 'f15.in', returnExcAction(SCons.Errors.InternalError("My Internal
def print_build_failures():
from SCons.Script import GetBuildFailures
- bf_list = GetBuildFailures()
- bf_list.sort(lambda a,b: cmp(str(a.node), str(b.node)))
- for bf in bf_list:
+ for bf in sorted(GetBuildFailures(), key=lambda t: str(t.node)):
assert( isinstance(bf, SCons.Errors.BuildError) )
print "BF: %%s failed (%%s): %%s" %% (bf.node, bf.status, bf.errstr)
if bf.command:
diff --git a/test/Glob/Repository.py b/test/Glob/Repository.py
index 5783443..0a2e326 100644
--- a/test/Glob/Repository.py
+++ b/test/Glob/Repository.py
@@ -75,9 +75,7 @@ test.write(['repository', 'src', 'SConscript'], """
Import("env")
env.Build('xxx.out', Glob('x*.in'))
env.Build('yyy.out', Glob('yy?.in'))
-zzz_in = Glob('*/zzz.in')
-zzz_in.sort(lambda a,b: cmp(a.abspath, b.abspath))
-env.Build('zzz.out', zzz_in)
+env.Build('zzz.out', sorted(Glob('*/zzz.in'), key=lambda t: t.abspath))
""")
test.write(['repository', 'src', 'xxx.in'], "repository/src/xxx.in\n")
diff --git a/test/Glob/VariantDir.py b/test/Glob/VariantDir.py
index 62226ce..175e5b9 100644
--- a/test/Glob/VariantDir.py
+++ b/test/Glob/VariantDir.py
@@ -54,9 +54,7 @@ def concatenate(target, source, env):
env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
-f_in = Glob('f*.in')
-f_in.sort(lambda a,b: cmp(a.name, b.name))
-env.Concatenate('f.out', f_in)
+env.Concatenate('f.out', sorted(Glob('f*.in'), key=lambda t: t.name))
""")
test.write(['src', 'f1.in'], "src/f1.in\n")
diff --git a/test/Glob/basic.py b/test/Glob/basic.py
index d985a73..9afbbc6 100644
--- a/test/Glob/basic.py
+++ b/test/Glob/basic.py
@@ -43,9 +43,7 @@ def concatenate(target, source, env):
env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
-f_in = Glob('f*.in')
-f_in.sort(lambda a,b: cmp(a.name, b.name))
-env.Concatenate('f.out', f_in)
+env.Concatenate('f.out', sorted(Glob('f*.in'), key=lambda t: t.name))
""")
test.write('f1.in', "f1.in\n")
diff --git a/test/Glob/source.py b/test/Glob/source.py
index 33baf37..afa17f5 100644
--- a/test/Glob/source.py
+++ b/test/Glob/source.py
@@ -59,16 +59,14 @@ SConscript('var2/SConscript')
test.write(['var1', 'SConscript'], """\
Import("env")
-f_in = Glob('f[45].in', source=True)
-f_in.sort(lambda a,b: cmp(a.name, b.name))
-env.Concatenate('f.out', f_in)
+env.Concatenate('f.out', sorted(Glob('f[45].in', source=True),
+ key=lambda t: t.name))
""")
test.write(['var2', 'SConscript'], """\
Import("env")
-f_in = Glob('f[67].in')
-f_in.sort(lambda a,b: cmp(a.name, b.name))
+f_in = sorted(Glob('f[67].in'), cmp=lambda a,b: cmp(a.name, b.name))
env.Concatenate('f.out', f_in)
""")
diff --git a/test/Glob/strings.py b/test/Glob/strings.py
index 1ef0421..3e47d10 100644
--- a/test/Glob/strings.py
+++ b/test/Glob/strings.py
@@ -55,9 +55,7 @@ def concatenate(target, source, env):
env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
-f_in = Glob('f*.in', strings=True)
-f_in.sort()
-env.Concatenate('f.out', f_in)
+env.Concatenate('f.out', sorted(Glob('f*.in', strings=True)))
""")
test.write(['src', 'f1.in'], "src/f1.in\n")
diff --git a/test/Glob/subdir.py b/test/Glob/subdir.py
index 0255ff8..6fc00f6 100644
--- a/test/Glob/subdir.py
+++ b/test/Glob/subdir.py
@@ -46,9 +46,7 @@ def concatenate(target, source, env):
env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
-f_in = Glob('subdir/*.in')
-f_in.sort(lambda a,b: cmp(a.name, b.name))
-env.Concatenate('f.out', f_in)
+env.Concatenate('f.out', sorted(Glob('subdir/*.in'), key=lambda t: t.name))
""")
test.write(['subdir', 'file.in'], "subdir/file.in\n")
diff --git a/test/Glob/subst.py b/test/Glob/subst.py
index abf2bb4..e21da81 100644
--- a/test/Glob/subst.py
+++ b/test/Glob/subst.py
@@ -44,9 +44,7 @@ def copy(target, source, env):
env['BUILDERS']['Copy'] = Builder(action=copy)
-f_in = env.Glob('$PATTERN')
-f_in.sort(lambda a,b: cmp(a.name, b.name))
-env.Copy('f.out', f_in)
+env.Copy('f.out', sorted(env.Glob('$PATTERN'), key=lambda t: t.name))
""")
test.write('f1.in', "f1.in\n")
diff --git a/test/Mkdir.py b/test/Mkdir.py
index 094e6ed..dbeecb7 100644
--- a/test/Mkdir.py
+++ b/test/Mkdir.py
@@ -129,9 +129,7 @@ def catdir(env, source, target):
outfp = open(target, "wb")
for src in source:
s = str(src)
- l = os.listdir(s)
- l.sort()
- for f in l:
+ for f in sorted(os.listdir(s)):
f = os.path.join(s, f)
if os.path.isfile(f):
outfp.write(open(f, "rb").read())
diff --git a/test/Scanner/generated.py b/test/Scanner/generated.py
index 8c90df4..0212043 100644
--- a/test/Scanner/generated.py
+++ b/test/Scanner/generated.py
@@ -301,10 +301,8 @@ import os
Scanned = {}
def write_out(file, dict):
- keys = dict.keys()
- keys.sort()
f = open(file, 'wb')
- for k in keys:
+ for k in sorted(dict.keys()):
file = os.path.split(k)[1]
f.write(file + ": " + str(dict[k]) + "\\n")
f.close()
diff --git a/test/Scanner/no-Dir-node.py b/test/Scanner/no-Dir-node.py
index 9a47c01..3a918bf 100644
--- a/test/Scanner/no-Dir-node.py
+++ b/test/Scanner/no-Dir-node.py
@@ -81,10 +81,8 @@ sys.exit(0)
test.write('SConstruct', """\
def foo(target, source, env):
- children = source[0].children()
- children.sort(lambda a,b: cmp(a.name, b.name))
fp = open(str(target[0]), 'wb')
- for c in children:
+ for c in sorted(source[0].children(), key=lambda t: t.name):
fp.write('%s\\n' % c)
fp.close()
Command('list.out', 'subdir', foo, source_scanner = DirScanner)
diff --git a/test/TAR/TAR.py b/test/TAR/TAR.py
index ac8d791..5a19a98 100644
--- a/test/TAR/TAR.py
+++ b/test/TAR/TAR.py
@@ -44,6 +44,8 @@ for opt, arg in opts:
if opt == '-f': out = arg
def process(outfile, name):
if os.path.isdir(name):
+ ## TODO 2.5: the next three lines can be replaced by
+ #for entry in sorted(os.listdir(name)):
list = os.listdir(name)
list.sort()
for entry in list:
diff --git a/test/TAR/TARFLAGS.py b/test/TAR/TARFLAGS.py
index f349b3a..96d61fe 100644
--- a/test/TAR/TARFLAGS.py
+++ b/test/TAR/TARFLAGS.py
@@ -46,6 +46,8 @@ for opt, arg in cmd_opts:
else: opt_string = opt_string + ' ' + opt
def process(outfile, name):
if os.path.isdir(name):
+ ## TODO 2.5: the next three lines can be replaced by
+ #for entry in sorted(os.listdir(name)):
entries = os.listdir(name)
entries.sort()
for entry in entries:
diff --git a/test/ZIP/ZIP.py b/test/ZIP/ZIP.py
index 73e7810..f9ba417 100644
--- a/test/ZIP/ZIP.py
+++ b/test/ZIP/ZIP.py
@@ -49,6 +49,8 @@ import os.path
import sys
def process(outfile, name):
if os.path.isdir(name):
+ ## TODO 2.5: the next three lines can be replaced by
+ #for entry in sorted(os.listdir(name)):
list = os.listdir(name)
list.sort()
for entry in list:
@@ -115,10 +117,9 @@ if zip:
test.write('SConstruct', """\
def marker(target, source, env):
open(r'%s', 'wb').write("marker\\n")
-import types
f1 = Environment()
zipcom = f1.Dictionary('ZIPCOM')
-if not type(zipcom) is types.ListType:
+if not isinstance(zipcom, list):
zipcom = [zipcom]
f2 = Environment(ZIPCOM = [Action(marker)] + zipcom)
f3 = Environment(ZIPSUFFIX = '.xyzzy')
diff --git a/test/option--C.py b/test/option--C.py
index 1a9a72b..27f4950 100644
--- a/test/option--C.py
+++ b/test/option--C.py
@@ -25,14 +25,13 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import os
-import types
import TestSCons
def match_normcase(lines, matches):
- if not type(lines) is types.ListType:
+ if not isinstance(lines, list):
lines = lines.split("\n")
- if not type(matches) is types.ListType:
+ if not isinstance(matches, list):
matches = matches.split("\n")
if len(lines) != len(matches):
return
diff --git a/test/option/help-options.py b/test/option/help-options.py
index 0f4dd4d..2b48a66 100644
--- a/test/option/help-options.py
+++ b/test/option/help-options.py
@@ -60,11 +60,10 @@ lines = [x[0] == '-' and x[1:] or x for x in lines]
options = [x.split()[0] for x in lines]
options = [x[-1] == ',' and x[:-1] or x for x in options]
lowered = [x.lower() for x in options]
-sorted = lowered[:]
-sorted.sort()
-if lowered != sorted:
+ordered = sorted(lowered)
+if lowered != ordered:
print "lowered =", lowered
- print "sorted =", sorted
+ print "sorted =", ordered
test.fail_test()
test.pass_test()
diff --git a/test/packaging/convenience-functions.py b/test/packaging/convenience-functions.py
index 66374e3..2fc6aee 100644
--- a/test/packaging/convenience-functions.py
+++ b/test/packaging/convenience-functions.py
@@ -43,10 +43,8 @@ env = Environment(tools=['default', 'packaging'])
prog = env.Install( 'bin/', ["f1", "f2"] )
env.File( "f3" )
-src_files = list(map(str, env.FindSourceFiles()))
-oth_files = list(map(str, env.FindInstalledFiles()))
-src_files.sort()
-oth_files.sort()
+src_files = sorted(map(str, env.FindSourceFiles()))
+oth_files = sorted(map(str, env.FindInstalledFiles()))
print src_files
print oth_files