1 # Copyright 2010-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 from portage import _python_interpreter
6 from portage import _shell_quote
7 from portage.const import EBUILD_SH_BINARY
8 from portage.package.ebuild.config import config
9 from portage.package.ebuild.doebuild import spawn as doebuild_spawn
10 from portage.tests import TestCase
11 from portage.tests.resolver.ResolverPlayground import ResolverPlayground
12 from _emerge.EbuildPhase import EbuildPhase
13 from _emerge.MiscFunctionsProcess import MiscFunctionsProcess
14 from _emerge.Package import Package
15 from _emerge.PollScheduler import PollScheduler
17 class DoebuildSpawnTestCase(TestCase):
19 Invoke portage.package.ebuild.doebuild.spawn() with a
20 minimal environment. This gives coverage to some of
21 the ebuild execution internals, like ebuild.sh,
22 AbstractEbuildProcess, and EbuildIpcDaemon.
25 def testDoebuildSpawn(self):
26 playground = ResolverPlayground()
28 settings = config(clone=playground.settings)
29 cpv = 'sys-apps/portage-2.1'
32 'INHERITED' : 'python eutils',
33 'IUSE' : 'build doc epydoc python3 selinux',
35 'PROVIDE' : 'virtual/portage',
36 'RDEPEND' : '>=app-shells/bash-3.2_p17 >=dev-lang/python-2.6',
39 root_config = playground.trees[playground.eroot]['root_config']
40 pkg = Package(built=False, cpv=cpv, installed=False,
41 metadata=metadata, root_config=root_config,
44 settings['PORTAGE_PYTHON'] = _python_interpreter
45 settings['PORTAGE_BUILDDIR'] = os.path.join(
46 settings['PORTAGE_TMPDIR'], cpv)
47 settings['T'] = os.path.join(
48 settings['PORTAGE_BUILDDIR'], 'temp')
49 for x in ('PORTAGE_BUILDDIR', 'T'):
50 os.makedirs(settings[x])
51 # Create a fake environment, to pretend as if the ebuild
52 # has been sourced already.
53 open(os.path.join(settings['T'], 'environment'), 'wb').close()
55 scheduler = PollScheduler().sched_iface
56 for phase in ('_internal_test',):
58 # Test EbuildSpawnProcess by calling doebuild.spawn() with
59 # returnpid=False. This case is no longer used by portage
60 # internals since EbuildPhase is used instead and that passes
61 # returnpid=True to doebuild.spawn().
62 rval = doebuild_spawn("%s %s" % (_shell_quote(
63 os.path.join(settings["PORTAGE_BIN_PATH"],
64 os.path.basename(EBUILD_SH_BINARY))), phase),
66 self.assertEqual(rval, os.EX_OK)
68 ebuild_phase = EbuildPhase(background=False,
69 phase=phase, scheduler=scheduler,
73 self.assertEqual(ebuild_phase.returncode, os.EX_OK)
75 ebuild_phase = MiscFunctionsProcess(background=False,
76 commands=['success_hooks'],
77 scheduler=scheduler, settings=settings)
80 self.assertEqual(ebuild_phase.returncode, os.EX_OK)