summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2007-03-17 08:18:49 +0000
committerMike Frysinger <vapier@gentoo.org>2007-03-17 08:18:49 +0000
commita963892e074b7a623db939f12401583391a323ce (patch)
tree4ff9d36296bdb74f8e1679f31bee545c7c1f14e2
parent40adef3a2457a2150c270c35ad8ee0ff8e1b2a8d (diff)
downloadportage-a963892e074b7a623db939f12401583391a323ce.tar.gz
portage-a963892e074b7a623db939f12401583391a323ce.tar.bz2
portage-a963892e074b7a623db939f12401583391a323ce.zip
start of framework for programs in portage bin
svn path=/main/trunk/; revision=6230
-rw-r--r--pym/portage/tests/bin/__init__.py0
-rw-r--r--pym/portage/tests/bin/setup_env.py65
-rw-r--r--pym/portage/tests/bin/test_dobin.py13
-rw-r--r--pym/portage/tests/bin/test_dodir.py13
4 files changed, 91 insertions, 0 deletions
diff --git a/pym/portage/tests/bin/__init__.py b/pym/portage/tests/bin/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/pym/portage/tests/bin/__init__.py
diff --git a/pym/portage/tests/bin/setup_env.py b/pym/portage/tests/bin/setup_env.py
new file mode 100644
index 000000000..0d9b8bc7f
--- /dev/null
+++ b/pym/portage/tests/bin/setup_env.py
@@ -0,0 +1,65 @@
+# setup_env.py -- Make sure bin subdir has sane env for testing
+# Copyright 2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id: test_dep_getcpv.py 6182 2007-03-06 07:35:22Z antarus $
+
+import os, shutil, sys
+from portage.tests import TestCase
+from portage.process import spawn
+
+bindir = os.path.join(os.getcwd(), "..", "..", "..", "bin")
+basedir = os.path.join(os.getcwd(), "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"]
+
+def binTestsCleanup():
+ if os.access(basedir, os.W_OK):
+ shutil.rmtree(basedir)
+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"])
+
+class BinTestCase(TestCase):
+ def __init__(self, methodName):
+ TestCase.__init__(self, methodName)
+ binTestsInit()
+ def __del__(self):
+ binTestsCleanup()
+
+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)
+def exists_in_D(path):
+ if not _exists_in_D(path):
+ raise TestCase.failureException
+def xexists_in_D(path):
+ if _exists_in_D(path):
+ raise TestCase.failureException
+
+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
+ f = open('/dev/null', 'w')
+ fd_pipes = {0:0,1:f.fileno(),2:f.fileno()}
+ spawn(func+" "+args, env=os.environ, fd_pipes=fd_pipes)
+
+def create_portage_wrapper(bin):
+ def derived_func(*args):
+ newargs = list(args)
+ newargs.insert(0, bin)
+ return portage_func(*newargs)
+ return derived_func
+
+for bin in os.listdir(bindir):
+ if bin.startswith("do") or \
+ bin.startswith("new") or \
+ bin.startswith("prep") or \
+ bin in ["ecompress","ecompressdir","fowners","fperms"]:
+ setattr(sys.modules[__name__], bin, create_portage_wrapper(bin))
diff --git a/pym/portage/tests/bin/test_dobin.py b/pym/portage/tests/bin/test_dobin.py
new file mode 100644
index 000000000..074c8944e
--- /dev/null
+++ b/pym/portage/tests/bin/test_dobin.py
@@ -0,0 +1,13 @@
+# test_dobin.py -- Portage Unit Testing Functionality
+# Copyright 2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id: test_dep_getcpv.py 6182 2007-03-06 07:35:22Z antarus $
+
+from setup_env import *
+
+class DoBin(BinTestCase):
+ def testBasic(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")
diff --git a/pym/portage/tests/bin/test_dodir.py b/pym/portage/tests/bin/test_dodir.py
new file mode 100644
index 000000000..a6ec5e196
--- /dev/null
+++ b/pym/portage/tests/bin/test_dodir.py
@@ -0,0 +1,13 @@
+# test_dodir.py -- Portage Unit Testing Functionality
+# Copyright 2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id: test_dep_getcpv.py 6182 2007-03-06 07:35:22Z antarus $
+
+from setup_env import *
+
+class DoDir(BinTestCase):
+ def testBasic(self):
+ dodir("usr /usr")
+ exists_in_D("/usr")
+ dodir("/var/lib/moocow")
+ exists_in_D("/var/lib/moocow")