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
17 from cliff.formatters import value
18 from cliff.tests import test_columns
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
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
43 def test_value_list_formatter():
44 sf = value.ValueFormatter()
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
56 def test_value_list_formatter_formattable_column():
57 sf = value.ValueFormatter()
59 d1 = ('A', 'B', test_columns.FauxColumn(['the', 'value']))
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