-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Babel now supports extraction by filename as well as by directory.
- Loading branch information
Eoin Nugent
committed
Jan 14, 2016
1 parent
a4cd0e3
commit 4b0d4c5
Showing
3 changed files
with
178 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,8 +108,13 @@ def test_both_sort_output_and_sort_by_file(self): | |
self.cmd.sort_by_file = True | ||
self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) | ||
|
||
def test_input_dirs_is_treated_as_list(self): | ||
self.cmd.input_dirs = self.datadir | ||
def test_invalid_file_or_dir_input_path(self): | ||
self.cmd.input_paths = 'nonexistent_path' | ||
self.cmd.output_file = 'dummy' | ||
self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) | ||
|
||
def test_input_paths_is_treated_as_list(self): | ||
self.cmd.input_paths = self.datadir | ||
self.cmd.output_file = self._pot_file() | ||
self.cmd.finalize_options() | ||
self.cmd.run() | ||
|
@@ -120,12 +125,12 @@ def test_input_dirs_is_treated_as_list(self): | |
self.assertEqual(1, len(msg.locations)) | ||
self.assertTrue('file1.py' in msg.locations[0][0]) | ||
|
||
def test_input_dirs_handle_spaces_after_comma(self): | ||
self.cmd.input_dirs = 'foo, bar' | ||
def test_input_paths_handle_spaces_after_comma(self): | ||
self.cmd.input_paths = '%s, %s' % (this_dir, self.datadir) | ||
self.cmd.output_file = self._pot_file() | ||
self.cmd.finalize_options() | ||
|
||
self.assertEqual(['foo', 'bar'], self.cmd.input_dirs) | ||
self.assertEqual([this_dir, self.datadir], self.cmd.input_paths) | ||
|
||
def test_extraction_with_default_mapping(self): | ||
self.cmd.copyright_holder = 'FooBar, Inc.' | ||
|
@@ -861,6 +866,54 @@ def test_extract_with_mapping_file(self): | |
msgstr[0] "" | ||
msgstr[1] "" | ||
""" % {'version': VERSION, | ||
'year': time.strftime('%Y'), | ||
'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', | ||
tzinfo=LOCALTZ, locale='en')} | ||
with open(pot_file, 'U') as f: | ||
actual_content = f.read() | ||
self.assertEqual(expected_content, actual_content) | ||
|
||
def test_extract_with_exact_file(self): | ||
"""Tests that we can call extract with a particular file and only | ||
strings from that file get extracted. (Note the absence of strings from file1.py) | ||
""" | ||
pot_file = self._pot_file() | ||
file_to_extract = os.path.join(self.datadir, 'project', 'file2.py') | ||
self.cli.run(sys.argv + ['extract', | ||
'--copyright-holder', 'FooBar, Inc.', | ||
'--project', 'TestProject', '--version', '0.1', | ||
'--msgid-bugs-address', '[email protected]', | ||
'--mapping', os.path.join(self.datadir, 'mapping.cfg'), | ||
'-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', | ||
'-o', pot_file, file_to_extract]) | ||
self.assert_pot_file_exists() | ||
expected_content = r"""# Translations template for TestProject. | ||
# Copyright (C) %(year)s FooBar, Inc. | ||
# This file is distributed under the same license as the TestProject | ||
# project. | ||
# FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. | ||
# | ||
#, fuzzy | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: TestProject 0.1\n" | ||
"Report-Msgid-Bugs-To: [email protected]\n" | ||
"POT-Creation-Date: %(date)s\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: Babel %(version)s\n" | ||
#: project/file2.py:9 | ||
msgid "foobar" | ||
msgid_plural "foobars" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
""" % {'version': VERSION, | ||
'year': time.strftime('%Y'), | ||
'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', | ||
|