Debian Codegraph @

test/unit/shell_test.py

raw
1 from unittest.mock import patch
2
3 from kiwi.system.shell import Shell
4
5 from kiwi.defaults import Defaults
6
7
8 class TestShell:
9 def test_quote(self):
10 assert Shell.quote(r'aa\!') == 'aa\\\\\\!'
11
12 @patch('kiwi.path.Path.which')
13 def test_quote_key_value_file(self, mock_which):
14 mock_which.side_effect = ['cp', 'bash']
15 assert Shell.quote_key_value_file('../data/key_value') == [
16 "foo='bar'",
17 "bar='xxx'",
18 "name='bob'",
19 "strange='$a_foo'"
20 ]
21
22 @patch('kiwi.system.shell.Command.run')
23 def test_run_common_function(self, mock_command):
24 Shell.run_common_function('foo', ['"param1"', '"param2"'])
25 command_string = ' '.join(
26 [
27 'source', Defaults.project_file('config/functions.sh') + ';',
28 'foo', '"param1"', '"param2"'
29 ]
30 )
31 mock_command.assert_called_once_with(
32 ['bash', '-c', command_string]
33 )