~homeworkprod/byceps

ref: 1181a35dd06d48c779208a6d2a4b3672dd38d812 byceps/tests/util/test_money.py -rw-r--r-- 1.3 KiB
1181a35d — Jochen Kupperschmidt Ported tests from nose2 to pytest 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
:Copyright: 2006-2017 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from decimal import Decimal

import pytest

from byceps.util.l10n import set_locale
from byceps.util.money import format_euro_amount, to_two_places


@pytest.mark.parametrize('value, expected', [
    (Decimal(      '0.00' ),         '0,00 €'),
    (Decimal(      '0.01' ),         '0,01 €'),
    (Decimal(      '0.5'  ),         '0,50 €'),
    (Decimal(      '1.23' ),         '1,23 €'),
    (Decimal(    '123.45' ),       '123,45 €'),
    (Decimal(    '123.456'),       '123,46 €'),
    (Decimal('1234567'    ), '1.234.567,00 €'),
    (Decimal('1234567.89' ), '1.234.567,89 €'),
])
def test_format_euro_amount(value, expected):
    set_locale('de_DE.UTF-8')

    assert format_euro_amount(value) == expected


@pytest.mark.parametrize('value, expected', [
    (Decimal(       '0'), Decimal(  '0.00')),
    (Decimal(     '0.1'), Decimal(  '0.10')),
    (Decimal(    '0.01'), Decimal(  '0.01')),
    (Decimal(  '0.1234'), Decimal(  '0.12')),
    (Decimal(   '0.009'), Decimal(  '0.01')),
    (Decimal('123.4500'), Decimal('123.45')),
    (Decimal('123.4567'), Decimal('123.46')),
])
def test_to_two_places(value, expected):
    assert to_two_places(value) == expected