Exemplo n.º 1
0
def test_currency_negative():
    """test_currency_negative."""
    amount = -100
    default = Currency(amount=amount)
    decimal = CONTEXT.create_decimal(amount)
    assert default.amount == decimal
    assert default.numeric_code == '0'
    assert default.alpha_code == ''
    assert default.decimal_sign == '.'
    assert default.grouping_sign == ','
    assert not default.international
    assert default.symbol == ''
    assert default.symbol_ahead
    assert default.symbol_separator == ''
    assert default.convertion == ''
    assert default.__hash__() == hash((decimal, '', '0'))
    assert default.__repr__() == ('Currency(amount: -100, '
                                  'alpha_code: "", '
                                  'symbol: "", '
                                  'symbol_ahead: True, '
                                  'symbol_separator: "", '
                                  'numeric_code: "0", '
                                  'decimal_places: "2", '
                                  'decimal_sign: ".", '
                                  'grouping_sign: ",", '
                                  'convertion: "", '
                                  'international: False)')
    assert default.__str__() == '-100.00'
Exemplo n.º 2
0
def test_currency_precision_1():
    """test_currency_precision_1."""
    test_currency = (Currency(1.01) - Currency(0.99)) * 1e18
    assert test_currency.amount == (
        (CONTEXT.create_decimal('1.01') - CONTEXT.create_decimal('0.99')) *
        CONTEXT.create_decimal('1e18'))
    assert test_currency.__str__() == '20,000,000,000,000,000.00'
Exemplo n.º 3
0
def test_currency_slots():
    """test_currency_slots."""
    euro = Currency(amount=1000)
    with raises(AttributeError,
                match=('\'Currency\' '
                       'object has no attribute \'new_variable\'')):
        euro.new_variable = 'fail'  # pylint: disable=assigning-non-slot
Exemplo n.º 4
0
def test_currency_decimal_places():
    """test_currency_decimal_places."""
    euro = Currency(amount=1000,
                    alpha_code='EUR',
                    symbol='€',
                    symbol_ahead=False,
                    symbol_separator='\u00A0',
                    numeric_code='978',
                    decimal_places=-2)
    assert euro.numeric_code == '978'
    assert euro.alpha_code == 'EUR'
    assert euro.decimal_places == 0
    assert not euro.symbol_ahead
    assert euro.symbol_separator == '\u00A0'
    assert not euro.international
    assert euro.__str__() == '1,000\u00A0€'
    assert euro.pstr(-2) == '1,000\u00A0€'
    assert euro.pstr(0) == '1,000\u00A0€'
    assert euro.pstr(1) == '1,000.0\u00A0€'
Exemplo n.º 5
0
def test_currency_convertion():
    """test_currency_convertion."""
    euro = Currency(amount=123456789,
                    alpha_code='EUR',
                    symbol='€',
                    symbol_ahead=False,
                    symbol_separator='\u00A0',
                    numeric_code='978',
                    decimal_places=2,
                    convertion='zabcdefghi-,.')
    assert euro.numeric_code == '978'
    assert euro.alpha_code == 'EUR'
    assert euro.decimal_places == 2
    assert not euro.symbol_ahead
    assert euro.symbol_separator == '\u00A0'
    assert not euro.international
    assert euro.__str__() == 'abc,def,ghi.zz\u00A0€'
    assert euro.pstr(-2) == 'abc,def,ghi\u00A0€'
    assert euro.pstr(0) == 'abc,def,ghi\u00A0€'
    assert euro.pstr(1) == 'abc,def,ghi.z\u00A0€'
Exemplo n.º 6
0
def test_currency_custom():
    """test_currency_custom."""
    amount = 1000
    euro = Currency(amount=amount,
                    alpha_code='EUR',
                    symbol='€',
                    symbol_ahead=False,
                    symbol_separator='\u00A0',
                    numeric_code='978',
                    decimal_places=2,
                    decimal_sign=',',
                    grouping_sign='.',
                    convertion='0123456789-,.',
                    international=True)
    decimal = CONTEXT.create_decimal(amount)
    assert euro.amount == decimal
    assert euro.numeric_code == '978'
    assert euro.alpha_code == 'EUR'
    assert euro.decimal_places == 2
    assert euro.decimal_sign == ','
    assert euro.grouping_sign == '.'
    assert euro.international
    assert euro.symbol == '€'
    assert not euro.symbol_ahead
    assert euro.symbol_separator == '\u00A0'
    assert euro.convertion == '0123456789-,.'
    assert euro.__hash__() == hash((decimal, 'EUR', '978'))
    assert euro.__repr__() == ('Currency(amount: 1000, '
                               'alpha_code: "EUR", '
                               'symbol: "€", '
                               'symbol_ahead: False, '
                               'symbol_separator: "\u00A0", '
                               'numeric_code: "978", '
                               'decimal_places: "2", '
                               'decimal_sign: ",", '
                               'grouping_sign: ".", '
                               'convertion: "0123456789-,.", '
                               'international: True)')
    assert euro.__str__() == 'EUR 1,000.00'
