Skip to content

Commit 1ae0325

Browse files
committed
Update progress on eof
1 parent fbefc80 commit 1ae0325

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/fastapi_cloud_cli/utils/progress_file.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def read(self, n=-1):
2222
data = self._file.read(n)
2323
self._bytes_read += len(data)
2424
now_ = datetime.now().timestamp()
25-
if now_ - self._last_update_time >= self._update_interval:
25+
is_eof = (len(data) == 0) or (n > 0 and len(data) < n)
26+
if (now_ - self._last_update_time >= self._update_interval) or is_eof:
2627
self._progress_callback(self._bytes_read)
2728
self._last_update_time = now_
2829
return data

tests/test_progress_file.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ def test_callback_tracks_cumulative_bytes() -> None:
7676

7777
mock_callback.assert_has_calls([call(10), call(30), call(40)])
7878

79+
def test_callback_called_on_eof() -> None:
80+
file = _make_file(b"abcd")
81+
mock_callback = Mock()
82+
83+
pf = ProgressFile(file, progress_callback=mock_callback)
84+
pf.read(3)
85+
pf.read(3)
86+
mock_callback.assert_has_calls([call(3), call(4)])
87+
7988

8089
def test_name_property() -> None:
8190
file = _make_file(name="test.tar.gz")

0 commit comments

Comments
 (0)