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

Add more tests to base.py #283

Merged
merged 4 commits into from
Dec 31, 2019
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
2 changes: 1 addition & 1 deletion num2words/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def float2tuple(self, value):
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))
Expand Down
26 changes: 26 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,29 @@ def setUpClass(cls):
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("one"),
"one"
)
self.base.is_title = True
self.assertEqual(
self.base.title("one"),
"One"
)