mirror of
https://github.com/esphome/esphome.git
synced 2026-10-01 17:00:21 +00:00
Do not end a progress bar that never drew a frame
This commit is contained in:
@@ -768,7 +768,13 @@ class BatchDownloadProgress:
|
||||
return update
|
||||
|
||||
def done(self) -> None:
|
||||
if self._bar is not None and self._bar.last_progress != 100:
|
||||
# Nothing to end unless a frame was drawn and it was not the final
|
||||
# one (update(1) already emitted its own newline).
|
||||
if (
|
||||
self._bar is not None
|
||||
and self._bar.last_progress is not None
|
||||
and self._bar.last_progress != 100
|
||||
):
|
||||
self._bar.done()
|
||||
|
||||
|
||||
|
||||
@@ -1197,6 +1197,15 @@ class TestBatchDownloadProgress:
|
||||
progress.done()
|
||||
assert stream.getvalue().endswith("50% \n")
|
||||
|
||||
def test_done_before_any_frame_writes_nothing(self) -> None:
|
||||
"""A batch aborted before any tracker fired must not emit a stray
|
||||
newline for a bar that was never drawn."""
|
||||
stream = io.StringIO()
|
||||
stream.isatty = lambda: True # type: ignore[method-assign]
|
||||
with patch("esphome.helpers.sys.stderr", stream):
|
||||
BatchDownloadProgress("Downloading", 10).done()
|
||||
assert stream.getvalue() == ""
|
||||
|
||||
def test_done_after_full_bar_adds_nothing(self) -> None:
|
||||
stream = io.StringIO()
|
||||
stream.isatty = lambda: True # type: ignore[method-assign]
|
||||
|
||||
Reference in New Issue
Block a user