Exemplo n.º 7
0
def test_eurosk_math_add():
    """test_eurosk_math_add."""
    eurosk_one = EuroSK(amount=1)
    eurosk_two = EuroSK(amount=2)
    eurosk_three = EuroSK(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency EUR and OTHER.'):
        _ = eurosk_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'euro.EuroSK\'> '
                       'and <class \'str\'>.')):
        _ = eurosk_one.__add__('1.00')
    assert (eurosk_one + eurosk_two) == eurosk_three
Exemplo n.º 8
0
def test_quetzal_math_add():
    """test_quetzal_math_add."""
    quetzal_one = Quetzal(amount=1)
    quetzal_two = Quetzal(amount=2)
    quetzal_three = Quetzal(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency GTQ and OTHER.'):
        _ = quetzal_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'quetzal.Quetzal\'> '
                       'and <class \'str\'>.')):
        _ = quetzal_one.__add__('1.00')
    assert (quetzal_one + quetzal_two) == quetzal_three
Exemplo n.º 9
0
def test_malagasy_ariary_math_add():
    """test_malagasy_ariary_math_add."""
    malagasy_ariary_one = MalagasyAriary(amount=1)
    malagasy_ariary_two = MalagasyAriary(amount=2)
    malagasy_ariary_three = MalagasyAriary(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency MGA and OTHER.'):
        _ = malagasy_ariary_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'ariary.MalagasyAriary\'> '
                       'and <class \'str\'>.')):
        _ = malagasy_ariary_one.__add__('1.00')
    assert (malagasy_ariary_one + malagasy_ariary_two) == malagasy_ariary_three
Exemplo n.º 10
0
def test_zcash_math_add():
    """test_zcash_math_add."""
    zcash_one = Zcash(amount=1)
    zcash_two = Zcash(amount=2)
    zcash_three = Zcash(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency ZEC and OTHER.'):
        _ = zcash_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'crypto.Zcash\'> '
                       'and <class \'str\'>.')):
        _ = zcash_one.__add__('1.00')
    assert (zcash_one + zcash_two) == zcash_three
Exemplo n.º 11
0
def test_mexican_peso_math_add():
    """test_mexican_peso_math_add."""
    mexican_peso_one = MexicanPeso(amount=1)
    mexican_peso_two = MexicanPeso(amount=2)
    mexican_peso_three = MexicanPeso(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency MXN and OTHER.'):
        _ = mexican_peso_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'peso.MexicanPeso\'> '
                       'and <class \'str\'>.')):
        _ = mexican_peso_one.__add__('1.00')
    assert (mexican_peso_one + mexican_peso_two) == mexican_peso_three
Exemplo n.º 12
0
def test_bahamian_dollar_math_add():
    """test_bahamian_dollar_math_add."""
    bahamian_dollar_one = BahamianDollar(amount=1)
    bahamian_dollar_two = BahamianDollar(amount=2)
    bahamian_dollar_three = BahamianDollar(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency BSD and OTHER.'):
        _ = bahamian_dollar_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'dollar.BahamianDollar\'> '
                       'and <class \'str\'>.')):
        _ = bahamian_dollar_one.__add__('1.00')
    assert (bahamian_dollar_one + bahamian_dollar_two) == bahamian_dollar_three
Exemplo n.º 13
0
def test_ripple_math_add():
    """test_ripple_math_add."""
    ripple_one = Ripple(amount=1)
    ripple_two = Ripple(amount=2)
    ripple_three = Ripple(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency XRP and OTHER.'):
        _ = ripple_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'crypto.Ripple\'> '
                       'and <class \'str\'>.')):
        _ = ripple_one.__add__('1.00')
    assert (ripple_one + ripple_two) == ripple_three
Exemplo n.º 14
0
def test_som_math_add():
    """test_som_math_add."""
    som_one = Som(amount=1)
    som_two = Som(amount=2)
    som_three = Som(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency KGS and OTHER.'):
        _ = som_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'som.Som\'> '
                       'and <class \'str\'>.')):
        _ = som_one.__add__('1.00')
    assert (som_one + som_two) == som_three
