File: setup_test.py

package info (click to toggle)
kiwi 10.2.41-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 7,592 kB
  • sloc: python: 69,585; sh: 4,230; xml: 3,386; ansic: 391; makefile: 360
file content (70 lines) | stat: -rw-r--r-- 2,212 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import logging
from unittest.mock import patch
from pytest import fixture
import unittest.mock as mock

from kiwi.filesystem.setup import FileSystemSetup


class TestFileSystemSetup:
    @fixture(autouse=True)
    def inject_fixtures(self, caplog):
        self._caplog = caplog

    @patch('kiwi.filesystem.setup.SystemSize')
    def setup(self, mock_size):
        size = mock.Mock()
        size.accumulate_mbyte_file_sizes = mock.Mock(
            return_value=42
        )
        size.customize = mock.Mock(
            return_value=42
        )
        mock_size.return_value = size
        self.xml_state = mock.Mock()
        self.xml_state.get_build_type_name = mock.Mock(
            return_value='ext4'
        )
        self.xml_state.get_build_type_unpartitioned_bytes = mock.Mock(
            return_value=0
        )
        self.setup = FileSystemSetup(
            self.xml_state, 'root_dir'
        )

    @patch('kiwi.filesystem.setup.SystemSize')
    def setup_method(self, cls, mock_size):
        self.setup()

    def test_init_with_unpartitioned(self):
        self.xml_state.get_build_type_unpartitioned_bytes = mock.Mock(
            return_value=1024
        )
        FileSystemSetup(self.xml_state, 'root_dir')

    def test_setup_with_pxe_type(self):
        self.xml_state.get_build_type_name = mock.Mock(
            return_value='pxe'
        )
        self.xml_state.build_type.get_filesystem = mock.Mock(
            return_value='xfs'
        )
        setup = FileSystemSetup(
            self.xml_state, 'root_dir'
        )
        assert setup.requested_filesystem == 'xfs'

    def test_get_size_mbytes_calculated(self):
        self.setup.configured_size = None
        assert self.setup.get_size_mbytes() == 42

    def test_get_size_mbytes_configured_additive(self):
        self.setup.configured_size.mbytes = 20
        self.setup.configured_size.additive = True
        assert self.setup.get_size_mbytes() == 62

    def test_get_size_mbytes_configured(self):
        self.setup.configured_size.mbytes = 3
        self.setup.configured_size.additive = False
        with self._caplog.at_level(logging.WARNING):
            assert self.setup.get_size_mbytes() == 3