summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4>2009-07-11 00:13:41 +0000
committermbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4>2009-07-11 00:13:41 +0000
commit78b48810bd1a3e71a070c0fcc23af33cac83d17c (patch)
tree362e6b3cbfa8e40c9c6e6e66f9509f54027e8282
parent28cd027c2c930661dcd328057e967adf6faa1c6f (diff)
Update parser unittests to use autotemp
Signed-off-by: Scott Zawalski <scottz@google.com> git-svn-id: svn://test.kernel.org/autotest/trunk@3397 592f7852-d20e-0410-864c-8624ca9c26a4
-rw-r--r--tko/parsers/test/new_scenario.py8
-rw-r--r--tko/parsers/test/scenario_base.py22
2 files changed, 19 insertions, 11 deletions
diff --git a/tko/parsers/test/new_scenario.py b/tko/parsers/test/new_scenario.py
index 37efdcfc..134626ee 100644
--- a/tko/parsers/test/new_scenario.py
+++ b/tko/parsers/test/new_scenario.py
@@ -17,11 +17,12 @@ While much is done automatically, a scenario harness is meant to
be easily extended and configured once generated.
"""
-import optparse, os, shutil, sys, tempfile
+import optparse, os, shutil, sys
from os import path
import common
from autotest_lib.tko.parsers.test import scenario_base
+from autotest_lib.client.common_lib import autotemp
usage = 'usage: %prog [options] results_dirpath scenerios_dirpath'
parser = optparse.OptionParser(usage=usage)
@@ -74,8 +75,8 @@ def main():
os.mkdir(scenario_package_dirpath)
# Create tmp_dir
- tmp_dirpath = tempfile.mkdtemp()
- copied_dirpath = path.join(tmp_dirpath, results_dirname)
+ tmp_dirpath = autotemp.tempdir(unique_id='new_scenario')
+ copied_dirpath = path.join(tmp_dirpath.name, results_dirname)
# Copy results_dir
shutil.copytree(results_dirpath, copied_dirpath)
@@ -103,6 +104,7 @@ def main():
scenario_base.install_unittest_module(
scenario_package_dirpath, options.template_type)
+ tmp_dirpath.clean()
if __name__ == '__main__':
diff --git a/tko/parsers/test/scenario_base.py b/tko/parsers/test/scenario_base.py
index 01f27d4b..4bbbb46b 100644
--- a/tko/parsers/test/scenario_base.py
+++ b/tko/parsers/test/scenario_base.py
@@ -2,10 +2,10 @@
"""
from os import path
-import ConfigParser, os, shelve, shutil, sys, tarfile, tempfile, time
+import ConfigParser, os, shelve, shutil, sys, tarfile, time
import difflib, itertools
import common
-from autotest_lib.client.common_lib import utils
+from autotest_lib.client.common_lib import utils, autotemp
from autotest_lib.tko import status_lib
from autotest_lib.tko.parsers.test import templates
from autotest_lib.tko.parsers.test import unittest_hotfix
@@ -208,7 +208,8 @@ class BaseScenarioTestCase(unittest_hotfix.TestCase):
unittest_hotfix.TestCase.__init__(self, methodName)
self.package_dirpath = path.dirname(
sys.modules[self.__module__].__file__)
- self.results_dirpath = load_results_dir(self.package_dirpath)
+ self.tmp_dirpath, self.results_dirpath = load_results_dir(
+ self.package_dirpath)
self.parser_result_store = load_parser_result_store(
self.package_dirpath)
self.config = load_config(self.package_dirpath)
@@ -224,6 +225,11 @@ class BaseScenarioTestCase(unittest_hotfix.TestCase):
self.harness = new_parser_harness(self.results_dirpath)
+ def tearDown(self):
+ if self.tmp_dirpath:
+ self.tmp_dirpath.clean()
+
+
def test_status_version(self):
"""Ensure basic sanity."""
self.skipIf(not self.harness)
@@ -323,15 +329,15 @@ def load_results_dir(package_dirpath):
"""
tgz_filepath = path.join(package_dirpath, RESULTS_DIR_TARBALL)
if not path.exists(tgz_filepath):
- return None
+ return None, None
tgz = tarfile.open(tgz_filepath, 'r:gz')
- tmp_dirpath = tempfile.mkdtemp()
+ tmp_dirpath = autotemp.tempdir(unique_id='scenario_base')
results_dirname = tgz.next().name
- tgz.extract(results_dirname, tmp_dirpath)
+ tgz.extract(results_dirname, tmp_dirpath.name)
for info in tgz:
- tgz.extract(info.name, tmp_dirpath)
- return path.join(tmp_dirpath, results_dirname)
+ tgz.extract(info.name, tmp_dirpath.name)
+ return tmp_dirpath, path.join(tmp_dirpath.name, results_dirname)
def write_config(package_dirpath, **properties):