Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-104400: Add more tests to pygettext #108173

Merged
merged 21 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Lib/test/test_tools/i18n_data/docstrings.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2000-01-01 00:00+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"


#: docstrings.py:7
#, docstring
msgid ""
msgstr ""

#: docstrings.py:18
#, docstring
msgid ""
"multiline\n"
" docstring\n"
" "
msgstr ""

#: docstrings.py:25
#, docstring
msgid "docstring1"
msgstr ""

#: docstrings.py:30
#, docstring
msgid "Hello, {}!"
msgstr ""

41 changes: 41 additions & 0 deletions Lib/test/test_tools/i18n_data/docstrings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Test docstring extraction
from gettext import gettext as _


# Empty docstring
def test(x):
""""""


# Leading empty line
def test2(x):

"""docstring""" # XXX This should be extracted but isn't.


# XXX Multiline docstrings should be cleaned with `inspect.cleandoc`.
def test3(x):
"""multiline
docstring
"""


# Multiple docstrings - only the first should be extracted
def test4(x):
"""docstring1"""
"""docstring2"""


def test5(x):
"""Hello, {}!""".format("world!") # XXX This should not be extracted.


# Nested docstrings
def test6(x):
def inner(y):
"""nested docstring""" # XXX This should be extracted but isn't.


class Outer:
class Inner:
"nested class docstring" # XXX This should be extracted but isn't.
35 changes: 35 additions & 0 deletions Lib/test/test_tools/i18n_data/fileloc.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2000-01-01 00:00+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"


#: fileloc.py:5 fileloc.py:6
msgid "foo"
msgstr ""

#: fileloc.py:9
msgid "bar"
msgstr ""

#: fileloc.py:14 fileloc.py:18
#, docstring
msgid "docstring"
msgstr ""

#: fileloc.py:22 fileloc.py:26
#, docstring
msgid "baz"
msgstr ""

26 changes: 26 additions & 0 deletions Lib/test/test_tools/i18n_data/fileloc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Test file locations
from gettext import gettext as _

# Duplicate strings
_('foo')
_('foo')

# Duplicate strings on the same line should only add one location to the output
_('bar'), _('bar')


# Duplicate docstrings
class A:
"""docstring"""


def f():
"""docstring"""


# Duplicate message and docstring
_('baz')


def g():
"""baz"""
67 changes: 67 additions & 0 deletions Lib/test/test_tools/i18n_data/messages.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2000-01-01 00:00+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"


#: messages.py:5
msgid ""
msgstr ""

#: messages.py:8 messages.py:9
msgid "parentheses"
msgstr ""

#: messages.py:12
msgid "Hello, world!"
msgstr ""

#: messages.py:15
msgid ""
"Hello,\n"
" multiline!\n"
msgstr ""

#: messages.py:29
msgid "Hello, {}!"
msgstr ""

#: messages.py:33
msgid "1"
msgstr ""

#: messages.py:33
msgid "2"
msgstr ""

#: messages.py:34 messages.py:35
msgid "A"
msgstr ""

#: messages.py:34 messages.py:35
msgid "B"
msgstr ""

#: messages.py:36
msgid "set"
msgstr ""

#: messages.py:42
msgid "nested string"
msgstr ""

#: messages.py:47
msgid "baz"
msgstr ""

64 changes: 64 additions & 0 deletions Lib/test/test_tools/i18n_data/messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Test message extraction
from gettext import gettext as _

# Empty string
_("")

# Extra parentheses
(_("parentheses"))
((_("parentheses")))

# Multiline strings
_("Hello, "
"world!")

_("""Hello,
multiline!
""")

# Invalid arguments
_()
_(None)
_(1)
_(False)
_(x="kwargs are not allowed")
_("foo", "bar")
_("something", x="something else")

# .format()
_("Hello, {}!").format("world") # valid
_("Hello, {}!".format("world")) # invalid

# Nested structures
_("1"), _("2")
arr = [_("A"), _("B")]
obj = {'a': _("A"), 'b': _("B")}
{{{_('set')}}}


# Nested functions and classes
def test():
_("nested string") # XXX This should be extracted but isn't.
[_("nested string")]


class Foo:
def bar(self):
return _("baz")


def bar(x=_('default value')): # XXX This should be extracted but isn't.
pass


def baz(x=[_('default value')]): # XXX This should be extracted but isn't.
pass


# Shadowing _()
def _(x):
pass


def _(x="don't extract me"):
pass
Loading
Loading