-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-31920: Fix pygettext directory walk #4225
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
"""Tests to cover the Tools/i18n package""" | ||
|
||
import os | ||
import re | ||
import sys | ||
import unittest | ||
|
||
from test.support.script_helper import assert_python_ok | ||
from test.test_tools import skip_if_missing, toolsdir | ||
from test.support import temp_cwd | ||
from test.support import temp_cwd, temp_dir | ||
|
||
|
||
skip_if_missing() | ||
|
@@ -72,3 +73,20 @@ def test_POT_Creation_Date(self): | |
|
||
# This will raise if the date format does not exactly match. | ||
datetime.strptime(creationDate, '%Y-%m-%d %H:%M%z') | ||
|
||
def test_files_list(self): | ||
"""Make sure the directories are inspected for source files | ||
bpo-31920 | ||
""" | ||
source_dir = 'pypkg' | ||
text = 'Text to translate' | ||
with temp_cwd(None) as cwd: | ||
with temp_dir(os.path.join(cwd, source_dir)) as sdir: | ||
with open(os.path.join(sdir, 'pymod.py'), 'w') as sfile: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to put the test file deeper in the directory tree, e.g. in |
||
sfile.write('_("{}")'.format(text)) | ||
assert_python_ok(self.script, source_dir) | ||
with open('messages.pot') as fp: | ||
data = fp.read() | ||
msgids = re.findall(r'msgid "(.*?)"', data) | ||
|
||
self.assertIn(text, msgids) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't be simpler to test the containment directly in the file content? self.assertIn('msgid "%s"' % text, data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to use
temp_dir(None)
and test with a path that is not a child of the current directory. If pygettext.py ignores the argument and searches from the current directory, it will pass the current test, but not the test with independent test directory.