=== modified file 'linaro_media_create/tests/test_media_create.py'
@@ -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)