Ejemplo n.º 1
0
    def test_list(self):
        sf = json_format.JSONFormatter()
        c = ('a', 'b', 'c')
        d = (('A1', 'B1', 'C1'), ('A2', 'B2', 'C2'), ('A3', 'B3', 'C3'))
        expected = [{
            'a': 'A1',
            'b': 'B1',
            'c': 'C1'
        }, {
            'a': 'A2',
            'b': 'B2',
            'c': 'C2'
        }, {
            'a': 'A3',
            'b': 'B3',
            'c': 'C3'
        }]
        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)

        args.noindent = False
        output = six.StringIO()
        sf.emit_list(c, d, output, args)
        value = output.getvalue()
        self.assertEqual(17, len(value.splitlines()))
        actual = json.loads(value)
        self.assertEqual(expected, actual)
Ejemplo n.º 2
0
    def test_formattablecolumn_one(self):
        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()))
        self.assertEqual(1, len(value.splitlines()))
        actual = json.loads(value)
        self.assertEqual(expected, actual)
Ejemplo n.º 3
0
def test_json_format_formattablecolumn_list():
    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()
    assert 1 == len(value.splitlines())
    actual = json.loads(value)
    assert expected == actual
Ejemplo n.º 4
0
    def test_one(self):
        sf = json_format.JSONFormatter()
        c = ('a', 'b', 'c', 'd')
        d = ('A', 'B', 'C', '"escape me"')
        expected = {'a': 'A', 'b': 'B', 'c': 'C', 'd': '"escape me"'}
        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()))
        self.assertEqual(1, len(value.splitlines()))
        actual = json.loads(value)
        self.assertEqual(expected, actual)

        args.noindent = False
        output = six.StringIO()
        sf.emit_one(c, d, output, args)
        value = output.getvalue()
        self.assertEqual(6, len(value.splitlines()))
        actual = json.loads(value)
        self.assertEqual(expected, actual)