public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH] TestFakedbapi: override EPREFIX for bug #492932
@ 2014-12-20 21:11 Zac Medico
  2015-01-17 19:16 ` [gentoo-portage-dev] " Zac Medico
  0 siblings, 1 reply; 3+ messages in thread
From: Zac Medico @ 2014-12-20 21:11 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico

For tests, override portage.const.EPREFIX in order to avoid unwanted
access to /etc/portage. This override may seem evil, but it is a
convenient way to simulate a prefix install, and it is reasonable to do
this because tests should be self-contained such that the "real" value
of portage.const.EPREFIX is entirely irrelevant.

X-Gentoo-Bug: 492932
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=492932
---
 pym/portage/tests/dbapi/test_fakedbapi.py        | 11 ++++++++++-
 pym/portage/tests/resolver/ResolverPlayground.py |  6 ++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/pym/portage/tests/dbapi/test_fakedbapi.py b/pym/portage/tests/dbapi/test_fakedbapi.py
index 7713563..4f718e0 100644
--- a/pym/portage/tests/dbapi/test_fakedbapi.py
+++ b/pym/portage/tests/dbapi/test_fakedbapi.py
@@ -1,8 +1,9 @@
-# Copyright 2011-2013 Gentoo Foundation
+# Copyright 2011-2014 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import tempfile
 
+import portage
 from portage import os
 from portage import shutil
 from portage.dbapi.virtual import fakedbapi
@@ -49,6 +50,14 @@ class TestFakedbapi(TestCase):
 			env = {
 				"PORTAGE_REPOSITORIES": "[DEFAULT]\nmain-repo = test_repo\n[test_repo]\nlocation = %s" % test_repo
 			}
+
+			# Tests may override portage.const.EPREFIX in order to
+			# simulate a prefix installation. It's reasonable to do
+			# this because tests should be self-contained such that
+			# the "real" value of portage.const.EPREFIX is entirely
+			# irrelevant (see bug #492932).
+			portage.const.EPREFIX = tempdir
+
 			fakedb = fakedbapi(settings=config(config_profile_path="",
 				env=env, eprefix=tempdir))
 			for cpv, metadata in packages:
diff --git a/pym/portage/tests/resolver/ResolverPlayground.py b/pym/portage/tests/resolver/ResolverPlayground.py
index 0be5d81..fb6a951 100644
--- a/pym/portage/tests/resolver/ResolverPlayground.py
+++ b/pym/portage/tests/resolver/ResolverPlayground.py
@@ -72,6 +72,12 @@ class ResolverPlayground(object):
 			self.eprefix = normalize_path(tempfile.mkdtemp())
 		else:
 			self.eprefix = normalize_path(eprefix)
+
+		# Tests may override portage.const.EPREFIX in order to
+		# simulate a prefix installation. It's reasonable to do
+		# this because tests should be self-contained such that
+		# the "real" value of portage.const.EPREFIX is entirely
+		# irrelevant (see bug #492932).
 		portage.const.EPREFIX = self.eprefix.rstrip(os.sep)
 
 		self.eroot = self.eprefix + os.sep
-- 
2.0.4



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-portage-dev] Re: [PATCH] TestFakedbapi: override EPREFIX for bug #492932
  2014-12-20 21:11 [gentoo-portage-dev] [PATCH] TestFakedbapi: override EPREFIX for bug #492932 Zac Medico
@ 2015-01-17 19:16 ` Zac Medico
  2015-01-18 16:54   ` Brian Dolbec
  0 siblings, 1 reply; 3+ messages in thread
From: Zac Medico @ 2015-01-17 19:16 UTC (permalink / raw
  To: gentoo-portage-dev

On 12/20/2014 01:11 PM, Zac Medico wrote:
> For tests, override portage.const.EPREFIX in order to avoid unwanted
> access to /etc/portage. This override may seem evil, but it is a
> convenient way to simulate a prefix install, and it is reasonable to do
> this because tests should be self-contained such that the "real" value
> of portage.const.EPREFIX is entirely irrelevant.

Any feedback on this? I think it's good to merge.

I know it's ugly, but it's simple and it works. Maybe we'll come up with
something fancier later on.
-- 
Thanks,
Zac


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gentoo-portage-dev] Re: [PATCH] TestFakedbapi: override EPREFIX for bug #492932
  2015-01-17 19:16 ` [gentoo-portage-dev] " Zac Medico
@ 2015-01-18 16:54   ` Brian Dolbec
  0 siblings, 0 replies; 3+ messages in thread
From: Brian Dolbec @ 2015-01-18 16:54 UTC (permalink / raw
  To: gentoo-portage-dev

On Sat, 17 Jan 2015 11:16:10 -0800
Zac Medico <zmedico@gentoo.org> wrote:

> On 12/20/2014 01:11 PM, Zac Medico wrote:
> > For tests, override portage.const.EPREFIX in order to avoid unwanted
> > access to /etc/portage. This override may seem evil, but it is a
> > convenient way to simulate a prefix install, and it is reasonable
> > to do this because tests should be self-contained such that the
> > "real" value of portage.const.EPREFIX is entirely irrelevant.
> 
> Any feedback on this? I think it's good to merge.
> 
> I know it's ugly, but it's simple and it works. Maybe we'll come up
> with something fancier later on.

I didn't think it was "ugly", 2 lines of code and some comments...

yes, merge please

-- 
Brian Dolbec <dolsen>



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-01-18 16:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-20 21:11 [gentoo-portage-dev] [PATCH] TestFakedbapi: override EPREFIX for bug #492932 Zac Medico
2015-01-17 19:16 ` [gentoo-portage-dev] " Zac Medico
2015-01-18 16:54   ` Brian Dolbec

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