From 975059ae8857a557c2a294e097febeb620533dec Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 19 Aug 2010 21:52:58 -0700 Subject: [PATCH] Fix BinTestCase instances to stop leaving orphan temp dirs. --- pym/portage/tests/bin/setup_env.py | 15 +++++++-------- pym/portage/tests/bin/test_dobin.py | 14 +++++++++----- pym/portage/tests/bin/test_dodir.py | 14 +++++++++----- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/pym/portage/tests/bin/setup_env.py b/pym/portage/tests/bin/setup_env.py index a73e2ddc8..e07643de5 100644 --- a/pym/portage/tests/bin/setup_env.py +++ b/pym/portage/tests/bin/setup_env.py @@ -1,5 +1,5 @@ # setup_env.py -- Make sure bin subdir has sane env for testing -# Copyright 2007 Gentoo Foundation +# Copyright 2007-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import tempfile @@ -40,16 +40,12 @@ def binTestsInit(): os.mkdir(env["D"]) os.mkdir(env["T"]) os.mkdir(env["S"]) - os.chdir(env["S"]) class BinTestCase(TestCase): - def __init__(self, methodName): - TestCase.__init__(self, methodName) + def init(self): binTestsInit() - def __del__(self): + def cleanup(self): binTestsCleanup() - if hasattr(TestCase, "__del__"): - TestCase.__del__(self) def _exists_in_D(path): # Note: do not use os.path.join() here, we assume D to end in / @@ -67,7 +63,10 @@ def portage_func(func, args, exit_status=0): global env f = open('/dev/null', 'wb') fd_pipes = {0:0,1:f.fileno(),2:f.fileno()} - spawn([func] + args.split(), env=env, fd_pipes=fd_pipes) + def pre_exec(): + os.chdir(env["S"]) + spawn([func] + args.split(), env=env, + fd_pipes=fd_pipes, pre_exec=pre_exec) f.close() def create_portage_wrapper(bin): diff --git a/pym/portage/tests/bin/test_dobin.py b/pym/portage/tests/bin/test_dobin.py index b9e9bbb1a..6f50d7aba 100644 --- a/pym/portage/tests/bin/test_dobin.py +++ b/pym/portage/tests/bin/test_dobin.py @@ -1,12 +1,16 @@ # test_dobin.py -- Portage Unit Testing Functionality -# Copyright 2007 Gentoo Foundation +# Copyright 2007-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 from portage.tests.bin.setup_env import BinTestCase, dobin, xexists_in_D class DoBin(BinTestCase): def testDoBin(self): - dobin("does-not-exist", 1) - xexists_in_D("does-not-exist") - xexists_in_D("/bin/does-not-exist") - xexists_in_D("/usr/bin/does-not-exist") + self.init() + try: + dobin("does-not-exist", 1) + xexists_in_D("does-not-exist") + xexists_in_D("/bin/does-not-exist") + xexists_in_D("/usr/bin/does-not-exist") + finally: + self.cleanup() diff --git a/pym/portage/tests/bin/test_dodir.py b/pym/portage/tests/bin/test_dodir.py index c6a71ed86..f4eb9b2ef 100644 --- a/pym/portage/tests/bin/test_dodir.py +++ b/pym/portage/tests/bin/test_dodir.py @@ -1,12 +1,16 @@ # test_dodir.py -- Portage Unit Testing Functionality -# Copyright 2007 Gentoo Foundation +# Copyright 2007-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 from portage.tests.bin.setup_env import BinTestCase, dodir, exists_in_D class DoDir(BinTestCase): def testDoDir(self): - dodir("usr /usr") - exists_in_D("/usr") - dodir("/var/lib/moocow") - exists_in_D("/var/lib/moocow") + self.init() + try: + dodir("usr /usr") + exists_in_D("/usr") + dodir("/var/lib/moocow") + exists_in_D("/var/lib/moocow") + finally: + self.cleanup() -- 2.26.2