From patchwork Thu Jan 27 18:47:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guilherme Salgado X-Patchwork-Id: 29 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:39:21 -0000 Delivered-To: patches@linaro.org Received: by 10.147.124.10 with SMTP id b10cs17576yan; Thu, 27 Jan 2011 10:47:29 -0800 (PST) Received: by 10.216.168.67 with SMTP id j45mr6546395wel.101.1296154048936; Thu, 27 Jan 2011 10:47:28 -0800 (PST) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id s51si14449129weh.91.2011.01.27.10.47.28; Thu, 27 Jan 2011 10:47:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1PiWsS-0007zK-En for ; Thu, 27 Jan 2011 18:47:28 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 6C70A2E8056 for ; Thu, 27 Jan 2011 18:47:28 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: linaro-image-tools X-Launchpad-Branch: ~linaro-maintainers/linaro-image-tools/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 265 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-maintainers/linaro-image-tools/trunk] Rev 265: Fix install_package_providing() to wait() for its child. Also change MockCmdRunnerPopenFixture to... Message-Id: <20110127184728.28712.8767.launchpad@loganberry.canonical.com> Date: Thu, 27 Jan 2011 18:47:28 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="12263"; Instance="initZopeless config overlay" X-Launchpad-Hash: ff3f251e87f22783ed0fe5c00c931bf28bcfe3f0 Merge authors: Guilherme Salgado (salgado) Related merge proposals: https://code.launchpad.net/~salgado/linaro-image-tools/misc/+merge/47700 proposed by: Guilherme Salgado (salgado) review: Approve - James Westby (james-w) ------------------------------------------------------------ revno: 265 [merge] committer: Guilherme Salgado branch nick: trunk timestamp: Thu 2011-01-27 16:43:55 -0200 message: Fix install_package_providing() to wait() for its child. Also change MockCmdRunnerPopenFixture to assert that any callsite that invokes Popen.__call__() also calls .wait() modified: README linaro_media_create/tests/fixtures.py linaro_media_create/tests/test_media_create.py linaro_media_create/utils.py --- lp:linaro-image-tools https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk You are subscribed to branch lp:linaro-image-tools. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk/+edit-subscription === modified file 'README' --- README 2010-12-10 21:39:04 +0000 +++ README 2011-01-27 17:54:57 +0000 @@ -13,6 +13,8 @@ - dpkg-dev - python-parted - python-dbus + - python-apt + - qemu-kvm And run the following command: === modified file 'linaro_media_create/tests/fixtures.py' --- linaro_media_create/tests/fixtures.py 2011-01-17 17:51:13 +0000 +++ linaro_media_create/tests/fixtures.py 2011-01-27 17:54:57 +0000 @@ -66,7 +66,13 @@ class MockCmdRunnerPopen(object): """A mock for cmd_runner.Popen() which stores the args given to it.""" calls = None + # A variable that is set to False in __call__() and only set back to True + # when wait() is called, to indicate that tht subprocess has finished. Is + # used in tests to make sure all callsites wait for their child. + child_finished = True + def __call__(self, cmd, *args, **kwargs): + self.child_finished = False if self.calls is None: self.calls = [] if isinstance(cmd, basestring): @@ -83,6 +89,7 @@ return '', '' def wait(self): + self.child_finished = True return self.returncode @property @@ -96,11 +103,16 @@ If no mock is given, a MockCmdRunnerPopen instance is used. """ - def __init__(self, mock=None): - if mock is None: - mock = MockCmdRunnerPopen() + def __init__(self): super(MockCmdRunnerPopenFixture, self).__init__( - cmd_runner, 'Popen', mock) + cmd_runner, 'Popen', MockCmdRunnerPopen()) + + def tearDown(self): + super(MockCmdRunnerPopenFixture, self).tearDown() + if not self.mock.child_finished: + raise AssertionError( + "You should call wait() or communicate() to ensure " + "the subprocess is finished before proceeding.") class MockCallableWithPositionalArgs(object): === modified file 'linaro_media_create/tests/test_media_create.py' --- linaro_media_create/tests/test_media_create.py 2011-01-27 17:19:03 +0000 +++ linaro_media_create/tests/test_media_create.py 2011-01-27 18:43:55 +0000 @@ -354,16 +354,17 @@ class TestCmdRunner(TestCaseWithFixtures): def test_run(self): - fixture = MockCmdRunnerPopenFixture() - self.useFixture(fixture) + fixture = self.useFixture(MockCmdRunnerPopenFixture()) proc = cmd_runner.run(['foo', 'bar', 'baz']) + # Call wait or else MockCmdRunnerPopenFixture() raises an + # AssertionError(). + proc.wait() self.assertEqual(0, proc.returncode) self.assertEqual([['foo', 'bar', 'baz']], fixture.mock.calls) def test_run_as_root(self): - fixture = MockCmdRunnerPopenFixture() - self.useFixture(fixture) - cmd_runner.run(['foo', 'bar'], as_root=True) + fixture = self.useFixture(MockCmdRunnerPopenFixture()) + cmd_runner.run(['foo', 'bar'], as_root=True).wait() self.assertEqual([['sudo', 'foo', 'bar']], fixture.mock.calls) def test_run_succeeds_on_zero_return_code(self): === modified file 'linaro_media_create/utils.py' --- linaro_media_create/utils.py 2011-01-18 12:43:13 +0000 +++ linaro_media_create/utils.py 2011-01-27 17:54:57 +0000 @@ -28,7 +28,7 @@ package, _ = packages[0] print ("Installing required command %s from package %s" % (command, package)) - cmd_runner.run(['apt-get', 'install', package], as_root=True) + cmd_runner.run(['apt-get', 'install', package], as_root=True).wait() def ensure_command(command):