Skip to content

Commit

Permalink
CRAYSAT-1936: fixed sat showrev error
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanholen-hpe committed Dec 9, 2024
1 parent 028ddba commit c191615
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
18 changes: 10 additions & 8 deletions sat/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,22 @@ def __init__(self, headings, title=None,
if not isinstance(self.sort_by, list):
self.sort_by = [self.sort_by]
warn_str = "Element '%s' is not in %s. Output will be unsorted on that element."
valid_sort_by = []
for i in range(len(self.sort_by)):
try:
self.sort_by[i] = int(self.sort_by[i])
self.sort_by[i] = self.headings[self.sort_by[i]]
index = int(self.sort_by[i])
valid_sort_by.append(self.headings[index])
except IndexError:
# sort_by is out of range.
LOGGER.warning(warn_str, sort_by, self.headings)
self.sort_by.remove(self.sort_by[i])
LOGGER.warning(warn_str, self.sort_by[i], self.headings)
except ValueError:
# sort_by is not an int.
self.sort_by[i] = match_query_key(self.sort_by[i], headings)
if not self.sort_by[i]:
LOGGER.warning(warn_str, sort_by, self.headings)
self.sort_by = None
if match_query_key(sort_by[i], self.headings):
valid_sort_by.append(match_query_key(self.sort_by[i], headings))
else:
LOGGER.warning(warn_str, self.sort_by[i], self.headings)

self.sort_by = valid_sort_by

if self.sort_by == []:
self.sort_by = None
Expand Down
13 changes: 13 additions & 0 deletions tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,19 @@ def test_sort_heading_invalid(self):
for expected, actual in zip(self.out_of_order, pt_s):
self.assertEqual(expected, actual)

def test_sort_heading_invalid_multiple(self):
"""The PT should default to not sorting if the heading is not present.
"""
report = Report(self.headings, sort_by=['does-not-exist', 'does-not-exist-two'])

self.assertEqual(None, report.sort_by)

report.add_rows(self.out_of_order)
pt_s = get_report_printed_list(report)

for expected, actual in zip(self.out_of_order, pt_s):
self.assertEqual(expected, actual)

def test_sort_heading_idx_invalid(self):
"""The PT should not sort if the idx is out-of-range.
"""
Expand Down

0 comments on commit c191615

Please sign in to comment.