summaryrefslogtreecommitdiffstats
path: root/test/Alias/action.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/Alias/action.py')
-rw-r--r--test/Alias/action.py14
1 files changed, 8 insertions, 6 deletions
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)