Debian Codegraph @

test/unit/utils/block_test.py

raw
1 from unittest.mock import (
2 Mock, patch
3 )
4
5 from kiwi.utils.block import BlockID
6
7
8 class TestBlockID:
9 def setup(self):
10 self.blkid = BlockID('device')
11
12 def setup_method(self, cls):
13 self.setup()
14
15 @patch('kiwi.utils.block.Command.run')
16 def test_setup_with_uuid_format(self, mock_command):
17 BlockID('UUID=uuid')
18 mock_command.assert_called_once_with(
19 ['blkid', '--uuid', 'uuid']
20 )
21
22 @patch('kiwi.utils.block.Command.run')
23 def test_get_blkid(self, mock_command):
24 self.blkid.get_blkid('LABEL')
25 mock_command.assert_called_once_with(
26 ['blkid', 'device', '-s', 'LABEL', '-o', 'value'],
27 raise_on_error=False
28 )
29
30 @patch('kiwi.utils.block.BlockID.get_blkid')
31 def test_get_filesystem(self, mock_get_blkid):
32 self.blkid.get_filesystem()
33 mock_get_blkid.assert_called_once_with('TYPE')
34
35 @patch('kiwi.utils.block.BlockID.get_blkid')
36 def test_get_label(self, mock_get_blkid):
37 self.blkid.get_label()
38 mock_get_blkid.assert_called_once_with('LABEL')
39
40 @patch('kiwi.utils.block.BlockID.get_blkid')
41 def test_get_uuid(self, mock_get_blkid):
42 self.blkid.get_uuid()
43 mock_get_blkid.assert_called_once_with('UUID')
44
45 @patch('kiwi.utils.block.BlockID.get_blkid')
46 def test_get_ptuuid(self, mock_get_blkid):
47 self.blkid.get_ptuuid()
48 mock_get_blkid.assert_called_once_with('PTUUID')
49
50 @patch('kiwi.utils.block.Command.run')
51 def test_get_partition_count(self, mock_Command_run):
52 lsblk_call = Mock()
53 lsblk_call.output = "NAME TYPE\nsda disk\nsda4 part \nsda3 part"
54 mock_Command_run.return_value = lsblk_call
55 assert self.blkid.get_partition_count() == 2