Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change implementation of to_currency() in es_ES #167

Merged
merged 3 commits into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions num2words/lang_ES.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@


class Num2Word_ES(Num2Word_EU):
CURRENCY_FORMS = {
'EUR': (('euro', 'euros'), ('centimo', 'centimos')),
'ESP': (('peseta', 'pesetas'), ('centimo', 'centimos')),
'USD': (('dolar', 'dolares'), ('centavo', 'centavos')),
}

# //CHECK: Is this sufficient??
def set_high_numwords(self, high):
max = 3 + 6 * len(high)
Expand Down Expand Up @@ -165,11 +171,10 @@ def to_ordinal_num(self, value):
self.verify_ordinal(value)
return "%s%s" % (value, "º" if self.gender_stem == 'o' else "ª")

def to_currency(self, val, longval=True, old=False):
hightxt, lowtxt = "euro/s", "centavo/s"
if old:
hightxt, lowtxt = "peso/s", "peseta/s"
result = self.to_splitnum(val, hightxt=hightxt, lowtxt=lowtxt,
divisor=1, jointxt="y", longval=longval)
def to_currency(self, val, currency='EUR', cents=True, seperator=' con',
adjective=False):
result = super(Num2Word_ES, self).to_currency(
val, currency=currency, cents=cents, seperator=seperator,
adjective=adjective)
# Handle exception, in spanish is "un euro" and not "uno euro"
return result.replace("uno", "un")
56 changes: 38 additions & 18 deletions tests/test_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,36 @@
)

TEST_CASES_TO_CURRENCY = (
(1, 'un euro'),
(2, 'dos euros'),
(8, 'ocho euros'),
(12, 'doce euros'),
(21, 'veintiun euros'),
(81.25, 'ochenta y un euros y veinticinco centavos'),
(100, 'cien euros'),
(1.00, 'un euro con cero centimos'),
(2.00, 'dos euros con cero centimos'),
(8.00, 'ocho euros con cero centimos'),
(12.00, 'doce euros con cero centimos'),
(21.00, 'veintiun euros con cero centimos'),
(81.25, 'ochenta y un euros con veinticinco centimos'),
(350.90, 'trescientos cincuenta euros con noventa centimos'),
(100.00, 'cien euros con cero centimos'),
)

TEST_CASES_TO_CURRENCY_OLD = (
(1, 'un peso'),
(2, 'dos pesos'),
(8, 'ocho pesos'),
(12, 'doce pesos'),
(21, 'veintiun pesos'),
(81.25, 'ochenta y un pesos y veinticinco pesetas'),
(100, 'cien pesos'),
TEST_CASES_TO_CURRENCY_ESP = (
(1.00, 'un peseta con cero centimos'),
(2.00, 'dos pesetas con cero centimos'),
(8.00, 'ocho pesetas con cero centimos'),
(12.00, 'doce pesetas con cero centimos'),
(21.00, 'veintiun pesetas con cero centimos'),
(81.25, 'ochenta y un pesetas con veinticinco centimos'),
(350.90, 'trescientos cincuenta pesetas con noventa centimos'),
(100.00, 'cien pesetas con cero centimos'),
)

TEST_CASES_TO_CURRENCY_USD = (
(1.00, 'un dolar con cero centavos'),
(2.00, 'dos dolares con cero centavos'),
(8.00, 'ocho dolares con cero centavos'),
(12.00, 'doce dolares con cero centavos'),
(21.00, 'veintiun dolares con cero centavos'),
(81.25, 'ochenta y un dolares con veinticinco centavos'),
(350.90, 'trescientos cincuenta dolares con noventa centavos'),
(100.00, 'cien dolares con cero centavos'),
)


Expand Down Expand Up @@ -157,9 +170,16 @@ def test_currency(self):
test[1]
)

def test_currency_old(self):
for test in TEST_CASES_TO_CURRENCY_OLD:
def test_currency_esp(self):
for test in TEST_CASES_TO_CURRENCY_ESP:
self.assertEqual(
num2words(test[0], lang='es', to='currency', currency='ESP'),
test[1]
)

def test_currency_usd(self):
for test in TEST_CASES_TO_CURRENCY_USD:
self.assertEqual(
num2words(test[0], lang='es', to='currency', old=True),
num2words(test[0], lang='es', to='currency', currency='USD'),
test[1]
)