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()
    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)
Exemple #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)
Exemple #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)
    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)
Exemple #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)