fix: fit the progress line to the terminal

This commit is contained in:
Abdessamad Derraz committed 2026-10-18 16:26:01 +02:00
1 parent 8247895664
commit e2d329c6ef
4 files changed
+53 -12

No files matched your search

+26
View File
@@ -2631,5 +2631,31 @@ class AChunkedCutIsADownloadFailure(unittest.TestCase):
self.assertIn("IncompleteRead", reason)
class TheProgressLineFitsTheTerminal(unittest.TestCase):
"""At 80 columns the 94-100 column line wrapped, and every redraw left
a ghost line behind."""
def test_each_width(self):
import os as _os
for columns in (40, 60, 80, 120):
with self.subTest(columns=columns):
out = io.StringIO()
term = install.Terminal(out)
term.live = True
progress = install.Progress(5865, 2_300_000_000, term)
progress.bytes = 1_000_000_000
progress.files = 5000
with unittest.mock.patch.object(
install.shutil, "get_terminal_size",
return_value=_os.terminal_size((columns, 24)),
):
progress._draw()
line = out.getvalue().split("\033[K")[-1]
self.assertLess(len(line), columns)
self.assertIn("%", line)
if __name__ == "__main__":
unittest.main()