| 1 |
import pytest |
| 2 |
|
| 3 |
from babel import lists, units |
| 4 |
|
| 5 |
|
| 6 |
@pytest.mark.parametrize(('list', 'locale', 'expected'), [ |
| 7 |
([], 'en', ''), |
| 8 |
(['string'], 'en', 'string'), |
| 9 |
(['string1', 'string2'], 'en', 'string1 and string2'), |
| 10 |
(['string1', 'string2', 'string3'], 'en', 'string1, string2, and string3'), |
| 11 |
(['string1', 'string2', 'string3'], 'zh', 'string1、string2和string3'), |
| 12 |
(['string1', 'string2', 'string3', 'string4'], 'ne', 'string1, string2, string3 र string4'), |
| 13 |
]) |
| 14 |
def test_format_list(list, locale, expected): |
| 15 |
assert lists.format_list(list, locale=locale) == expected |
| 16 |
|
| 17 |
|
| 18 |
def test_format_list_error(): |
| 19 |
with pytest.raises(ValueError): |
| 20 |
lists.format_list(['a', 'b', 'c'], style='orange', locale='en') |
| 21 |
|
| 22 |
|
| 23 |
def test_issue_1098(): |
| 24 |
one_foot = units.format_unit(1, "length-foot", length="short", locale="zh_CN") |
| 25 |
five_inches = units.format_unit(5, "length-inch", length="short", locale="zh_CN") |
| 26 |
# zh-CN does not specify the "unit" style, so we fall back to "unit-short" style. |
| 27 |
assert ( |
| 28 |
lists.format_list([one_foot, five_inches], style="unit", locale="zh_CN") == |
| 29 |
lists.format_list([one_foot, five_inches], style="unit-short", locale="zh_CN") == |
| 30 |
# Translation verified using Google Translate. It would add more spacing, but the glyphs are correct. |
| 31 |
"1英尺5英寸" |
| 32 |
) |
| 33 |
|
| 34 |
|
| 35 |
def test_lists_default_locale_deprecation(): |
| 36 |
with pytest.warns(DeprecationWarning): |
| 37 |
_ = lists.DEFAULT_LOCALE |