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
7 # http://www.apache.org/licenses/LICENSE-2.0
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
18 from cliff.formatters import yaml_format
19 from cliff.tests import test_columns
24 def test_yaml_format_one():
25 sf = yaml_format.YAMLFormatter()
26 c = ('a', 'b', 'c', 'd')
27 d = ('A', 'B', 'C', '"escape me"')
34 output = six.StringIO()
36 sf.emit_one(c, d, output, args)
37 actual = yaml.safe_load(output.getvalue())
38 assert expected == actual
41 def test_yaml_format_formattablecolumn_one():
42 sf = yaml_format.YAMLFormatter()
43 c = ('a', 'b', 'c', 'd')
44 d = ('A', 'B', 'C', test_columns.FauxColumn(['the', 'value']))
49 'd': ['the', 'value'],
52 sf.add_argument_group(args)
55 output = six.StringIO()
56 sf.emit_one(c, d, output, args)
57 value = output.getvalue()
58 print(len(value.splitlines()))
59 actual = yaml.safe_load(output.getvalue())
60 assert expected == actual
63 def test_yaml_format_list():
64 sf = yaml_format.YAMLFormatter()
72 {'a': 'A1', 'b': 'B1', 'c': 'C1'},
73 {'a': 'A2', 'b': 'B2', 'c': 'C2'},
74 {'a': 'A3', 'b': 'B3', 'c': 'C3'}
76 output = six.StringIO()
78 sf.add_argument_group(args)
79 sf.emit_list(c, d, output, args)
80 actual = yaml.safe_load(output.getvalue())
81 assert expected == actual
84 def test_yaml_format_formattablecolumn_list():
85 sf = yaml_format.YAMLFormatter()
88 ('A1', 'B1', test_columns.FauxColumn(['the', 'value'])),
91 {'a': 'A1', 'b': 'B1', 'c': ['the', 'value']},
94 sf.add_argument_group(args)
97 output = six.StringIO()
98 sf.emit_list(c, d, output, args)
99 actual = yaml.safe_load(output.getvalue())
100 assert expected == actual