コード例 #1
0
ファイル: cli_test.py プロジェクト: weihann-hor/treadmill
    def test_table(self):
        """Tests table output."""
        schema = [('A', 'a', None),
                  ('b', None, None),
                  ('c', None, None)]

        tbl = cli.make_dict_to_table(schema)
        list_tbl = cli.make_list_to_table(schema)

        self.assertEquals(_lines(tbl({'a': 1, 'b': 2, 'c': [1, 2, 3]})),
                          ['A  :  1',
                           'b  :  2',
                           'c  :  1,2,3'])

        self.assertEquals(_lines(list_tbl([{'a': 1, 'b': 2, 'c': [1, 2, 3]}])),
                          ['A  b  c',
                           '1  2  1,2,3'])
コード例 #2
0
    def format(item):
        """Return pretty-formatted item."""
        schema = [
            ('name', None, None),
            ('tgid', None, None),
            ('threads', None, None),
            ('private', None, None),
            ('shared', None, None),
            ('total', None, None),
        ]

        format_item = cli.make_dict_to_table(schema)
        format_list = cli.make_list_to_table(schema)

        if isinstance(item, list):
            return format_list(item)
        else:
            return format_item(item)