public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/emerge/, pym/portage/
@ 2011-08-29  6:58 Zac Medico
  0 siblings, 0 replies; only message in thread
From: Zac Medico @ 2011-08-29  6:58 UTC (permalink / raw
  To: gentoo-commits

commit:     0891a5f671527f99fa1e9ca56ea96e5566abd52f
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 29 06:50:16 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Aug 29 06:50:16 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=0891a5f6

emerge: add simple unit tests

These tests are similar to the repoman tests, using a
__PORTAGE_TEST_EPREFIX environment variable to make emerge confine
itself to a testing prefix so that things like install and uninstall
operations can be performed.

---
 pym/portage/__init__.py                 |    6 +-
 pym/portage/data.py                     |    3 +
 pym/portage/tests/emerge/__init__.py    |    2 +
 pym/portage/tests/emerge/test_simple.py |  139 +++++++++++++++++++++++++++++++
 4 files changed, 148 insertions(+), 2 deletions(-)

diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 78d9b54..72cdf2d 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -472,8 +472,9 @@ def create_trees(config_root=None, target_root=None, trees=None):
 			portdbapi.portdbapi_instances.remove(portdb)
 			del trees[myroot]["porttree"], myroot, portdb
 
+	eprefix = os.environ.get("__PORTAGE_TEST_EPREFIX")
 	settings = config(config_root=config_root, target_root=target_root,
-		config_incrementals=portage.const.INCREMENTALS)
+		config_incrementals=portage.const.INCREMENTALS, _eprefix=eprefix)
 	settings.lock()
 
 	myroots = [(settings["ROOT"], settings)]
@@ -489,7 +490,8 @@ def create_trees(config_root=None, target_root=None, trees=None):
 			v = settings.get(k)
 			if v is not None:
 				clean_env[k] = v
-		settings = config(config_root=None, target_root="/", env=clean_env)
+		settings = config(config_root=None, target_root="/",
+			env=clean_env, _eprefix=eprefix)
 		settings.lock()
 		myroots.append((settings["ROOT"], settings))
 

diff --git a/pym/portage/data.py b/pym/portage/data.py
index c38fa17..c496c0b 100644
--- a/pym/portage/data.py
+++ b/pym/portage/data.py
@@ -65,6 +65,9 @@ wheelgid=0
 
 if uid==0:
 	secpass=2
+elif "__PORTAGE_TEST_EPREFIX" in os.environ:
+	secpass = 2
+
 try:
 	wheelgid=grp.getgrnam("wheel")[2]
 except KeyError:

diff --git a/pym/portage/tests/emerge/__init__.py b/pym/portage/tests/emerge/__init__.py
new file mode 100644
index 0000000..532918b
--- /dev/null
+++ b/pym/portage/tests/emerge/__init__.py
@@ -0,0 +1,2 @@
+# Copyright 2011 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2

diff --git a/pym/portage/tests/emerge/__test__ b/pym/portage/tests/emerge/__test__
new file mode 100644
index 0000000..e69de29

