def test_print_list_sort_by_none(self):
        objs = [_FakeResult("k1", 1),
                _FakeResult("k3", 3),
                _FakeResult("k2", 2)]

        cliutils.print_list(objs, ["Name", "Value"], sortby_index=None)

        self.assertEqual(self.mock_add_row.call_args_list,
                         [mock.call(["k1", 1]),
                          mock.call(["k3", 3]),
                          mock.call(["k2", 2])])
        self.mock_get_string.assert_called_with()
示例#2
0
    def test_print_list_field_labels(self):
        objs = [_FakeResult("k1", 1),
                _FakeResult("k3", 3),
                _FakeResult("k2", 2)]
        field_labels = ["Another Name", "Another Value"]

        cliutils.print_list(objs, ["Name", "Value"], sortby_index=None,
                            field_labels=field_labels)

        self.assertEqual(self.mock_add_row.call_args_list,
                         [mock.call(["k1", 1]),
                          mock.call(["k3", 3]),
                          mock.call(["k2", 2])])
        self.mock_init.assert_called_once_with(field_labels)
示例#3
0
    def test_print_list_sort_by_none(self):
        objs = [
            _FakeResult("k1", 1),
            _FakeResult("k3", 3),
            _FakeResult("k2", 2)
        ]

        cliutils.print_list(objs, ["Name", "Value"], sortby_index=None)

        self.assertEqual(
            self.mock_add_row.call_args_list,
            [mock.call(["k1", 1]),
             mock.call(["k3", 3]),
             mock.call(["k2", 2])])
        self.mock_get_string.assert_called_with(sortby=None)
示例#4
0
    def test_print_list_field_labels(self):
        objs = [
            _FakeResult("k1", 1),
            _FakeResult("k3", 3),
            _FakeResult("k2", 2)
        ]
        field_labels = ["Another Name", "Another Value"]

        cliutils.print_list(objs, ["Name", "Value"],
                            sortby_index=None,
                            field_labels=field_labels)

        self.assertEqual(
            self.mock_add_row.call_args_list,
            [mock.call(["k1", 1]),
             mock.call(["k3", 3]),
             mock.call(["k2", 2])])
        self.mock_init.assert_called_once_with(field_labels)
示例#5
0
    def test_print_list_string(self):
        objs = [_FakeResult("k1", 1)]
        field_labels = ["Another Name", "Another Value"]

        orig = sys.stdout
        sys.stdout = six.StringIO()
        cliutils.print_list(objs, ["Name", "Value"], sortby_index=0,
                            field_labels=field_labels)
        out = sys.stdout.getvalue()
        sys.stdout.close()
        sys.stdout = orig
        expected = '''\
+--------------+---------------+
| Another Name | Another Value |
+--------------+---------------+
| k1           | 1             |
+--------------+---------------+
'''
        self.assertEqual(expected, out)
示例#6
0
    def test_print_list_string(self):
        objs = [_FakeResult("k1", 1)]
        field_labels = ["Another Name", "Another Value"]

        orig = sys.stdout
        sys.stdout = six.StringIO()
        cliutils.print_list(objs, ["Name", "Value"],
                            sortby_index=0,
                            field_labels=field_labels)
        out = sys.stdout.getvalue()
        sys.stdout.close()
        sys.stdout = orig
        expected = '''\
+--------------+---------------+
| Another Name | Another Value |
+--------------+---------------+
| k1           | 1             |
+--------------+---------------+
'''
        self.assertEqual(expected, out)