Skip to content

gh-130655: Add tests for dgettext, dngettext, dpgettext, dnpgettext#154006

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

gh-130655: Add tests for dgettext, dngettext, dpgettext, dnpgettext#154006
magic-peach wants to merge 1 commit into
python:mainfrom
magic-peach:improve-gettext-domain-tests

Conversation

@magic-peach

@magic-peach magic-peach commented Jul 18, 2026

Copy link
Copy Markdown

Summary

  • Add focused test coverage for dgettext, dngettext, dpgettext, and dnpgettext
  • Updates TODO comment with issue reference and additional function names

Motivation

This addresses the TODO at Lib/test/test_gettext.py:13-15 and extends the work in gh-134594 to cover all four domain-specific gettext functions.

Design

Each function is tested with a single test method using a for loop and subTest for clear failure reporting, following reviewer feedback:

  • DGettextTests (7 cases): translations, missing translations, nonexistent domains, empty domain
  • DnGettextTests (6 cases): singular/plural selection, nonexistent domains
  • DpGettextTests (5 cases): context-based translations, wrong contexts, nonexistent domains
  • DnpGettextTests (7 cases): context + plural forms, wrong contexts, nonexistent domains

All test classes inherit from GettextBaseTest to reuse existing .mo test fixtures. Tests follow reviewer feedback:

  • No docstrings on test methods
  • super().setUp() instead of explicit parent call
  • Expected values stored directly (no computation in assertions)
  • Concise structure reflecting that these are simple wrappers

All 25 test assertions verified passing against the current main.

…text

Add focused test coverage for the domain-specific gettext functions
that were previously only tested indirectly. This extends the work
started in pythongh-134594 to cover all four domain-specific functions.

Each function is tested with a for loop and subTests covering:
- Existing translations
- Missing translations (fallback to original message)
- Nonexistent domains (fallback to original message)
- Context-based translations (dpgettext, dnpgettext)
- Plural forms (dngettext, dnpgettext)
- Wrong/missing contexts

Updated the TODO comment to reference the issue and additional
functions that now have coverage.
@magic-peach
magic-peach requested a review from tomasr8 as a code owner July 18, 2026 15:32
@python-cla-bot

Copy link
Copy Markdown

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

CLA not signed

@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label Jul 18, 2026
@bedevere-app

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.

@picnixz

picnixz commented Jul 18, 2026

Copy link
Copy Markdown
Member

Usually, it is common to first ask on the original PR whether the author intends to pursue their work before creating a similar PR. Please discuss this in #134594.

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