Update tests/test_utils_tqdm_mod.py
Run CI Tests / test (push) Successful in 40s

This commit is contained in:
2025-07-30 15:47:19 +02:00
parent 83a47fed9f
commit 9cec262a05
+26 -10
View File
@@ -82,31 +82,47 @@ def test_format_sizeof_alignment():
# test format_sizeof rounding using tqdm
def test_float_alignment_in_bar():
import io
from contextlib import redirect_stdout
# Capture the tqdm output into a string buffer
f = io.StringIO()
with redirect_stdout(f):
bar = tqdm_mod(total=100.12, desc="AlignBar", file=f)
bar.set(1.3)
bar.set(1.3333)
bar.set(12.5)
bar.set(99.9)
bar.set(99.98)
bar.set(100.0)
bar.set(100.1)
bar.set(100.12)
bar.close()
# Extract lines containing the label
lines = extract_lines(f.getvalue(), "AlignBar")
# Extrait uniquement les morceaux contenant "xx.x/100.1"
# Expected strings that should appear in the output, rounded with format_sizeof
expected_values = [
" 1.3/100.1",
" 12.5/100.1",
" 99.9/100.1",
"100.0/100.1",
"100.1/100.1",
]
# Extract progress values matching the format "xx.x/100.1"
values = []
for line in lines:
match = re.search(r"(\d{1,3}\.\d)/100\.1", line)
if match:
values.append(match.group(0)) # e.g. " 1.3/100.1"
values.append(match.group(0))
# Vérifie que toutes les chaînes ont exactement la même longueur
# Ensure raw 100.12 never appears : format_sizeof must have truncated it
assert all("100.12" not in line for line in lines), "Unrounded value '100.12' found in output!"
# Ensure all expected formatted values are found in the output
for expected in expected_values:
assert expected in values, f"Missing expected value: {expected}"
# Ensure all values are visually aligned thanks to format_sizeof : all outouts with same length
lengths = [len(v) for v in values]
assert len(set(lengths)) == 1, f"Lengths differ: {lengths}, values: {values}"
assert len(set(lengths)) == 1, f"Misaligned values: {values}"
def test_custom_unit():