From patchwork Tue Nov 15 08:09:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattias Backman X-Patchwork-Id: 5141 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 549EF23EF6 for ; Tue, 15 Nov 2011 08:09:15 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id 43165A1820A for ; Tue, 15 Nov 2011 08:09:15 +0000 (UTC) Received: by faaa26 with SMTP id a26so148483faa.11 for ; Tue, 15 Nov 2011 00:09:15 -0800 (PST) Received: by 10.152.162.10 with SMTP id xw10mr16242107lab.12.1321344554874; Tue, 15 Nov 2011 00:09:14 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.41.198 with SMTP id h6cs29387lal; Tue, 15 Nov 2011 00:09:14 -0800 (PST) Received: by 10.227.198.77 with SMTP id en13mr17144758wbb.28.1321344553318; Tue, 15 Nov 2011 00:09:13 -0800 (PST) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id ev7si11862605wbb.98.2011.11.15.00.09.13 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 15 Nov 2011 00:09:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1RQE4u-0005G1-PS for ; Tue, 15 Nov 2011 08:09:12 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id B5418E15A1 for ; Tue, 15 Nov 2011 08:09:12 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: linaro-image-tools X-Launchpad-Branch: ~linaro-image-tools/linaro-image-tools/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 459 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-image-tools/linaro-image-tools/trunk] Rev 459: Fix unit tests so they don't execute commands using sudo. Message-Id: <20111115080912.14609.70826.launchpad@ackee.canonical.com> Date: Tue, 15 Nov 2011 08:09:12 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14291"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 84c2c5922248eda486a220f054b4a75754eea50b Merge authors: Mattias Backman (mabac) Related merge proposals: https://code.launchpad.net/~mabac/linaro-image-tools/bug-888694-fix-sudo-tests/+merge/82155 proposed by: Mattias Backman (mabac) review: Approve - Guilherme Salgado (salgado) ------------------------------------------------------------ revno: 459 [merge] committer: Mattias Backman branch nick: linaro-image-tools timestamp: Tue 2011-11-15 09:07:46 +0100 message: Fix unit tests so they don't execute commands using sudo. modified: linaro_image_tools/media_create/tests/test_media_create.py --- lp:linaro-image-tools https://code.launchpad.net/~linaro-image-tools/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-image-tools/linaro-image-tools/trunk/+edit-subscription === modified file 'linaro_image_tools/media_create/tests/test_media_create.py' --- linaro_image_tools/media_create/tests/test_media_create.py 2011-11-14 15:14:29 +0000 +++ linaro_image_tools/media_create/tests/test_media_create.py 2011-11-15 08:07:46 +0000 @@ -2402,7 +2402,17 @@ self.assertFalse( has_space_left_for_swap('/', swap_size_in_megs)) + def mock_write_data_to_protected_file(self, path, data): + # Duplicate of write_data_to_protected_file() but does not sudo. + _, tmpfile = tempfile.mkstemp() + with open(tmpfile, 'w') as fd: + fd.write(data) + cmd_runner.run(['mv', '-f', tmpfile, path], as_root=False).wait() + def test_update_interfaces_no_interfaces_no_update(self): + self.useFixture(MockSomethingFixture( + rootfs, 'write_data_to_protected_file', + self.mock_write_data_to_protected_file)) tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir() os.makedirs(os.path.join(tempdir, 'etc', 'network')) if_path = os.path.join(tempdir, 'etc', 'network', 'interfaces') @@ -2413,6 +2423,9 @@ self.assertFalse(os.path.exists(if_path)) def test_update_interfaces_creates_entry(self): + self.useFixture(MockSomethingFixture( + rootfs, 'write_data_to_protected_file', + self.mock_write_data_to_protected_file)) tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir() os.makedirs(os.path.join(tempdir, 'etc', 'network')) if_path = os.path.join(tempdir, 'etc', 'network', 'interfaces') @@ -2425,6 +2438,9 @@ self.assertEqual(expected, open(if_path).read()) def test_update_interfaces_creates_entries(self): + self.useFixture(MockSomethingFixture( + rootfs, 'write_data_to_protected_file', + self.mock_write_data_to_protected_file)) tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir() os.makedirs(os.path.join(tempdir, 'etc', 'network')) if_path = os.path.join(tempdir, 'etc', 'network', 'interfaces') @@ -2441,6 +2457,9 @@ self.assertIn(expected % {'if': 'wlan0'}, open(if_path).read()) def test_update_interfaces_leaves_original(self): + self.useFixture(MockSomethingFixture( + rootfs, 'write_data_to_protected_file', + self.mock_write_data_to_protected_file)) tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir() os.makedirs(os.path.join(tempdir, 'etc', 'network')) if_path = os.path.join(tempdir, 'etc', 'network', 'interfaces')