Skip to content

Commit

Permalink
Change OLD to ESP and add USD
Browse files Browse the repository at this point in the history
  • Loading branch information
Abranes committed Apr 18, 2018
1 parent ca8def5 commit 45ec843
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
5 changes: 2 additions & 3 deletions num2words/lang_ES.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ 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??
Expand Down Expand Up @@ -171,9 +172,7 @@ def to_ordinal_num(self, value):
return "%s%s" % (value, "º" if self.gender_stem == 'o' else "ª")

def to_currency(self, val, currency='EUR', cents=True, seperator=' con',
adjective=False, old=False):
if old:
currency = 'ESP'
adjective=False):
result = super(Num2Word_ES, self).to_currency(
val, currency=currency, cents=cents, seperator=seperator,
adjective=adjective)
Expand Down
26 changes: 22 additions & 4 deletions tests/test_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
(100.00, 'cien euros con cero centimos'),
)

TEST_CASES_TO_CURRENCY_OLD = (
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'),
Expand All @@ -131,6 +131,17 @@
(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'),
)


class Num2WordsESTest(TestCase):

Expand Down Expand Up @@ -159,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]
)

0 comments on commit 45ec843

Please sign in to comment.