Skip to content

Commit

Permalink
Merge pull request #6533 from grondo/issue#6530
Browse files Browse the repository at this point in the history
fix possible truncation of strings with "expandable" output fields
  • Loading branch information
mergify[bot] authored Dec 21, 2024
2 parents bb3e8c7 + 27f4c50 commit d58f245
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/bindings/python/flux/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def width(self, val):

# Also adjust precision if necessary (only for string type)
if (
self.type in (None, "s")
self.type in (None, "s", "")
and self.precision
and self.precision < self.width
):
Expand Down
15 changes: 13 additions & 2 deletions t/python/t0024-util.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ def test_filter(self):
self.assertEqual(fmt, "{i:>8} {f:8.2}")

fmt = OutputFormat(
"?+:{i:>7} ?:{s:>6} ?+:{f:.2}", headings=self.headings
"?+:{i:>7} ?:{s:>6} ?+:{f:.2f}", headings=self.headings
).filter(items)
self.assertEqual(fmt, "{i:>8} {f:3.2}")
self.assertEqual(fmt, "{i:>8} {f:3.2f}")

def test_sort(self):
a = Item("a", 0, 2.2)
Expand Down Expand Up @@ -250,6 +250,17 @@ def test_sort(self):
formatter.sort_items(items)
self.assertListEqual(items, [z, d, a])

def test_issue6530(self):
a = Item("1234567890", 0, 2.2)
b = Item("abcdefghijklmnop", 2, 13)
c = Item("c", 4, 5.0)

items = [a, b, c]
fmt = OutputFormat(
"+:{s:5.5} +:{i:4d} +:{f:.2f}", headings=self.headings
).filter(items)
self.assertEqual(fmt, "{s:16.16} {i:4d} {f:3.2f}")


if __name__ == "__main__":
unittest.main(testRunner=TAPTestRunner())

0 comments on commit d58f245

Please sign in to comment.