From 601e8cee848ee1ba382827a9d59853519383d7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Jos=C3=A9=20Moreno=20Reyes?= Date: Fri, 25 Oct 2019 19:38:55 -0600 Subject: [PATCH 1/3] Add AttributeError to to_cardinal_float MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: William José Moreno Reyes --- num2words/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/num2words/base.py b/num2words/base.py index 025e014..ccf5248 100644 --- a/num2words/base.py +++ b/num2words/base.py @@ -139,7 +139,7 @@ class Num2Word_Base(object): def to_cardinal_float(self, value): try: float(value) == value - except (ValueError, TypeError, AssertionError): + except (ValueError, TypeError, AssertionError, AttributeError): raise TypeError(self.errmsg_nonnum % value) pre, post = self.float2tuple(float(value)) From e90061af65379b4bd4700abbed1dd40b2c4e9005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Jos=C3=A9=20Moreno=20Reyes?= Date: Fri, 25 Oct 2019 17:44:57 -0600 Subject: [PATCH 2/3] Add more tests to cover num2words/base.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix: - https://github.com/savoirfairelinux/num2words/issues/125 Signed-off-by: William José Moreno Reyes --- tests/test_base.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_base.py b/tests/test_base.py index ea7701c..d043066 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -32,3 +32,29 @@ class Num2WordBaseTest(TestCase): def test_to_currency_not_implemented(self): with self.assertRaises(NotImplementedError): self.base.to_currency(Decimal('1.00'), currency='EUR') + + def test_error_to_cardinal_float(self): + from num2words.base import Num2Word_Base + with self.assertRaises(TypeError): + Num2Word_Base.to_cardinal_float(9) + with self.assertRaises(TypeError): + Num2Word_Base.to_cardinal_float("a") + + def test_error_merge(self): + from num2words.base import Num2Word_Base + self.base = Num2Word_Base() + with self.assertRaises(NotImplementedError): + self.base.merge(2, 3) + + def test_is_title(self): + from num2words.base import Num2Word_Base + self.base = Num2Word_Base() + self.assertEqual( + self.base.title(9), + 9 + ) + self.base.is_title = True + self.assertEqual( + self.base.title("ii"), + "Ii" + ) From a1d29fc2bcb6d5878db997c31bc7ef00aff3d879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Jos=C3=A9=20Moreno=20Reyes?= Date: Fri, 25 Oct 2019 20:52:30 -0600 Subject: [PATCH 3/3] Update to title test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: William José Moreno Reyes --- tests/test_base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_base.py b/tests/test_base.py index d043066..bd9cbd1 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -50,11 +50,11 @@ class Num2WordBaseTest(TestCase): from num2words.base import Num2Word_Base self.base = Num2Word_Base() self.assertEqual( - self.base.title(9), - 9 + self.base.title("one"), + "one" ) self.base.is_title = True self.assertEqual( - self.base.title("ii"), - "Ii" + self.base.title("one"), + "One" )