[Checkins] SVN: zope.app.locales/trunk/src/zope/app/locales/ More robust base_dir stripping, more tests.
Marius Gedminas
marius at pov.lt
Mon Dec 12 14:16:16 UTC 2011
Log message for revision 123773:
More robust base_dir stripping, more tests.
Changed:
U zope.app.locales/trunk/src/zope/app/locales/extract.py
U zope.app.locales/trunk/src/zope/app/locales/tests.py
-=-
Modified: zope.app.locales/trunk/src/zope/app/locales/extract.py
===================================================================
--- zope.app.locales/trunk/src/zope/app/locales/extract.py 2011-12-12 14:05:33 UTC (rev 123772)
+++ zope.app.locales/trunk/src/zope/app/locales/extract.py 2011-12-12 14:16:15 UTC (rev 123773)
@@ -160,9 +160,10 @@
if msgid not in self.catalog:
self.catalog[msgid] = POTEntry(msgid)
+ if base_dir:
+ locations = [(strip_base_dir(filename, base_dir), lineno)
+ for filename, lineno in locations]
for filename, lineno in sorted(locations):
- if base_dir is not None:
- filename = filename.replace(base_dir, '')
self.catalog[msgid].addLocationComment(filename, lineno)
def _getProductVersion(self):
@@ -613,6 +614,22 @@
cwd = os.environ['PWD']
return os.path.normpath(os.path.join(cwd, path))
+def strip_base_dir(filename, base_dir):
+ """Strip base directory from filename if it starts there.
+
+ >>> strip_base_dir('/path/to/base/relpath/to/file',
+ ... '/path/to/base/')
+ 'relpath/to/file'
+
+ >>> strip_base_dir('/path/to/somewhere/else/relpath/to/file',
+ ... '/path/to/base/')
+ '/path/to/somewhere/else/relpath/to/file'
+
+ """
+ if filename.startswith(base_dir):
+ filename = filename[len(base_dir):]
+ return filename
+
def main(argv=None):
if argv is None:
argv = sys.argv[1:]
Modified: zope.app.locales/trunk/src/zope/app/locales/tests.py
===================================================================
--- zope.app.locales/trunk/src/zope/app/locales/tests.py 2011-12-12 14:05:33 UTC (rev 123772)
+++ zope.app.locales/trunk/src/zope/app/locales/tests.py 2011-12-12 14:16:15 UTC (rev 123773)
@@ -107,6 +107,36 @@
"""
+def doctest_POTMaker_add_skips_blank_msgids():
+ """Test for POTMaker.add
+
+ >>> from zope.app.locales.extract import POTMaker
+ >>> pm = POTMaker('/dev/null', 'path')
+ >>> pm.add({'': [('file2.py', 2), ('file1.py', 3)]})
+ >>> sorted(pm.catalog)
+ []
+
+ """
+
+
+def doctest_POTMaker_add_strips_basedirs():
+ """Test for POTMaker.add
+
+ >>> from zope.app.locales.extract import POTMaker
+ >>> pm = POTMaker('/dev/null', 'path')
+ >>> pm.add({'msgid1': [('basedir/file2.py', 2),
+ ... ('file1.py', 3),
+ ... ('notbasedir/file3.py', 5)]},
+ ... 'basedir/')
+ >>> print pm.catalog['msgid1'].comments
+ #: file1.py:3
+ #: file2.py:2
+ #: notbasedir/file3.py:5
+ <BLANKLINE>
+
+ """
+
+
def test_suite():
return unittest.TestSuite((
doctest.DocTestSuite(),
More information about the checkins
mailing list