diff mbox

[Branch,~linaro-maintainers/linaro-image-tools/trunk] Rev 285: Factor the prefer_dir computation which had to be repeated in the previous

Message ID 20110202174053.10088.40370.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

Loïc Minier Feb. 2, 2011, 5:40 p.m. UTC
------------------------------------------------------------
revno: 285
committer: Loïc Minier <lool@dooz.org>
branch nick: linaro-image-tools
timestamp: Wed 2011-02-02 18:38:16 +0100
message:
  Factor the prefer_dir computation which had to be repeated in the previous
  merge.
modified:
  linaro_media_create/tests/test_media_create.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
diff mbox

Patch

=== modified file 'linaro_media_create/tests/test_media_create.py'
--- linaro_media_create/tests/test_media_create.py	2011-02-02 17:32:10 +0000
+++ linaro_media_create/tests/test_media_create.py	2011-02-02 17:38:16 +0000
@@ -97,6 +97,14 @@ 
     )
 
 
+def preferred_tools_dir():
+    prefer_dir = None
+    # running from bzr checkout?
+    if not os.path.isabs(__file__):
+        prefer_dir = os.getcwd()
+    return prefer_dir
+
+
 class TestEnsureCommand(TestCaseWithFixtures):
 
     install_pkg_providing_called = False
@@ -135,14 +143,14 @@ 
 
     def test_existing_command(self):
         lmc = 'linaro-media-create'
-        # running from bzr checkout?
-        if os.path.isabs(__file__):
+        prefer_dir = preferred_tools_dir()
+        if prefer_dir is None:
             expected, _ = cmd_runner.run(
                 ['which', lmc, ],
                 stdout=subprocess.PIPE).communicate()
             expected = expected.strip()
         else:
-            expected = os.path.join(os.getcwd(), lmc)
+            expected = os.path.join(prefer_dir, lmc)
         self.assertEquals(expected, find_command(lmc))
 
     def test_nonexisting_command(self):
@@ -1112,10 +1120,7 @@ 
         fixture = self.useFixture(MockCmdRunnerPopenFixture())
         force_yes = True
 
-        prefer_dir = None
-        # running from bzr checkout?
-        if not os.path.isabs(__file__):
-            prefer_dir = os.getcwd()
+        prefer_dir = preferred_tools_dir()
 
         install_hwpacks(
             'chroot', '/tmp/dir', prefer_dir, force_yes, 'hwpack1.tgz',
@@ -1188,17 +1193,12 @@ 
             linaro_media_create.hwpack, 'run_local_atexit_funcs',
             mock_run_local_atexit_functions))
 
-        prefer_dir = None
-        # running from bzr checkout?
-        if not os.path.isabs(__file__):
-            prefer_dir = os.getcwd()
-
         force_yes = True
         exception_caught = False
         try:
             install_hwpacks(
-                'chroot', '/tmp/dir', prefer_dir, force_yes, 'hwp.tgz',
-                'hwp2.tgz')
+                'chroot', '/tmp/dir', preferred_tools_dir(), force_yes,
+                'hwp.tgz', 'hwp2.tgz')
         except:
             exception_caught = True
         self.assertTrue(self.run_local_atexit_functions_called)