Debian Codegraph @

test/unit/utils/sparse_test.py

raw
1 from unittest.mock import patch
2
3 from kiwi.utils.sparse import SparseFile
4
5
6 class TestSparseFile:
7 @patch('kiwi.utils.sparse.Path.which')
8 @patch('kiwi.utils.sparse.Command.run')
9 def test_create_with_qemu_img(self, mock_command_run, mock_which):
10 mock_which.return_value = '/usr/bin/qemu-img'
11 SparseFile.create('disk.raw', '20M')
12 mock_command_run.assert_called_once_with(
13 ['qemu-img', 'create', 'disk.raw', '20M']
14 )
15
16 @patch('kiwi.utils.sparse.Path.which')
17 @patch('kiwi.utils.sparse.Command.run')
18 def test_create_with_dd_fallback(self, mock_command_run, mock_which):
19 mock_which.return_value = None
20 SparseFile.create('disk.raw', '20M')
21 mock_command_run.assert_called_once_with(
22 [
23 'dd', 'if=/dev/null', 'of=disk.raw',
24 'bs=1', 'count=0', 'seek=20M'
25 ]
26 )