Bug 903606 - Use mozfile.TemporaryDirectory in cppunittest scripts;r=ted

This commit is contained in:
Dan Minor
2013-08-19 10:02:42 -04:00
parent 9b4e8e2e89
commit f8c3947cc1
2 changed files with 3 additions and 9 deletions

View File

@@ -132,7 +132,7 @@ class RemoteCPPUnitTests(cppunittests.CPPUnitTests):
returncode = self.device.shell([remote_bin], buf, env=env, cwd=self.remote_home_dir, returncode = self.device.shell([remote_bin], buf, env=env, cwd=self.remote_home_dir,
timeout=cppunittests.CPPUnitTests.TEST_PROC_TIMEOUT) timeout=cppunittests.CPPUnitTests.TEST_PROC_TIMEOUT)
print >> sys.stdout, buf.getvalue() print >> sys.stdout, buf.getvalue()
with cppunittests.TemporaryDirectory() as tempdir: with mozfile.TemporaryDirectory() as tempdir:
self.device.getDirectory(self.remote_home_dir, tempdir) self.device.getDirectory(self.remote_home_dir, tempdir)
if mozcrash.check_for_crashes(tempdir, symbols_path, if mozcrash.check_for_crashes(tempdir, symbols_path,
test_name=basename): test_name=basename):

View File

@@ -7,17 +7,11 @@
from __future__ import with_statement from __future__ import with_statement
import sys, os, tempfile, shutil import sys, os, tempfile, shutil
from optparse import OptionParser from optparse import OptionParser
import mozprocess, mozinfo, mozlog, mozcrash import mozprocess, mozinfo, mozlog, mozcrash, mozfile
from contextlib import contextmanager from contextlib import contextmanager
log = mozlog.getLogger('cppunittests') log = mozlog.getLogger('cppunittests')
@contextmanager
def TemporaryDirectory():
tempdir = tempfile.mkdtemp()
yield tempdir
shutil.rmtree(tempdir)
class CPPUnitTests(object): class CPPUnitTests(object):
# Time (seconds) to wait for test process to complete # Time (seconds) to wait for test process to complete
TEST_PROC_TIMEOUT = 1200 TEST_PROC_TIMEOUT = 1200
@@ -38,7 +32,7 @@ class CPPUnitTests(object):
""" """
basename = os.path.basename(prog) basename = os.path.basename(prog)
log.info("Running test %s", basename) log.info("Running test %s", basename)
with TemporaryDirectory() as tempdir: with mozfile.TemporaryDirectory() as tempdir:
proc = mozprocess.ProcessHandler([prog], proc = mozprocess.ProcessHandler([prog],
cwd=tempdir, cwd=tempdir,
env=env) env=env)