summaryrefslogtreecommitdiff
path: root/cliff/tests/test_formatters_shell.py
blob: e6813e5425bd5f6bd53fb3fdb91ec92fe833de4a (plain)
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
#!/usr/bin/env python
from six import StringIO, text_type

from cliff.formatters import shell

import mock


def test_shell_formatter():
    sf = shell.ShellFormatter()
    c = ('a', 'b', 'c', 'd')
    d = ('A', 'B', 'C', '"escape me"')
    expected = 'a="A"\nb="B"\nd="\\"escape me\\""\n'
    output = StringIO()
    args = mock.Mock()
    args.variables = ['a', 'b', 'd']
    args.prefix = ''
    sf.emit_one(c, d, output, args)
    actual = output.getvalue()
    assert expected == actual


def test_shell_formatter_with_non_string_values():
    sf = shell.ShellFormatter()
    c = ('a', 'b', 'c', 'd', 'e')
    d = (True, False, 100, '"esc"', text_type('"esc"'))
    expected = 'a="True"\nb="False"\nc="100"\nd="\\"esc\\""\ne="\\"esc\\""\n'
    output = StringIO()
    args = mock.Mock()
    args.variables = ['a', 'b', 'c', 'd', 'e']
    args.prefix = ''
    sf.emit_one(c, d, output, args)
    actual = output.getvalue()
    assert expected == actual