|
2 | 2 | from unittest import TestCase |
3 | 3 | from unittest.mock import patch |
4 | 4 |
|
| 5 | +from num2words import num2words |
| 6 | + |
| 7 | +from brutils import convert_date_to_text |
| 8 | +from brutils.data.enums.months import MonthsEnum |
5 | 9 | from brutils.date_utils import is_holiday |
6 | 10 |
|
7 | 11 |
|
@@ -92,3 +96,78 @@ def test_data_sem_uf(self, mock_is_holiday): |
92 | 96 | self.assertFalse( |
93 | 97 | is_holiday(datetime(2024, 7, 9)) |
94 | 98 | ) # Data estadual de SP, sem UF |
| 99 | + |
| 100 | + |
| 101 | +class TestNum2Words(TestCase): |
| 102 | + def test_num_conversion(self) -> None: |
| 103 | + """ |
| 104 | + Smoke test of the num2words library. |
| 105 | + This test is used to guarantee that our dependency still works. |
| 106 | + """ |
| 107 | + self.assertEqual(num2words(30, lang="pt-br"), "trinta") |
| 108 | + self.assertEqual(num2words(42, lang="pt-br"), "quarenta e dois") |
| 109 | + self.assertEqual( |
| 110 | + num2words(2024, lang="pt-br"), "dois mil e vinte e quatro" |
| 111 | + ) |
| 112 | + self.assertEqual(num2words(0, lang="pt-br"), "zero") |
| 113 | + self.assertEqual(num2words(-1, lang="pt-br"), "menos um") |
| 114 | + |
| 115 | + |
| 116 | +class TestConvertDateToText(TestCase): |
| 117 | + def test_convert_date_to_text(self): |
| 118 | + self.assertEqual( |
| 119 | + convert_date_to_text("15/08/2024"), |
| 120 | + "Quinze de agosto de dois mil e vinte e quatro", |
| 121 | + ) |
| 122 | + self.assertEqual( |
| 123 | + convert_date_to_text("01/01/2000"), |
| 124 | + "Primeiro de janeiro de dois mil", |
| 125 | + ) |
| 126 | + self.assertEqual( |
| 127 | + convert_date_to_text("31/12/1999"), |
| 128 | + "Trinta e um de dezembro de mil novecentos e noventa e nove", |
| 129 | + ) |
| 130 | + |
| 131 | + self.assertIsNone(convert_date_to_text("30/02/2020"), None) |
| 132 | + self.assertIsNone(convert_date_to_text("30/00/2020"), None) |
| 133 | + self.assertIsNone(convert_date_to_text("30/02/2000"), None) |
| 134 | + self.assertIsNone(convert_date_to_text("50/09/2000"), None) |
| 135 | + self.assertIsNone(convert_date_to_text("25/15/2000"), None) |
| 136 | + self.assertIsNone(convert_date_to_text("29/02/2019"), None) |
| 137 | + |
| 138 | + # Invalid date pattern. |
| 139 | + self.assertIsNone(convert_date_to_text("Invalid")) |
| 140 | + self.assertIsNone(convert_date_to_text("25/1/2020")) |
| 141 | + self.assertIsNone(convert_date_to_text("1924/08/20")) |
| 142 | + self.assertIsNone(convert_date_to_text("5/09/2020")) |
| 143 | + self.assertIsNone(convert_date_to_text("00/09/2020")) |
| 144 | + self.assertIsNone(convert_date_to_text("32/09/2020")) |
| 145 | + |
| 146 | + self.assertEqual( |
| 147 | + convert_date_to_text("29/02/2020"), |
| 148 | + "Vinte e nove de fevereiro de dois mil e vinte", |
| 149 | + ) |
| 150 | + self.assertEqual( |
| 151 | + convert_date_to_text("01/01/1900"), |
| 152 | + "Primeiro de janeiro de mil e novecentos", |
| 153 | + ) |
| 154 | + |
| 155 | + months_year = [ |
| 156 | + (1, "janeiro"), |
| 157 | + (2, "fevereiro"), |
| 158 | + (3, "marco"), |
| 159 | + (4, "abril"), |
| 160 | + (5, "maio"), |
| 161 | + (6, "junho"), |
| 162 | + (7, "julho"), |
| 163 | + (8, "agosto"), |
| 164 | + (9, "setembro"), |
| 165 | + (10, "outubro"), |
| 166 | + (11, "novembro"), |
| 167 | + (12, "dezembro"), |
| 168 | + ] |
| 169 | + |
| 170 | + def testMonthEnum(self): |
| 171 | + for number_month, name_month in self.months_year: |
| 172 | + month = MonthsEnum(number_month) |
| 173 | + self.assertEqual(month.month_name, name_month) |
0 commit comments