| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from babel.lists import format_list |
| 4 |
|
| 5 |
TWO = ["omena", "peruna"] |
| 6 |
FIVE = ["omena", "peruna", "aplari", "kurpitsa", "porkkana"] |
| 7 |
|
| 8 |
|
| 9 |
def test_format_list_two(benchmark, fi_locale): |
| 10 |
# Two items hit the special-cased "2" pattern. |
| 11 |
assert benchmark(lambda: format_list(TWO, locale=fi_locale)) == "omena ja peruna" |
| 12 |
|
| 13 |
|
| 14 |
def test_format_list_five(benchmark, fi_locale): |
| 15 |
assert ( |
| 16 |
benchmark(lambda: format_list(FIVE, locale=fi_locale)) |
| 17 |
== "omena, peruna, aplari, kurpitsa ja porkkana" |
| 18 |
) |
| 19 |
|
| 20 |
|
| 21 |
def test_format_list_or(benchmark, fi_locale): |
| 22 |
assert ( |
| 23 |
benchmark(lambda: format_list(FIVE, "or", locale=fi_locale)) |
| 24 |
== "omena, peruna, aplari, kurpitsa tai porkkana" |
| 25 |
) |
| 26 |
|
| 27 |
|
| 28 |
def test_format_list_style_fallback(benchmark, fi_locale): |
| 29 |
# fi has no "standard-short" list patterns, so this falls back to "standard". |
| 30 |
assert ( |
| 31 |
benchmark(lambda: format_list(FIVE, "standard-short", locale=fi_locale)) |
| 32 |
== "omena, peruna, aplari, kurpitsa ja porkkana" |
| 33 |
) |