Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdcae5cd

Browse files
authored
gh-104400: Add more tests to pygettext (GH-108173)
1 parent556dc9b commitdcae5cd

File tree

8 files changed

+363
-21
lines changed

8 files changed

+363
-21
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) YEAR ORGANIZATION
3+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version:PACKAGE VERSION\n"
8+
"POT-Creation-Date:2000-01-01 00:00+0000\n"
9+
"PO-Revision-Date:YEAR-MO-DA HO:MI+ZONE\n"
10+
"Last-Translator:FULL NAME <EMAIL@ADDRESS>\n"
11+
"Language-Team:LANGUAGE <LL@li.org>\n"
12+
"MIME-Version:1.0\n"
13+
"Content-Type:text/plain; charset=UTF-8\n"
14+
"Content-Transfer-Encoding:8bit\n"
15+
"Generated-By:pygettext.py 1.5\n"
16+
17+
18+
#:docstrings.py:7
19+
#, docstring
20+
msgid""
21+
msgstr""
22+
23+
#:docstrings.py:18
24+
#, docstring
25+
msgid""
26+
"multiline\n"
27+
" docstring\n"
28+
" "
29+
msgstr""
30+
31+
#:docstrings.py:25
32+
#, docstring
33+
msgid"docstring1"
34+
msgstr""
35+
36+
#:docstrings.py:30
37+
#, docstring
38+
msgid"Hello, {}!"
39+
msgstr""
40+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Test docstring extraction
2+
fromgettextimportgettextas_
3+
4+
5+
# Empty docstring
6+
deftest(x):
7+
""""""
8+
9+
10+
# Leading empty line
11+
deftest2(x):
12+
13+
"""docstring"""# XXX This should be extracted but isn't.
14+
15+
16+
# XXX Multiline docstrings should be cleaned with `inspect.cleandoc`.
17+
deftest3(x):
18+
"""multiline
19+
docstring
20+
"""
21+
22+
23+
# Multiple docstrings - only the first should be extracted
24+
deftest4(x):
25+
"""docstring1"""
26+
"""docstring2"""
27+
28+
29+
deftest5(x):
30+
"""Hello, {}!""".format("world!")# XXX This should not be extracted.
31+
32+
33+
# Nested docstrings
34+
deftest6(x):
35+
definner(y):
36+
"""nested docstring"""# XXX This should be extracted but isn't.
37+
38+
39+
classOuter:
40+
classInner:
41+
"nested class docstring"# XXX This should be extracted but isn't.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) YEAR ORGANIZATION
3+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version:PACKAGE VERSION\n"
8+
"POT-Creation-Date:2000-01-01 00:00+0000\n"
9+
"PO-Revision-Date:YEAR-MO-DA HO:MI+ZONE\n"
10+
"Last-Translator:FULL NAME <EMAIL@ADDRESS>\n"
11+
"Language-Team:LANGUAGE <LL@li.org>\n"
12+
"MIME-Version:1.0\n"
13+
"Content-Type:text/plain; charset=UTF-8\n"
14+
"Content-Transfer-Encoding:8bit\n"
15+
"Generated-By:pygettext.py 1.5\n"
16+
17+
18+
#:fileloc.py:5fileloc.py:6
19+
msgid"foo"
20+
msgstr""
21+
22+
#:fileloc.py:9
23+
msgid"bar"
24+
msgstr""
25+
26+
#:fileloc.py:14fileloc.py:18
27+
#, docstring
28+
msgid"docstring"
29+
msgstr""
30+
31+
#:fileloc.py:22fileloc.py:26
32+
#, docstring
33+
msgid"baz"
34+
msgstr""
35+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Test file locations
2+
fromgettextimportgettextas_
3+
4+
# Duplicate strings
5+
_('foo')
6+
_('foo')
7+
8+
# Duplicate strings on the same line should only add one location to the output
9+
_('bar'),_('bar')
10+
11+
12+
# Duplicate docstrings
13+
classA:
14+
"""docstring"""
15+
16+
17+
deff():
18+
"""docstring"""
19+
20+
21+
# Duplicate message and docstring
22+
_('baz')
23+
24+
25+
defg():
26+
"""baz"""
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) YEAR ORGANIZATION
3+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version:PACKAGE VERSION\n"
8+
"POT-Creation-Date:2000-01-01 00:00+0000\n"
9+
"PO-Revision-Date:YEAR-MO-DA HO:MI+ZONE\n"
10+
"Last-Translator:FULL NAME <EMAIL@ADDRESS>\n"
11+
"Language-Team:LANGUAGE <LL@li.org>\n"
12+
"MIME-Version:1.0\n"
13+
"Content-Type:text/plain; charset=UTF-8\n"
14+
"Content-Transfer-Encoding:8bit\n"
15+
"Generated-By:pygettext.py 1.5\n"
16+
17+
18+
#:messages.py:5
19+
msgid""
20+
msgstr""
21+
22+
#:messages.py:8messages.py:9
23+
msgid"parentheses"
24+
msgstr""
25+
26+
#:messages.py:12
27+
msgid"Hello, world!"
28+
msgstr""
29+
30+
#:messages.py:15
31+
msgid""
32+
"Hello,\n"
33+
" multiline!\n"
34+
msgstr""
35+
36+
#:messages.py:29
37+
msgid"Hello, {}!"
38+
msgstr""
39+
40+
#:messages.py:33
41+
msgid"1"
42+
msgstr""
43+
44+
#:messages.py:33
45+
msgid"2"
46+
msgstr""
47+
48+
#:messages.py:34messages.py:35
49+
msgid"A"
50+
msgstr""
51+
52+
#:messages.py:34messages.py:35
53+
msgid"B"
54+
msgstr""
55+
56+
#:messages.py:36
57+
msgid"set"
58+
msgstr""
59+
60+
#:messages.py:42
61+
msgid"nested string"
62+
msgstr""
63+
64+
#:messages.py:47
65+
msgid"baz"
66+
msgstr""
67+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Test message extraction
2+
fromgettextimportgettextas_
3+
4+
# Empty string
5+
_("")
6+
7+
# Extra parentheses
8+
(_("parentheses"))
9+
((_("parentheses")))
10+
11+
# Multiline strings
12+
_("Hello, "
13+
"world!")
14+
15+
_("""Hello,
16+
multiline!
17+
""")
18+
19+
# Invalid arguments
20+
_()
21+
_(None)
22+
_(1)
23+
_(False)
24+
_(x="kwargs are not allowed")
25+
_("foo","bar")
26+
_("something",x="something else")
27+
28+
# .format()
29+
_("Hello, {}!").format("world")# valid
30+
_("Hello, {}!".format("world"))# invalid
31+
32+
# Nested structures
33+
_("1"),_("2")
34+
arr= [_("A"),_("B")]
35+
obj= {'a':_("A"),'b':_("B")}
36+
{{{_('set')}}}
37+
38+
39+
# Nested functions and classes
40+
deftest():
41+
_("nested string")# XXX This should be extracted but isn't.
42+
[_("nested string")]
43+
44+
45+
classFoo:
46+
defbar(self):
47+
return_("baz")
48+
49+
50+
defbar(x=_('default value')):# XXX This should be extracted but isn't.
51+
pass
52+
53+
54+
defbaz(x=[_('default value')]):# XXX This should be extracted but isn't.
55+
pass
56+
57+
58+
# Shadowing _()
59+
def_(x):
60+
pass
61+
62+
63+
def_(x="don't extract me"):
64+
pass

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp