Skip to content

Fix base bandwidth conversions and byte formatter scaling - #929

Open
omrzk wants to merge 2 commits into
networktocode:developfrom
omrzk:fix/bandwidth-base-unit-conversion
Open

omrzk wants to merge 2 commits into
networktocode:developfrom
omrzk:fix/bandwidth-base-unit-conversion

Conversation

@omrzk

@omrzk omrzk commented Nov 19, 2026

Copy link
Copy Markdown

New Pull Request

Have you:

  • Updated the README if necessary? Existing API documentation already describes these units; no README change is needed.
  • Updated any configuration settings? Not applicable: no settings change.
  • Written a unit test? Base-unit, SI boundary, round-trip and Jinja filter regressions are included.

Change Notes

Fixes #928. Base-unit names such as 100bps and 100Bps currently parse as zero because their range lower bound is also used as their unit factor. Use one bit and eight bits per byte as the minimum factors, including when converting into Bps.

bytes_to_name also compares a byte input against bit-based thresholds and multiplies base-unit output by eight. Compare using the converted bit value and divide by the correct unit factor: 950.0 now produces 950.0Bps, and 1000.0 produces 1.0KBps. Five existing formatter expectations are corrected to match the documented bytes/s contract; prefixed and invalid-input cases remain covered.

Justification

This repairs direct conversions and network automation templates using the existing Jinja filters. Formatting then parsing 950 bytes/s currently returns zero; it now preserves 950.0.

Validation: the final bandwidth tests fail on unchanged develop (32 failed, 96 passed) and pass with the fix (128 passed), including a real Jinja filter round trip. Full suites pass on CPython 3.10.22 and 3.14.10 (879 passed each), and 3.13.18 (877 passed, two skipped); all three pass 117 doctests. On Python 3.13, full Ruff formatting/lint, mypy, Pylint, yamllint, strict documentation build, Poetry check and Towncrier check pass. Poetry and docs tools emit existing deprecation notices. Tests run locally on Linux; no live network device testing was performed.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Base bandwidth units convert to zero and byte formatting uses inconsistent scales

1 participant