# 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
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 /
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):
# 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()
# 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()