Exemplo n.º 15
0
def test_argentine_peso_math_add():
    """test_argentine_peso_math_add."""
    argentine_peso_one = ArgentinePeso(amount=1)
    argentine_peso_two = ArgentinePeso(amount=2)
    argentine_peso_three = ArgentinePeso(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency ARS and OTHER.'):
        _ = argentine_peso_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'peso.ArgentinePeso\'> '
                       'and <class \'str\'>.')):
        _ = argentine_peso_one.__add__('1.00')
    assert (argentine_peso_one + argentine_peso_two) == argentine_peso_three
Exemplo n.º 16
0
def test_denar_math_add():
    """test_denar_math_add."""
    denar_one = Denar(amount=1)
    denar_two = Denar(amount=2)
    denar_three = Denar(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency MKD and OTHER.'):
        _ = denar_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'denar.Denar\'> '
                       'and <class \'str\'>.')):
        _ = denar_one.__add__('1.00')
    assert (denar_one + denar_two) == denar_three
Exemplo n.º 17
0
def test_suriname_dollar_math_add():
    """test_suriname_dollar_math_add."""
    suriname_dollar_one = SurinameDollar(amount=1)
    suriname_dollar_two = SurinameDollar(amount=2)
    suriname_dollar_three = SurinameDollar(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency SRD and OTHER.'):
        _ = suriname_dollar_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'dollar.SurinameDollar\'> '
                       'and <class \'str\'>.')):
        _ = suriname_dollar_one.__add__('1.00')
    assert (suriname_dollar_one + suriname_dollar_two) == suriname_dollar_three
Exemplo n.º 18
0
def test_yemeni_rial_math_add():
    """test_yemeni_rial_math_add."""
    yemeni_rial_one = YemeniRial(amount=1)
    yemeni_rial_two = YemeniRial(amount=2)
    yemeni_rial_three = YemeniRial(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency YER and OTHER.'):
        _ = yemeni_rial_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'rial.YemeniRial\'> '
                       'and <class \'str\'>.')):
        _ = yemeni_rial_one.__add__('1.00')
    assert (yemeni_rial_one + yemeni_rial_two) == yemeni_rial_three
Exemplo n.º 19
0
def test_guinea_franc_math_add():
    """test_guinea_franc_math_add."""
    guinea_franc_one = GuineaFranc(amount=1)
    guinea_franc_two = GuineaFranc(amount=2)
    guinea_franc_three = GuineaFranc(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency GNF and OTHER.'):
        _ = guinea_franc_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'franc.GuineaFranc\'> '
                       'and <class \'str\'>.')):
        _ = guinea_franc_one.__add__('1.00')
    assert (guinea_franc_one + guinea_franc_two) == guinea_franc_three
Exemplo n.º 20
0
def test_ethiopian_birr_math_add():
    """test_ethiopian_birr_math_add."""
    ethiopian_birr_one = EthiopianBirr(amount=1)
    ethiopian_birr_two = EthiopianBirr(amount=2)
    ethiopian_birr_three = EthiopianBirr(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency ETB and OTHER.'):
        _ = ethiopian_birr_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'birr.EthiopianBirr\'> '
                       'and <class \'str\'>.')):
        _ = ethiopian_birr_one.__add__('1.00')
    assert (ethiopian_birr_one + ethiopian_birr_two) == ethiopian_birr_three
Exemplo n.º 21
0
def test_lilangeni_math_add():
    """test_lilangeni_math_add."""
    lilangeni_one = Lilangeni(amount=1)
    lilangeni_two = Lilangeni(amount=2)
    lilangeni_three = Lilangeni(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency SZL and OTHER.'):
        _ = lilangeni_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'lilangeni.Lilangeni\'> '
                       'and <class \'str\'>.')):
        _ = lilangeni_one.__add__('1.00')
    assert (lilangeni_one + lilangeni_two) == lilangeni_three
Exemplo n.º 22
0
def test_sudanese_pound_math_add():
    """test_sudanese_pound_math_add."""
    sudanese_pound_one = SudanesePound(amount=1)
    sudanese_pound_two = SudanesePound(amount=2)
    sudanese_pound_three = SudanesePound(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency SDG and OTHER.'):
        _ = sudanese_pound_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'pound.SudanesePound\'> '
                       'and <class \'str\'>.')):
        _ = sudanese_pound_one.__add__('1.00')
    assert (sudanese_pound_one + sudanese_pound_two) == sudanese_pound_three
