Fix BinTestCase instances to stop leaving orphan temp dirs.
authorZac Medico <zmedico@gentoo.org>
Fri, 20 Aug 2010 04:52:58 +0000 (21:52 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 20 Aug 2010 04:52:58 +0000 (21:52 -0700)
pym/portage/tests/bin/setup_env.py
pym/portage/tests/bin/test_dobin.py
pym/portage/tests/bin/test_dodir.py

index a73e2ddc886ae053da0fa144a0c2bbca4f89a1a5..e07643de5e4d75a53079c14e4e205f881fc14335 100644 (file)
@@ -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):
index b9e9bbb1a834c0cad5e27e8b1b1096f75ed94c8b..6f50d7aba8857c181787869ace120977e1bb4995 100644 (file)
@@ -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()
index c6a71ed86b03f10bd322ba72491ad6bdb8fd29dd..f4eb9b2eff25c0dfd9bc6cabf18d05af12caba04 100644 (file)
@@ -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()