| 1 |
import datetime |
| 2 |
from decimal import Decimal |
| 3 |
|
| 4 |
import pytest |
| 5 |
|
| 6 |
from babel import support |
| 7 |
|
| 8 |
|
| 9 |
@pytest.fixture |
| 10 |
def ar_eg_format() -> support.Format: |
| 11 |
return support.Format('ar_EG', numbering_system="default") |
| 12 |
|
| 13 |
|
| 14 |
@pytest.fixture |
| 15 |
def en_us_format(timezone_getter) -> support.Format: |
| 16 |
return support.Format('en_US', tzinfo=timezone_getter('US/Eastern')) |
| 17 |
|
| 18 |
|
| 19 |
def test_format_datetime(en_us_format): |
| 20 |
when = datetime.datetime(2007, 4, 1, 15, 30) |
| 21 |
assert en_us_format.datetime(when) == 'Apr 1, 2007, 11:30:00\u202fAM' |
| 22 |
|
| 23 |
|
| 24 |
def test_format_time(en_us_format): |
| 25 |
when = datetime.datetime(2007, 4, 1, 15, 30) |
| 26 |
assert en_us_format.time(when) == '11:30:00\u202fAM' |
| 27 |
|
| 28 |
|
| 29 |
def test_format_number(ar_eg_format, en_us_format): |
| 30 |
assert en_us_format.number(1234) == '1,234' |
| 31 |
assert ar_eg_format.number(1234) == '1٬234' |
| 32 |
|
| 33 |
|
| 34 |
def test_format_decimal(ar_eg_format, en_us_format): |
| 35 |
assert en_us_format.decimal(1234.5) == '1,234.5' |
| 36 |
assert en_us_format.decimal(Decimal("1234.5")) == '1,234.5' |
| 37 |
assert ar_eg_format.decimal(1234.5) == '1٬234٫5' |
| 38 |
assert ar_eg_format.decimal(Decimal("1234.5")) == '1٬234٫5' |
| 39 |
|
| 40 |
|
| 41 |
def test_format_compact_decimal(ar_eg_format, en_us_format): |
| 42 |
assert en_us_format.compact_decimal(1234) == '1K' |
| 43 |
assert ar_eg_format.compact_decimal(1234, fraction_digits=1) == '1٫2\xa0ألف' |
| 44 |
assert ar_eg_format.compact_decimal(Decimal("1234"), fraction_digits=1) == '1٫2\xa0ألف' |
| 45 |
|
| 46 |
|
| 47 |
def test_format_currency(ar_eg_format, en_us_format): |
| 48 |
assert en_us_format.currency(1099.98, 'USD') == '$1,099.98' |
| 49 |
assert en_us_format.currency(Decimal("1099.98"), 'USD') == '$1,099.98' |
| 50 |
assert ar_eg_format.currency(1099.98, 'EGP') == '\u200f1٬099٫98\xa0ج.م.\u200f' |
| 51 |
|
| 52 |
|
| 53 |
def test_format_compact_currency(ar_eg_format, en_us_format): |
| 54 |
assert en_us_format.compact_currency(1099.98, 'USD') == '$1K' |
| 55 |
assert en_us_format.compact_currency(Decimal("1099.98"), 'USD') == '$1K' |
| 56 |
assert ar_eg_format.compact_currency(1099.98, 'EGP') == '\u200f1\xa0ألف\xa0ج.م.\u200f' |
| 57 |
|
| 58 |
|
| 59 |
def test_format_percent(ar_eg_format, en_us_format): |
| 60 |
assert en_us_format.percent(0.34) == '34%' |
| 61 |
assert en_us_format.percent(Decimal("0.34")) == '34%' |
| 62 |
assert ar_eg_format.percent(134.5) == '13٬450%' |
| 63 |
|
| 64 |
|
| 65 |
def test_format_scientific(ar_eg_format, en_us_format): |
| 66 |
assert en_us_format.scientific(10000) == '1E4' |
| 67 |
assert en_us_format.scientific(Decimal("10000")) == '1E4' |
| 68 |
assert ar_eg_format.scientific(10000) == '1أس4' |