Exemplo n.º 23
0
def test_namibia_dollar_math_add():
    """test_namibia_dollar_math_add."""
    namibia_dollar_one = NamibiaDollar(amount=1)
    namibia_dollar_two = NamibiaDollar(amount=2)
    namibia_dollar_three = NamibiaDollar(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency NAD and OTHER.'):
        _ = namibia_dollar_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'dollar.NamibiaDollar\'> '
                       'and <class \'str\'>.')):
        _ = namibia_dollar_one.__add__('1.00')
    assert (namibia_dollar_one + namibia_dollar_two) == namibia_dollar_three
Exemplo n.º 24
0
def test_boliviano_math_add():
    """test_boliviano_math_add."""
    boliviano_one = Boliviano(amount=1)
    boliviano_two = Boliviano(amount=2)
    boliviano_three = Boliviano(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency BOB and OTHER.'):
        _ = boliviano_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'boliviano.Boliviano\'> '
                       'and <class \'str\'>.')):
        _ = boliviano_one.__add__('1.00')
    assert (boliviano_one + boliviano_two) == boliviano_three
Exemplo n.º 25
0
def test_armenian_dram_math_add():
    """test_armenian_dram_math_add."""
    armenian_dram_one = ArmenianDram(amount=1)
    armenian_dram_two = ArmenianDram(amount=2)
    armenian_dram_three = ArmenianDram(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency AMD and OTHER.'):
        _ = armenian_dram_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'dram.ArmenianDram\'> '
                       'and <class \'str\'>.')):
        _ = armenian_dram_one.__add__('1.00')
    assert (armenian_dram_one + armenian_dram_two) == armenian_dram_three
Exemplo n.º 26
0
def test_moroccan_dirham_math_add():
    """test_moroccan_dirham_math_add."""
    moroccan_dirham_one = MoroccanDirham(amount=1)
    moroccan_dirham_two = MoroccanDirham(amount=2)
    moroccan_dirham_three = MoroccanDirham(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency MAD and OTHER.'):
        _ = moroccan_dirham_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'dirham.MoroccanDirham\'> '
                       'and <class \'str\'>.')):
        _ = moroccan_dirham_one.__add__('1.00')
    assert (moroccan_dirham_one + moroccan_dirham_two) == moroccan_dirham_three
Exemplo n.º 27
0
def test_tezos_math_add():
    """test_tezos_math_add."""
    tezos_one = Tezos(amount=1)
    tezos_two = Tezos(amount=2)
    tezos_three = Tezos(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency XTZ and OTHER.'):
        _ = tezos_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'crypto.Tezos\'> '
                       'and <class \'str\'>.')):
        _ = tezos_one.__add__('1.00')
    assert (tezos_one + tezos_two) == tezos_three
Exemplo n.º 28
0
def test_tugrik_math_add():
    """test_tugrik_math_add."""
    tugrik_one = Tugrik(amount=1)
    tugrik_two = Tugrik(amount=2)
    tugrik_three = Tugrik(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency MNT and OTHER.'):
        _ = tugrik_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'tugrik.Tugrik\'> '
                       'and <class \'str\'>.')):
        _ = tugrik_one.__add__('1.00')
    assert (tugrik_one + tugrik_two) == tugrik_three
Exemplo n.º 29
0
def test_rand_za_math_add():
    """test_rand_za_math_add."""
    rand_za_one = RandZA(amount=1)
    rand_za_two = RandZA(amount=2)
    rand_za_three = RandZA(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency ZAR and OTHER.'):
        _ = rand_za_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'rand.RandZA\'> '
                       'and <class \'str\'>.')):
        _ = rand_za_one.__add__('1.00')
    assert (rand_za_one + rand_za_two) == rand_za_three
Exemplo n.º 30
0
def test_moldovan_leu_math_add():
    """test_moldovan_leu_math_add."""
    moldovan_leu_one = MoldovanLeu(amount=1)
    moldovan_leu_two = MoldovanLeu(amount=2)
    moldovan_leu_three = MoldovanLeu(amount=3)
    currency = Currency(amount=1, alpha_code='OTHER')
    with raises(CurrencyMismatchException,
                match='unsupported operation between currency MDL and OTHER.'):
        _ = moldovan_leu_one + currency
    with raises(CurrencyTypeException,
                match=('unsupported operation between <class \'multicurrency.'
                       'leu.MoldovanLeu\'> '
                       'and <class \'str\'>.')):
        _ = moldovan_leu_one.__add__('1.00')
    assert (moldovan_leu_one + moldovan_leu_two) == moldovan_leu_three