summaryrefslogtreecommitdiffstats
path: root/pym/portage/tests/bin
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-09-27 18:01:30 +0000
committerZac Medico <zmedico@gentoo.org>2009-09-27 18:01:30 +0000
commitbd8c156409e558fd86d7884670575295188a181d (patch)
tree55f3c2b32c88364c6d581aa4cfd097e64a6eb650 /pym/portage/tests/bin
parent7a6a2598c417b0079036a37e3203d3451bb49654 (diff)
downloadportage-bd8c156409e558fd86d7884670575295188a181d.tar.gz
portage-bd8c156409e558fd86d7884670575295188a181d.tar.bz2
portage-bd8c156409e558fd86d7884670575295188a181d.zip
Use mkdtemp() instead of hardcoded pym/portage/tests/bin/root directory.
svn path=/main/trunk/; revision=14445
Diffstat (limited to 'pym/portage/tests/bin')
-rw-r--r--pym/portage/tests/bin/setup_env.py42
1 files changed, 26 insertions, 16 deletions
diff --git a/pym/portage/tests/bin/setup_env.py b/pym/portage/tests/bin/setup_env.py
index aab210ee9..086bcd5f5 100644
--- a/pym/portage/tests/bin/setup_env.py
+++ b/pym/portage/tests/bin/setup_env.py
@@ -3,6 +3,8 @@
# Distributed under the terms of the GNU General Public License v2
# $Id$
+import tempfile
+
from portage import os
from portage import shutil
from portage.tests import TestCase
@@ -12,25 +14,32 @@ from portage.const import PORTAGE_BIN_PATH
bindir = os.path.join(os.path.dirname(os.path.dirname(
os.path.abspath(__file__))),
"..", "..", "..", "bin", "ebuild-helpers")
-basedir = os.path.join(os.path.dirname(os.path.dirname(
- os.path.abspath(__file__))), "bin", "root")
-os.environ["D"] = os.path.join(basedir, "image")
-os.environ["T"] = os.path.join(basedir, "temp")
-os.environ["S"] = os.path.join(basedir, "workdir")
-os.environ["PF"] = "portage-tests-0.09-r1"
-os.environ["PATH"] = bindir + ":" + os.environ["PATH"]
-os.environ["PORTAGE_BIN_PATH"] = PORTAGE_BIN_PATH
+basedir = None
+env = None
def binTestsCleanup():
+ global basedir
+ if basedir is None:
+ return
if os.access(basedir, os.W_OK):
shutil.rmtree(basedir)
+ basedir = None
+
def binTestsInit():
binTestsCleanup()
- os.mkdir(basedir)
- os.mkdir(os.environ["D"])
- os.mkdir(os.environ["T"])
- os.mkdir(os.environ["S"])
- os.chdir(os.environ["S"])
+ global basedir, env
+ basedir = tempfile.mkdtemp()
+ env = os.environ.copy()
+ env["D"] = os.path.join(basedir, "image")
+ env["T"] = os.path.join(basedir, "temp")
+ env["S"] = os.path.join(basedir, "workdir")
+ env["PF"] = "portage-tests-0.09-r1"
+ env["PATH"] = bindir + ":" + env["PATH"]
+ env["PORTAGE_BIN_PATH"] = PORTAGE_BIN_PATH
+ os.mkdir(env["D"])
+ os.mkdir(env["T"])
+ os.mkdir(env["S"])
+ os.chdir(env["S"])
class BinTestCase(TestCase):
def __init__(self, methodName):
@@ -43,7 +52,7 @@ class BinTestCase(TestCase):
def _exists_in_D(path):
# Note: do not use os.path.join() here, we assume D to end in /
- return os.access(os.environ["D"] + path, os.W_OK)
+ return os.access(env["D"] + path, os.W_OK)
def exists_in_D(path):
if not _exists_in_D(path):
raise TestCase.failureException
@@ -54,9 +63,10 @@ def xexists_in_D(path):
def portage_func(func, args, exit_status=0):
# we don't care about the output of the programs,
# just their exit value and the state of $D
+ global env
f = open('/dev/null', 'wb')
fd_pipes = {0:0,1:f.fileno(),2:f.fileno()}
- spawn(func+" "+args, env=os.environ, fd_pipes=fd_pipes)
+ spawn([func] + args.split(), env=env, fd_pipes=fd_pipes)
f.close()
def create_portage_wrapper(bin):
@@ -71,4 +81,4 @@ for bin in os.listdir(bindir):
bin.startswith("new") or \
bin.startswith("prep") or \
bin in ["ecompress","ecompressdir","fowners","fperms"]:
- globals()[bin] = create_portage_wrapper(bin)
+ globals()[bin] = create_portage_wrapper(os.path.join(bindir, bin))