Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions SoftLayer/CLI/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:license: MIT, see LICENSE for more details.
"""
# pylint: disable=E0202
import collections
import json
import os

Expand Down Expand Up @@ -252,6 +253,13 @@ class Table(object):
:param list columns: a list of column names
"""
def __init__(self, columns):
duplicated_cols = [col for col, count
in collections.Counter(columns).items()
if count > 1]
if len(duplicated_cols) > 0:
raise exceptions.CLIAbort("Duplicated columns are not allowed: %s"
% ','.join(duplicated_cols))

self.columns = columns
self.rows = []
self.align = {}
Expand Down
6 changes: 6 additions & 0 deletions tests/CLI/helper_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ def test_resolve_id_multiple(self):
exceptions.CLIAbort, helpers.resolve_id, resolver, 'test')


class TestTable(testing.TestCase):

def test_table_with_duplicated_columns(self):
self.assertRaises(exceptions.CLIHalt, formatting.Table, ['col', 'col'])


class TestFormatOutput(testing.TestCase):

def test_format_output_string(self):
Expand Down