diff --git a/tests/test_utils_rangebar.py b/tests/test_utils_rangebar.py index da4168daa..4c635cc49 100644 --- a/tests/test_utils_rangebar.py +++ b/tests/test_utils_rangebar.py @@ -85,37 +85,28 @@ def test_repr(): expected = "[ 0 kg |10 blocks| 100 kg ]" assert repr(bar) == expected -def test_multiple_show_evolution(capture_stdout): +import pytest + +@pytest.mark.parametrize("value, expected_bar_part", [ + (0, ' ' * 10), + (10, '█' + ' ' * 9), + (25, '██▌' + ' ' * 7), + (27, '██▋' + ' ' * 7), + (49, '████▉' + ' ' * 5), + (50, '█' * 5 + ' ' * 5), + (51, '█' * 5 + '▏' + ' ' * 4), + (73, '█' * 7 + '▎' + ' ' * 2), + (75, '█' * 7 + '▌' + ' ' * 2), + (90, '█' * 9 + ' ' * 0), + (100, '█' * 10) +]) +def test_each_value_separately(capture_stdout, value, expected_bar_part): out = capture_stdout with RangeBar(0, 100, width=10, units="kg", fmt=".0f") as bar: - bar.show(0) - bar.show(10) - bar.show(25) - bar.show(27) - bar.show(49) - bar.show(50) - bar.show(51) - bar.show(73) - bar.show(75) - bar.show(90) - bar.show(100) - - result = out.getvalue() - lines = result.strip().split("\r") - - expected_lines = [ - f"[ 0 kg |{colorama.Fore.GREEN}{' ' * 10}{colorama.Fore.RESET}| 100 kg ] {colorama.Style.BRIGHT}0 kg{colorama.Style.RESET_ALL}", - f"[ 0 kg |{colorama.Fore.GREEN}{'█' * 1}{' ' * 9}{colorama.Fore.RESET}| 100 kg ] {colorama.Style.BRIGHT}10 kg{colorama.Style.RESET_ALL}", - f"[ 0 kg |{colorama.Fore.GREEN}{'█' * 2}▌{' ' * 7}{colorama.Fore.RESET}| 100 kg ] {colorama.Style.BRIGHT}25 kg{colorama.Style.RESET_ALL}", # 25% → 1.75 → round=2 → ▌ - f"[ 0 kg |{colorama.Fore.GREEN}{'█' * 2}▋{' ' * 7}{colorama.Fore.RESET}| 100 kg ] {colorama.Style.BRIGHT}27 kg{colorama.Style.RESET_ALL}", # 27% → 1.89 → round=2 → ▌ - f"[ 0 kg |{colorama.Fore.GREEN}{'█' * 5}{' ' * 5}{colorama.Fore.RESET}| 100 kg ] {colorama.Style.BRIGHT}49 kg{colorama.Style.RESET_ALL}", # 49% → 3.43 → round=3 → ▋ - f"[ 0 kg |{colorama.Fore.GREEN}{'█' * 5}{' ' * 5}{colorama.Fore.RESET}| 100 kg ] {colorama.Style.BRIGHT}50 kg{colorama.Style.RESET_ALL}", - f"[ 0 kg |{colorama.Fore.GREEN}{'█' * 5}▏{' ' * 4}{colorama.Fore.RESET}| 100 kg ] {colorama.Style.BRIGHT}51 kg{colorama.Style.RESET_ALL}", # 51% → 3.57 → round=4 → ▍ - f"[ 0 kg |{colorama.Fore.GREEN}{'█' * 7}▎{' ' * 2}{colorama.Fore.RESET}| 100 kg ] {colorama.Style.BRIGHT}73 kg{colorama.Style.RESET_ALL}", # 73% → 5.11 → round=5 → ▋ - f"[ 0 kg |{colorama.Fore.GREEN}{'█' * 7}▌{' ' * 2}{colorama.Fore.RESET}| 100 kg ] {colorama.Style.BRIGHT}75 kg{colorama.Style.RESET_ALL}", # 75% → 5.25 → round=5 → ▊ - f"[ 0 kg |{colorama.Fore.GREEN}{'█' * 9} {' ' * 0}{colorama.Fore.RESET}| 100 kg ] {colorama.Style.BRIGHT}90 kg{colorama.Style.RESET_ALL}", - f"[ 0 kg |{colorama.Fore.GREEN}{'█' * 10}{colorama.Fore.RESET}| 100 kg ] {colorama.Style.BRIGHT}100 kg{colorama.Style.RESET_ALL}" - ] - - for expected in expected_lines: - assert expected in lines + bar.show(value) + + result = out.getvalue().strip() + expected = f"[ 0 kg |{colorama.Fore.GREEN}{expected_bar_part}{colorama.Fore.RESET}| 100 kg ] {colorama.Style.BRIGHT}{value} kg{colorama.Style.RESET_ALL}" + + assert expected in result, f"\nExpected: {expected}\nGot: {result}" +