]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-69714: Make `calendar` module fully tested (#93655)
authorBart Skowron <bart@bxsx.dev>
Sat, 22 Jul 2023 13:20:40 +0000 (15:20 +0200)
committerGitHub <noreply@github.com>
Sat, 22 Jul 2023 13:20:40 +0000 (15:20 +0200)
commit2aba047f0a2be57cc33a57756707452fdd6a1b3f
treeb638e1823275eb965ff6b6ac688aa62b0a0366fb
parent463b56da1265a17e4207f651d6d5835a8d6de2dd
gh-69714: Make `calendar` module fully tested (#93655)

There are 3 paths to use `locale` argument in
`calendar.Locale{Text|HTML}Calendar.__init__(..., locale=None)`:
(1) `locale=None` -- denotes the "default locale"[1]
(2) `locale=""` -- denotes the native environment
(3) `locale=other_valid_locale` -- denotes a custom locale

So far case (2) is covered and case (1) is in 78935daf5a (same branch).
This commit adds a remaining case (3).

[1] In the current implementation, this translates into the following
approach:

GET current locale
IF current locale == "C" THEN
  SET current locale TO ""
  GET current locale
ENDIF

* Remove unreachable code (and increase test coverage)

This condition cannot be true. `_locale.setlocale()` from the C module
raises `locale.Error` instead of returning `None` for
`different_locale.__enter__` (where `self.oldlocale` is set).

* Expand the try clause to calls to `LocaleTextCalendar.formatmonthname()`.

This method temporarily changes the current locale to the given locale,
so `_locale.setlocale()` may raise `local.Error`.

Co-authored-by: Rohit Mediratta <rohitm@gmail.com>
Co-authored-by: Jessica McKellar <jesstess@mit.edu>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Lib/calendar.py
Lib/test/test_calendar.py
Misc/ACKS
Misc/NEWS.d/next/Tests/2022-06-09-21-27-38.gh-issue-69714.49tyHW.rst [new file with mode: 0644]