f704b08c47257333fbfca18d0f73801f0031cb66
[sdc/sdc-distribution-client.git] /
1 #!/usr/bin/env python
2 #
3 #  Licensed under the Apache License, Version 2.0 (the "License"); you may
4 #  not use this file except in compliance with the License. You may obtain
5 #  a copy of the License at
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #  Unless required by applicable law or agreed to in writing, software
10 #  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 #  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 #  License for the specific language governing permissions and limitations
13 #  under the License.
14
15 import six
16
17 from cliff.formatters import value
18 from cliff.tests import test_columns
19
20
21 def test_value_formatter():
22     sf = value.ValueFormatter()
23     c = ('a', 'b', 'c', 'd')
24     d = ('A', 'B', 'C', '"no escape me"')
25     expected = 'A\nB\nC\n"no escape me"\n'
26     output = six.StringIO()
27     sf.emit_one(c, d, output, None)
28     actual = output.getvalue()
29     assert expected == actual
30
31
32 def test_value_formatter_formattable_column():
33     sf = value.ValueFormatter()
34     c = ('a', 'b', 'c', 'd')
35     d = ('A', 'B', 'C', test_columns.FauxColumn(['the', 'value']))
36     expected = "A\nB\nC\n['the', 'value']\n"
37     output = six.StringIO()
38     sf.emit_one(c, d, output, None)
39     actual = output.getvalue()
40     assert expected == actual
41
42
43 def test_value_list_formatter():
44     sf = value.ValueFormatter()
45     c = ('a', 'b', 'c')
46     d1 = ('A', 'B', 'C')
47     d2 = ('D', 'E', 'F')
48     data = [d1, d2]
49     expected = 'A B C\nD E F\n'
50     output = six.StringIO()
51     sf.emit_list(c, data, output, None)
52     actual = output.getvalue()
53     assert expected == actual
54
55
56 def test_value_list_formatter_formattable_column():
57     sf = value.ValueFormatter()
58     c = ('a', 'b', 'c')
59     d1 = ('A', 'B', test_columns.FauxColumn(['the', 'value']))
60     data = [d1]
61     expected = "A B ['the', 'value']\n"
62     output = six.StringIO()
63     sf.emit_list(c, data, output, None)
64     actual = output.getvalue()
65     assert expected == actual