FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add tests for dgettext, dngettext, dpgettext, dnpgettext functions by magic-peach · Pull Request #153887 · python/cpython · GitHub

Repository navigation

Add tests for dgettext, dngettext, dpgettext, dnpgettext functions - #153887

Closed
magic-peach wants to merge 1 commit into
python:mainfrom
magic-peach:add-gettext-domain-tests
Closed

magic-peach wants to merge 1 commit into
python:mainfrom
magic-peach:add-gettext-domain-tests

Conversation

Copy link
Copy Markdown

Summary

This PR adds comprehensive test coverage for the domain-specific gettext functions (dgettext, dngettext, dpgettext, dnpgettext) that were previously untested. This addresses an explicit TODO comment in test_gettext.py that requested tests for these functions.

Changes

  • Removed the TODO comment at lines 13-15 that explicitly requested tests for dgettext
  • Added DGettextTests class with 7 tests for dgettext()
  • Added DnGettextTests class with 7 tests for dngettext()
  • Added DpGettextTests class with 6 tests for dpgettext()
  • Added DnpGettextTests class with 7 tests for dnpgettext()

Test Coverage

Each test class covers:

  • Basic translation functionality
  • Fallback behavior for missing domains
  • Behavior when translations are missing
  • Edge cases (wrong context, large numbers, special characters, multiline strings)

Motivation

The gettext module provides both non-domain-specific functions (gettext, ngettext, pgettext, npgettext) and domain-specific functions (dgettext, dngettext, dpgettext, dnpgettext). While the non-domain functions had test coverage, the domain-specific functions were only tested indirectly through the PluralFormsTests mixin. This PR adds direct, focused tests for each domain-specific function.

The existing TODO comment in the file explicitly requested:

# TODO:
#  - Add new tests, for example for "dgettext"
#  - Tests should have only one assert.

This contribution follows the coding style of the existing tests and uses the same test fixtures (GNU_MO_DATA) that are already defined in the file.

Add comprehensive test coverage for the domain-specific gettext functions
that were previously untested. This addresses the TODO comment in
test_gettext.py that explicitly requested tests for these functions.

Changes:
- Remove TODO comment requesting dgettext tests
- Add DGettextTests class with 7 tests for dgettext()
- Add DnGettextTests class with 7 tests for dngettext()
- Add DpGettextTests class with 6 tests for dpgettext()
- Add DnpGettextTests class with 7 tests for dnpgettext()

Each test covers:
- Basic translation functionality
- Fallback behavior for missing domains
- Behavior when translations are missing
- Edge cases (wrong context, large numbers, special characters)
magic-peach requested a review from tomasr8 as a code owner July 18, 2026 07:52
bedevere-app Bot added the tests Tests in the Lib/test dir label Jul 18, 2026

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

bedevere-app Bot commented Jul 18, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Copy link
Copy Markdown
Member

Duplicate of #134594.

Copy link
Copy Markdown
Author

Closing as this is a duplicate of #134594 (dgettext tests) and #148430 (which covered dgettext, dpgettext, dngettext, and dnpgettext). Thank you for the review feedback from @StanFromIreland.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL