Skip to content

Commit

Permalink
Upper enumerant names
Browse files Browse the repository at this point in the history
Close #18
  • Loading branch information
dahlia committed Jul 24, 2024
1 parent e211deb commit 8cb9c58
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
23 changes: 12 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@ This Python package contains `ISO 4217`_ currency data, represented as
enum_ module which was introduced in 3.4.

>>> from iso4217 import Currency
>>> Currency.usd
<Currency.usd: 'USD'>
>>> Currency.usd.code
>>> Currency.USD
<Currency.USD: 'USD'>
>>> Currency.USD.code
'USD'
>>> Currency.usd.currency_name
>>> Currency.USD.currency_name
'US Dollar'
>>> Currency.usd.exponent # USD has cents
>>> Currency.USD.exponent # USD has cents
2
>>> Currency.jpy
<Currency.jpy: 'JPY'>
>>> Currency.jpy.currency_name
>>> Currency.JPY
<Currency.JPY: 'JPY'>
>>> Currency.JPY.currency_name
'Yen'
>>> Currency.jpy.exponent # JPY has no minor units
>>> Currency.JPY.exponent # JPY has no minor units
0
>>> Currency('KRW') # Get by the code string
<Currency.krw: 'KRW'>
>>> Currency.krw is Currency('KRW')
<Currency.KRW: 'KRW'>
>>> Currency.KRW is Currency('KRW')
True
>>> Currency.krw is Currency.KRW # Lower enumerants are also available

Written by `Hong Minhee`_. Distributed under Public Domain.

Expand Down
1 change: 1 addition & 0 deletions iso4217/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def update_enum_dict(locals_, raw_table):
lcode += '_'
enumerants[lcode] = code
for code, enumerant in enumerants.items():
locals_[enumerant] = enumerant
locals_[code] = enumerant


Expand Down
24 changes: 14 additions & 10 deletions iso4217/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@


def test():
assert Currency.usd.code == 'USD'
assert Currency.usd.number == 840
assert Currency.usd.currency_name == 'US Dollar'
assert Currency.usd.country_names.issuperset(
assert Currency('USD') is Currency.USD
assert Currency.USD.code == 'USD'
assert Currency.USD.number == 840
assert Currency.USD.currency_name == 'US Dollar'
assert Currency.USD.country_names.issuperset(
frozenset(['GUAM', 'UNITED STATES OF AMERICA (THE)'])
)
assert Currency.usd.exponent == 2
assert Currency.jpy.code == 'JPY'
assert Currency.jpy.number == 392
assert Currency.jpy.currency_name == 'Yen'
assert Currency.jpy.country_names == frozenset(['JAPAN'])
assert Currency.jpy.exponent == 0
assert Currency.USD.exponent == 2
assert Currency.usd is Currency.USD
assert Currency('JPY') is Currency.JPY
assert Currency.JPY.code == 'JPY'
assert Currency.JPY.number == 392
assert Currency.JPY.currency_name == 'Yen'
assert Currency.JPY.country_names == frozenset(['JAPAN'])
assert Currency.JPY.exponent == 0
assert Currency.jpy is Currency.JPY


if __name__ == '__main__':
Expand Down

0 comments on commit 8cb9c58

Please sign in to comment.