=== modified file 'README'
@@ -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'
@@ -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'
@@ -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'
@@ -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):