diff --git a/pym/portage/tests/emerge/test_simple.py b/pym/portage/tests/emerge/test_simple.py
new file mode 100644
index 0000000..a13d0e6
--- /dev/null
+++ b/pym/portage/tests/emerge/test_simple.py
@@ -0,0 +1,139 @@
+# Copyright 2011 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import subprocess
+import sys
+
+import portage
+from portage import os
+from portage import _unicode_decode
+from portage.const import PORTAGE_BIN_PATH, PORTAGE_PYM_PATH
+from portage.process import find_binary
+from portage.tests import TestCase
+from portage.tests.resolver.ResolverPlayground import ResolverPlayground
+from portage.util import ensure_dirs
+
+class SimpleEmergeTestCase(TestCase):
+
+	def testSimple(self):
+
+		ebuilds = {
+			"dev-libs/A-1": {
+				"EAPI" : "4",
+				"IUSE" : "+flag",
+				"KEYWORDS": "x86",
+				"LICENSE": "GPL-2",
+				"RDEPEND": "flag? ( dev-libs/B[flag] )",
+			},
+			"dev-libs/B-1": {
+				"EAPI" : "4",
+				"IUSE" : "+flag",
+				"KEYWORDS": "x86",
+				"LICENSE": "GPL-2",
+			},
+		}
+
+		installed = {
+			"dev-libs/A-1": {
+				"EAPI" : "4",
+				"IUSE" : "+flag",
+				"KEYWORDS": "x86",
+				"LICENSE": "GPL-2",
+				"RDEPEND": "flag? ( dev-libs/B[flag] )",
+			},
+			"dev-libs/B-1": {
+				"EAPI" : "4",
+				"IUSE" : "+flag",
+				"KEYWORDS": "x86",
+				"LICENSE": "GPL-2",
+			},
+		}
+
+		default_args = ("--package-moves=n",)
+		test_args = (
+			("--version",),
+			("--info",),
+			("--info", "--verbose"),
+			("--pretend", "dev-libs/A"),
+			("--pretend", "--tree", "--complete-graph", "dev-libs/A"),
+			("-p", "dev-libs/B"),
+			("--oneshot", "dev-libs/A",),
+			("--noreplace", "dev-libs/A",),
+			("--pretend", "--depclean", "--verbose", "dev-libs/B"),
+			("--pretend", "--depclean",),
+			("--depclean",),
+			("--unmerge", "--quiet", "dev-libs/A"),
+			("-C", "--quiet", "dev-libs/B"),
+		)
+
+		playground = ResolverPlayground(ebuilds=ebuilds, installed=installed)
+		settings = playground.settings
+		eprefix = settings["EPREFIX"]
+		distdir = os.path.join(eprefix, "distdir")
+		fake_bin = os.path.join(eprefix, "bin")
+		portage_tmpdir = os.path.join(eprefix, "var", "tmp", "portage")
+		profile_path = settings.profile_path
+		var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
+		env = os.environ.copy()
+
+		path = env.get("PATH")
+		if path is not None and not path.strip():
+			path = None
+		if path is None:
+			path = ""
+		else:
+			path = ":" + path
+		path = fake_bin + path
+
+		pythonpath = env.get("PYTHONPATH")
+		if pythonpath is not None and not pythonpath.strip():
+			pythonpath = None
+		if pythonpath is not None and \
+			pythonpath.startswith(PORTAGE_PYM_PATH + ":"):
+			pass
+		else:
+			if pythonpath is None:
+				pythonpath = ""
+			else:
+				pythonpath = ":" + pythonpath
+			pythonpath = PORTAGE_PYM_PATH + pythonpath
+
+		env['PYTHONPATH'] = pythonpath
+		env.update({
+			"__PORTAGE_TEST_EPREFIX" : eprefix,
+			"DISTDIR" : distdir,
+			"INFODIR" : "",
+			"INFOPATH" : "",
+			"PATH" : path,
+			"PORTAGE_TMPDIR" : portage_tmpdir,
+		})
+		dirs = [distdir, fake_bin, portage_tmpdir, var_cache_edb]
+		true_symlinks = ["chown", "chgrp"]
+		true_binary = find_binary("true")
+		self.assertEqual(true_binary is None, False,
+			"true command not found")
+		try:
+			for d in dirs:
+				ensure_dirs(d)
+			for x in true_symlinks:
+				os.symlink(true_binary, os.path.join(fake_bin, x))
+			with open(os.path.join(var_cache_edb, "counter"), 'wb') as f:
+				f.write(b"100")
+			# non-empty system set keeps --depclean quiet
+			with open(os.path.join(profile_path, "packages"), 'w') as f:
+				f.write("*dev-libs/token-system-pkg")
+			for args in test_args:
+				proc = subprocess.Popen([portage._python_interpreter, "-Wd",
+					os.path.join(PORTAGE_BIN_PATH, "emerge")] + \
+					list(default_args) + list(args),
+					env=env, stdout=subprocess.PIPE)
+				output = proc.stdout.readlines()
+				proc.wait()
+				proc.stdout.close()
+				if proc.returncode != os.EX_OK:
+					for line in output:
+						sys.stderr.write(_unicode_decode(line))
+
+				self.assertEqual(os.EX_OK, proc.returncode, "emerge failed")
+		finally:
+			playground.cleanup()



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-08-29  6:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-29  6:58 [gentoo-commits] proj/portage:master commit in: pym/portage/tests/emerge/, pym/portage/ Zac Medico

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox