forked from brazilian-utils/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_date.py
More file actions
80 lines (69 loc) · 2.71 KB
/
test_date.py
File metadata and controls
80 lines (69 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from unittest import TestCase
from num2words import num2words
from brutils import convert_date_to_text
from brutils.data.enums.months import MonthsEnum
class TestNum2Words(TestCase):
def test_num_conversion(self) -> None:
"""
Smoke test of the num2words library.
This test is used to guarantee that our dependency still works.
"""
self.assertEqual(num2words(30, lang="pt-br"), "trinta")
self.assertEqual(num2words(42, lang="pt-br"), "quarenta e dois")
self.assertEqual(
num2words(2024, lang="pt-br"), "dois mil e vinte e quatro"
)
self.assertEqual(num2words(0, lang="pt-br"), "zero")
self.assertEqual(num2words(-1, lang="pt-br"), "menos um")
class TestDate(TestCase):
def test_convert_date_to_text(self):
self.assertEqual(
convert_date_to_text("15/08/2024"),
"Quinze de agosto de dois mil e vinte e quatro",
)
self.assertEqual(
convert_date_to_text("01/01/2000"),
"Primeiro de janeiro de dois mil",
)
self.assertEqual(
convert_date_to_text("31/12/1999"),
"Trinta e um de dezembro de mil novecentos e noventa e nove",
)
#
self.assertIsNone(convert_date_to_text("30/02/2020"), None)
self.assertIsNone(convert_date_to_text("30/00/2020"), None)
self.assertIsNone(convert_date_to_text("30/02/2000"), None)
self.assertIsNone(convert_date_to_text("50/09/2000"), None)
self.assertIsNone(convert_date_to_text("25/15/2000"), None)
self.assertIsNone(convert_date_to_text("29/02/2019"), None)
# Invalid date pattern.
self.assertRaises(ValueError, convert_date_to_text, "Invalid")
self.assertRaises(ValueError, convert_date_to_text, "25/1/2020")
self.assertRaises(ValueError, convert_date_to_text, "1924/08/20")
self.assertRaises(ValueError, convert_date_to_text, "5/09/2020")
self.assertEqual(
convert_date_to_text("29/02/2020"),
"Vinte e nove de fevereiro de dois mil e vinte",
)
self.assertEqual(
convert_date_to_text("01/01/1900"),
"Primeiro de janeiro de mil e novecentos",
)
months_year = [
(1, "janeiro"),
(2, "fevereiro"),
(3, "marco"),
(4, "abril"),
(5, "maio"),
(6, "junho"),
(7, "julho"),
(8, "agosto"),
(9, "setembro"),
(10, "outubro"),
(11, "novembro"),
(12, "dezembro"),
]
def testMonthEnum(self):
for number_month, name_month in self.months_year:
month = MonthsEnum(number_month)
self.assertEqual(month.month_name, name_month)