DoebuildSpawnTestCase: Invoke portage.package.ebuild.doebuild.spawn()
authorZac Medico <zmedico@gentoo.org>
Sun, 15 Aug 2010 07:07:36 +0000 (00:07 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 15 Aug 2010 07:07:36 +0000 (00:07 -0700)
with a minimal environment. This gives coverage to some of the ebuild
execution internals, like ebuild.sh, EbuildSpawnProcess, and
EbuildIpcDaemon.

bin/ebuild.sh
pym/portage/tests/ebuild/test_doebuild_spawn.py [new file with mode: 0644]

index c8161773b4c256f863cbfaea8996b83af150f2fc..8813bd6d0b8d89023bc3a3dbd28b3a089afb8564 100755 (executable)
@@ -2200,6 +2200,8 @@ ebuild_main() {
                fi
                set +f
                ;;
+       _internal_test)
+               ;;
        *)
                export SANDBOX_ON="1"
                echo "Unrecognized EBUILD_SH_ARGS: '${EBUILD_SH_ARGS}'"
diff --git a/pym/portage/tests/ebuild/test_doebuild_spawn.py b/pym/portage/tests/ebuild/test_doebuild_spawn.py
new file mode 100644 (file)
index 0000000..dd0ddcb
--- /dev/null
@@ -0,0 +1,47 @@
+# Copyright 2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+from portage import os
+from portage import _shell_quote
+from portage.const import EBUILD_SH_BINARY
+from portage.package.ebuild.config import config
+from portage.package.ebuild.doebuild import spawn as doebuild_spawn
+from portage.tests import TestCase
+from portage.tests.resolver.ResolverPlayground import ResolverPlayground
+
+class DoebuildSpawnTestCase(TestCase):
+       """
+       Invoke portage.package.ebuild.doebuild.spawn() with a
+       minimal environment. This gives coverage to some of
+       the ebuild execution internals, like ebuild.sh,
+       EbuildSpawnProcess, and EbuildIpcDaemon.
+       """
+
+       def testDoebuildSpawn(self):
+               playground = ResolverPlayground()
+               try:
+                       settings = config(clone=playground.settings)
+                       cpv = 'sys-apps/portage-2.1'
+                       metadata = {}
+                       settings.setcpv(cpv, mydb=metadata)
+                       settings['PORTAGE_BUILDDIR'] = os.path.join(
+                               settings['PORTAGE_TMPDIR'], cpv)
+                       settings['T'] = os.path.join(
+                               settings['PORTAGE_BUILDDIR'], 'temp')
+                       for x in ('PORTAGE_BUILDDIR', 'T'):
+                               os.makedirs(settings[x])
+                       # Create a fake environment, to pretend as if the ebuild
+                       # has been sourced already.
+                       open(os.path.join(settings['T'], 'environment'), 'wb')
+                       for enable_ipc in (False, True):
+                               if enable_ipc:
+                                       settings['PORTAGE_IPC_DAEMON_ENABLE'] = '1'
+                               else:
+                                       settings.pop('PORTAGE_IPC_DAEMON_ENABLE', None)
+                               for phase in ('_internal_test',):
+                                       rval = doebuild_spawn(
+                                               "%s %s" % (_shell_quote(EBUILD_SH_BINARY), phase),
+                                               settings, free=1)
+                                       self.assertEqual(rval, os.EX_OK)
+               finally:
+                       playground.cleanup()