From c19161560999c372982fe5f1e3132bb34b534d56 Mon Sep 17 00:00:00 2001 From: ethanholen-hpe Date: Mon, 9 Dec 2024 12:21:24 -0700 Subject: [PATCH] CRAYSAT-1936: fixed sat showrev error --- sat/report.py | 18 ++++++++++-------- tests/test_report.py | 13 +++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/sat/report.py b/sat/report.py index f24d04e4..5358ec9a 100644 --- a/sat/report.py +++ b/sat/report.py @@ -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 diff --git a/tests/test_report.py b/tests/test_report.py index 7b2dc28c..226720e3 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -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. """