File: shell_test.py

package info (click to toggle)
kiwi 10.2.33-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,528 kB
  • sloc: python: 67,299; sh: 3,980; xml: 3,379; ansic: 391; makefile: 354
file content (33 lines) | stat: -rw-r--r-- 985 bytes parent folder | download
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
from unittest.mock import patch

from kiwi.system.shell import Shell

from kiwi.defaults import Defaults


class TestShell:
    def test_quote(self):
        assert Shell.quote(r'aa\!') == 'aa\\\\\\!'

    @patch('kiwi.path.Path.which')
    def test_quote_key_value_file(self, mock_which):
        mock_which.side_effect = ['cp', 'bash']
        assert Shell.quote_key_value_file('../data/key_value') == [
            "foo='bar'",
            "bar='xxx'",
            "name='bob'",
            "strange='$a_foo'"
        ]

    @patch('kiwi.system.shell.Command.run')
    def test_run_common_function(self, mock_command):
        Shell.run_common_function('foo', ['"param1"', '"param2"'])
        command_string = ' '.join(
            [
                'source', Defaults.project_file('config/functions.sh') + ';',
                'foo', '"param1"', '"param2"'
            ]
        )
        mock_command.assert_called_once_with(
            ['bash', '-c', command_string]
        )