Skip to content

Commit 889b0f8

Browse files
authored
Explicitly check for duplicated columns when using tables in the cli (softlayer#746)
1 parent 6a1e4a3 commit 889b0f8

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

SoftLayer/CLI/formatting.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
:license: MIT, see LICENSE for more details.
88
"""
99
# pylint: disable=E0202
10+
import collections
1011
import json
1112
import os
1213

@@ -252,6 +253,13 @@ class Table(object):
252253
:param list columns: a list of column names
253254
"""
254255
def __init__(self, columns):
256+
duplicated_cols = [col for col, count
257+
in collections.Counter(columns).items()
258+
if count > 1]
259+
if len(duplicated_cols) > 0:
260+
raise exceptions.CLIAbort("Duplicated columns are not allowed: %s"
261+
% ','.join(duplicated_cols))
262+
255263
self.columns = columns
256264
self.rows = []
257265
self.align = {}

tests/CLI/helper_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ def test_resolve_id_multiple(self):
265265
exceptions.CLIAbort, helpers.resolve_id, resolver, 'test')
266266

267267

268+
class TestTable(testing.TestCase):
269+
270+
def test_table_with_duplicated_columns(self):
271+
self.assertRaises(exceptions.CLIHalt, formatting.Table, ['col', 'col'])
272+
273+
268274
class TestFormatOutput(testing.TestCase):
269275

270276
def test_format_output_string(self):

0 commit comments

Comments
 (0)