kiwi-el8/test/unit/system/size_test.py
Alexandre Detiste fb69627ad3
Use unittest.mock from core python everywhere
mock was an independent module that has been merged into the Python standard library.
2024-02-18 22:15:30 +01:00

46 lines
1.4 KiB
Python

from unittest.mock import patch
import unittest.mock as mock
from kiwi.system.size import SystemSize
class TestSystemSize:
def setup(self):
self.size = SystemSize('directory')
def setup_method(self, cls):
self.setup()
def test_customize_ext(self):
self.size.accumulate_files = mock.Mock(
return_value=10000
)
assert self.size.customize(42, 'ext3') == 67
def test_customize_btrfs(self):
assert self.size.customize(42, 'btrfs') == 63
def test_customize_xfs(self):
assert self.size.customize(42, 'xfs') == 63
@patch('kiwi.system.size.Command.run')
def test_accumulate_mbyte_file_sizes(self, mock_command):
assert isinstance(self.size.accumulate_mbyte_file_sizes(['/foo']), int)
mock_command.assert_called_once_with(
[
'du', '-s', '--apparent-size', '--block-size', '1',
'--exclude', 'directory/proc',
'--exclude', 'directory/sys',
'--exclude', 'directory/dev',
'--exclude', '/foo', 'directory'
]
)
@patch('kiwi.system.size.Command.run')
def test_accumulate_files(self, mock_command):
assert isinstance(self.size.accumulate_files(), int)
mock_command.assert_called_once_with(
['bash', '-c', 'find directory | wc -l']
)