commit: a9aea5f9a055e6a38acfbaa1b6190d0c627cb299 Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Sat Dec 20 21:08:35 2014 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Sun Jan 18 18:39:12 2015 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=a9aea5f9
TestFakedbapi: override EPREFIX for bug #492932 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 Acked-by: Brian Dolbec <dolsen <AT> gentoo.org> --- pym/portage/tests/dbapi/test_fakedbapi.py | 11 ++++++++++- pym/portage/tests/resolver/ResolverPlayground.py | 8 +++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pym/portage/tests/dbapi/test_fakedbapi.py b/pym/portage/tests/dbapi/test_fakedbapi.py index 7713563..e4f5dd7 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-2015 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..b5c0446 100644 --- a/pym/portage/tests/resolver/ResolverPlayground.py +++ b/pym/portage/tests/resolver/ResolverPlayground.py @@ -1,4 +1,4 @@ -# Copyright 2010-2014 Gentoo Foundation +# Copyright 2010-2015 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 from itertools import permutations @@ -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