Skip to content

Fix convert_size_bytes_to_string returning "1024 <unit>" after rounding - #200

Open
Shaisolaris wants to merge 1 commit into
fabiocaccamo:mainfrom
Shaisolaris:size-string-rounding
Open

Shaisolaris wants to merge 1 commit into
fabiocaccamo:mainfrom
Shaisolaris:size-string-rounding

Conversation

@Shaisolaris

Copy link
Copy Markdown

Describe your changes

convert_size_bytes_to_string picks the unit before rounding, so values just below a unit boundary round up to 1024 of the smaller unit instead of moving to the next one:

fsutil.convert_size_bytes_to_string(1048575)     # "1024 KB", expected "1.00 MB"
fsutil.convert_size_bytes_to_string(1073741823)  # "1024.00 MB", expected "1.00 GB"

This happens for any size whose rounded value reaches 1024 (for example get_file_size_formatted on a file of 1048575 bytes). After the unit loop, the value is now rounded with the same precision used for display, and if that reaches 1024 it is moved to the next unit. Sizes that do not round up to 1024 (such as 1073217536 -> "1023.50 MB") and the existing cases are unchanged, including sizes beyond YB.

Related issue

None that I could find.

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have added tests for the proposed changes.
  • I have run the tests and there are not errors.

Three cases were added to test_convert_size_bytes_to_string; the two boundary cases fail on main and pass with the change. pytest tests gives 308 passed locally, and ruff check, ruff format --check and mypy src are clean. I left CHANGELOG.md alone since it looks like you write it at release time.

@fabiocaccamo fabiocaccamo added the bug Something isn't working label Oct 13, 2026
@fabiocaccamo fabiocaccamo self-assigned this Oct 13, 2026
@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.52%. Comparing base (d3a77c5) to head (576159e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #200   +/-   ##
=======================================
  Coverage   98.52%   98.52%           
=======================================
  Files          13       13           
  Lines         812      815    +3     
=======================================
+ Hits          800      803    +3     
  Misses         12       12           
Flag Coverage Δ
unittests 98.52% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants