|
13 | 13 |
|
14 | 14 | # 3rd party
|
15 | 15 | import pytest
|
16 |
| -from coincidence import count |
| 16 | +from coincidence.params import count |
17 | 17 |
|
18 | 18 | # this package
|
19 | 19 | from domdf_python_tools import dates
|
20 |
| -from domdf_python_tools.dates import calc_easter, month_full_names |
21 | 20 |
|
22 | 21 | # TODO: test get_timezone
|
23 | 22 |
|
@@ -159,25 +158,68 @@ def test_utc_offset_no_pytz():
|
159 | 158 |
|
160 | 159 | # TODO: Finish
|
161 | 160 |
|
| 161 | +# import sys |
| 162 | +# from importlib.abc import MetaPathFinder |
| 163 | +# |
| 164 | +# class NoPytzPath(MetaPathFinder): |
| 165 | +# |
| 166 | +# def find_spec(self, fullname, path, target=None): |
| 167 | +# if fullname == "pytz": |
| 168 | +# raise ModuleNotFoundError(f"No module named '{fullname}'") |
| 169 | +# |
| 170 | +# |
| 171 | +# class TestDatesNoPytz: |
| 172 | +# |
| 173 | +# def test_import_pytz(self, fake_no_pytz): |
| 174 | +# with pytest.raises(ImportError): |
| 175 | +# import pytz |
| 176 | +# # this package |
| 177 | +# from domdf_python_tools import dates |
| 178 | +# |
| 179 | +# with pytest.raises(ImportError): |
| 180 | +# # 3rd party |
| 181 | +# import pytz |
| 182 | +# |
| 183 | +# def test_utc_offset_no_pytz(self, fake_no_pytz): |
| 184 | +# # this package |
| 185 | +# from domdf_python_tools import dates |
| 186 | +# |
| 187 | +# print(sys.modules.keys()) |
| 188 | +# |
| 189 | +# with pytest.raises( |
| 190 | +# ImportError, |
| 191 | +# match=r"'get_utc_offset' requires pytz \(.*\), but it could not be imported", |
| 192 | +# ): |
| 193 | +# dates.get_utc_offset # pylint: disable=pointless-statement |
| 194 | +# |
| 195 | +# with pytest.raises( |
| 196 | +# ImportError, |
| 197 | +# match=r"'get_utc_offset' requires pytz \(.*\), but it could not be imported", |
| 198 | +# ): |
| 199 | +# |
| 200 | +# # this package |
| 201 | +# from domdf_python_tools.dates import get_utc_offset # noqa: F401 |
| 202 | + |
| 203 | + |
| 204 | +@pytest.mark.parametrize("month_idx, month", enumerate(dates.month_full_names)) |
| 205 | +def test_parse_month(month_idx: int, month: str): |
| 206 | + month_idx += 1 # to make 1-indexed |
162 | 207 |
|
163 |
| -def test_parse_month(): |
164 |
| - for month_idx, month in enumerate(month_full_names): |
165 |
| - |
166 |
| - month_idx += 1 # to make 1-indexed |
| 208 | + for i in range(3, len(month)): |
| 209 | + assert dates.parse_month(month.lower()[:i]) == month |
| 210 | + assert dates.parse_month(month.upper()[:i]) == month |
| 211 | + assert dates.parse_month(month.capitalize()[:i]) == month |
167 | 212 |
|
168 |
| - for i in range(3, len(month)): |
169 |
| - assert dates.parse_month(month.lower()[:i]) == month |
170 |
| - assert dates.parse_month(month.upper()[:i]) == month |
171 |
| - assert dates.parse_month(month.capitalize()[:i]) == month |
| 213 | + assert dates.parse_month(month_idx) == month |
172 | 214 |
|
173 |
| - assert dates.parse_month(month_idx) == month |
174 | 215 |
|
| 216 | +def test_parse_month_errors(): |
175 | 217 | for value in ["abc", 0, '0', -1, "-1", 13, "13"]:
|
176 | 218 | with pytest.raises(ValueError, match=fr"The given month \({value!r}\) is not recognised."):
|
177 | 219 | dates.parse_month(value) # type: ignore
|
178 | 220 |
|
179 | 221 |
|
180 |
| -@pytest.mark.parametrize("month_idx, month", enumerate(month_full_names)) |
| 222 | +@pytest.mark.parametrize("month_idx, month", enumerate(dates.month_full_names)) |
181 | 223 | def test_get_month_number_from_name(month_idx: int, month: str):
|
182 | 224 | month_idx += 1 # to make 1-indexed
|
183 | 225 |
|
@@ -212,7 +254,7 @@ def test_get_month_number_errors(value: Union[str, int], match: str):
|
212 | 254 |
|
213 | 255 |
|
214 | 256 | def test_check_date():
|
215 |
| - for month_idx, month in enumerate(month_full_names): |
| 257 | + for month_idx, month in enumerate(dates.month_full_names): |
216 | 258 |
|
217 | 259 | month_idx += 1 # to make 1-indexed
|
218 | 260 |
|
@@ -282,4 +324,4 @@ def test_check_date():
|
282 | 324 | ]
|
283 | 325 | )
|
284 | 326 | def test_calc_easter(date):
|
285 |
| - assert calc_easter(date.year) == date |
| 327 | + assert dates.calc_easter(date.year) == date |
0 commit comments