def test_formattable_column(self):
     sf = value.ValueFormatter()
     c = ('a', 'b', 'c', 'd')
     d = ('A', 'B', 'C', test_columns.FauxColumn(['the', 'value']))
     expected = "A\nB\nC\n['the', 'value']\n"
     output = six.StringIO()
     sf.emit_one(c, d, output, None)
     actual = output.getvalue()
     self.assertEqual(expected, actual)
 def test_list_formatter_formattable_column(self):
     sf = value.ValueFormatter()
     c = ('a', 'b', 'c')
     d1 = ('A', 'B', test_columns.FauxColumn(['the', 'value']))
     data = [d1]
     expected = "A B ['the', 'value']\n"
     output = six.StringIO()
     sf.emit_list(c, data, output, None)
     actual = output.getvalue()
     self.assertEqual(expected, actual)
 def test_commaseparated_list_formatter_formattable_column(self):
     sf = commaseparated.CSVLister()
     c = ('a', 'b', 'c')
     d1 = ('A', 'B', test_columns.FauxColumn(['the', 'value']))
     data = [d1]
     expected = 'a,b,c\nA,B,[\'the\'\\, \'value\']\n'
     output = six.StringIO()
     parsed_args = mock.Mock()
     parsed_args.quote_mode = 'none'
     sf.emit_list(c, data, output, parsed_args)
     actual = output.getvalue()
     self.assertEqual(expected, actual)
 def test_formattable_column(self, tw):
     tw.return_value = 80
     c = ('a', 'b', 'c')
     d1 = ('A', 'B', test_columns.FauxColumn(['the', 'value']))
     data = [d1]
     expected = textwrap.dedent('''\
     +---+---+---------------------------------------------+
     | a | b | c                                           |
     +---+---+---------------------------------------------+
     | A | B | I made this string myself: ['the', 'value'] |
     +---+---+---------------------------------------------+
     ''')
     self.assertEqual(expected, _table_tester_helper(c, data))
def test_table_list_formatter_formattable_column(tw):
    tw.return_value = 80
    c = ('a', 'b', 'c')
    d1 = ('A', 'B', test_columns.FauxColumn(['the', 'value']))
    data = [d1]
    expected = '''\
+---+---+---------------------------------------------+
| a | b | c                                           |
+---+---+---------------------------------------------+
| A | B | I made this string myself: ['the', 'value'] |
+---+---+---------------------------------------------+
'''
    assert expected == _table_tester_helper(c, data)
 def test_table_formatter_formattable_column(self, tw):
     tw.return_value = 0
     c = ('a', 'b', 'c', 'd')
     d = ('A', 'B', 'C', test_columns.FauxColumn(['the', 'value']))
     expected = textwrap.dedent('''\
     +-------+---------------------------------------------+
     | Field | Value                                       |
     +-------+---------------------------------------------+
     | a     | A                                           |
     | b     | B                                           |
     | c     | C                                           |
     | d     | I made this string myself: ['the', 'value'] |
     +-------+---------------------------------------------+
     ''')
     self.assertEqual(expected, _table_tester_helper(c, d))
def test_table_formatter_formattable_column(tw):
    tw.return_value = 0
    c = ('a', 'b', 'c', 'd')
    d = ('A', 'B', 'C', test_columns.FauxColumn(['the', 'value']))
    expected = '''\
+-------+---------------------------------------------+
| Field | Value                                       |
+-------+---------------------------------------------+
| a     | A                                           |
| b     | B                                           |
| c     | C                                           |
| d     | I made this string myself: ['the', 'value'] |
+-------+---------------------------------------------+
'''
    assert expected == _table_tester_helper(c, d)
 def test_formattable_column(self):
     sf = shell.ShellFormatter()
     c = ('a', 'b', 'c')
     d = ('A', 'B', test_columns.FauxColumn(['the', 'value']))
     expected = '\n'.join([
         'a="A"',
         'b="B"',
         'c="[\'the\', \'value\']"\n',
     ])
     output = six.StringIO()
     args = mock.Mock()
     args.variables = ['a', 'b', 'c']
     args.prefix = ''
     sf.emit_one(c, d, output, args)
     actual = output.getvalue()
     self.assertEqual(expected, actual)
    def test_formattablecolumn_list(self):
        sf = yaml_format.YAMLFormatter()
        c = ('a', 'b', 'c')
        d = (
            ('A1', 'B1', test_columns.FauxColumn(['the', 'value'])),
        )
        expected = [
            {'a': 'A1', 'b': 'B1', 'c': ['the', 'value']},
        ]
        args = mock.Mock()
        sf.add_argument_group(args)

        args.noindent = True
        output = six.StringIO()
        sf.emit_list(c, d, output, args)
        actual = yaml.safe_load(output.getvalue())
        self.assertEqual(expected, actual)
    def test_formattablecolumn_one(self):
        sf = yaml_format.YAMLFormatter()
        c = ('a', 'b', 'c', 'd')
        d = ('A', 'B', 'C', test_columns.FauxColumn(['the', 'value']))
        expected = {
            'a': 'A',
            'b': 'B',
            'c': 'C',
            'd': ['the', 'value'],
        }
        args = mock.Mock()
        sf.add_argument_group(args)

        args.noindent = True
        output = six.StringIO()
        sf.emit_one(c, d, output, args)
        value = output.getvalue()
        print(len(value.splitlines()))
        actual = yaml.safe_load(output.getvalue())
        self.assertEqual(expected, actual)
Example #11
0
    def test_formattablecolumn_list(self):
        sf = json_format.JSONFormatter()
        c = ('a', 'b', 'c')
        d = (('A1', 'B1', test_columns.FauxColumn(['the', 'value'])), )
        expected = [
            {
                'a': 'A1',
                'b': 'B1',
                'c': ['the', 'value']
            },
        ]
        args = mock.Mock()
        sf.add_argument_group(args)

        args.noindent = True
        output = six.StringIO()
        sf.emit_list(c, d, output, args)
        value = output.getvalue()
        self.assertEqual(1, len(value.splitlines()))
        actual = json.loads(value)
        self.assertEqual(expected, actual)
Example #12
0
def test_json_format_formattablecolumn_one():
    sf = json_format.JSONFormatter()
    c = ('a', 'b', 'c', 'd')
    d = ('A', 'B', 'C', test_columns.FauxColumn(['the', 'value']))
    expected = {
        'a': 'A',
        'b': 'B',
        'c': 'C',
        'd': ['the', 'value'],
    }
    args = mock.Mock()
    sf.add_argument_group(args)

    args.noindent = True
    output = six.StringIO()
    sf.emit_one(c, d, output, args)
    value = output.getvalue()
    print(len(value.splitlines()))
    assert 1 == len(value.splitlines())
    actual = json.loads(value)
    assert expected == actual