Skip to content

Commit

Permalink
Write POT creation date in standard format.
Browse files Browse the repository at this point in the history
Add a doctest for POTMaker.write
  • Loading branch information
menesis committed Feb 16, 2012
1 parent 5eca474 commit 5322982
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Expand Up @@ -5,7 +5,7 @@ CHANGES
3.7.4 (unreleased)
------------------

- Nothing changed yet.
- Write POT creation date in standard format.


3.7.3 (2012-01-06)
Expand Down
2 changes: 1 addition & 1 deletion buildout.cfg
Expand Up @@ -11,7 +11,7 @@ arguments = ['-p', 'testproj/src', '-s', 'testproj/site.zcml',

[test]
recipe = zc.recipe.testrunner
eggs = zope.app.locales [test,zcml]
eggs = zope.app.locales [test,zcml,extract]

[ctags]
recipe = z3c.recipe.tag
Expand Down
3 changes: 2 additions & 1 deletion src/zope/app/locales/extract.py
Expand Up @@ -181,7 +181,8 @@ def _getProductVersion(self):

def write(self):
file = open(self._output_filename, 'w')
file.write(pot_header % {'time': time.ctime(),
ztime = time.strftime('%Y-%m-%d %H:%M%z')
file.write(pot_header % {'time': ztime,
'version': self._getProductVersion(),
'charset': DEFAULT_CHARSET,
'encoding': DEFAULT_ENCODING})
Expand Down
68 changes: 66 additions & 2 deletions src/zope/app/locales/tests.py
Expand Up @@ -12,10 +12,12 @@
#
##############################################################################
"""Tests for the message string extraction tool."""
__docformat__ = 'restructuredtext'

import doctest
import os
import unittest
import tempfile
import zope.app.locales
import zope.component
import zope.configuration.xmlconfig
Expand Down Expand Up @@ -162,11 +164,73 @@ def doctest_POTMaker_add_strips_basedirs():
"""


def doctest_POTMaker_write():
r"""Test for POTMaker.write
>>> from zope.app.locales.extract import POTMaker
>>> f, path = tempfile.mkstemp()
>>> pm = POTMaker(path, '')
>>> pm.add({'msgid1': [('file2.py', 2), ('file1.py', 3)],
... 'msgid2': [('file1.py', 5)]})
>>> from zope.app.locales.pygettext import make_escapes
>>> make_escapes(0)
>>> pm.write()
>>> f = open(path)
>>> pot = f.read()
>>> print pot
##############################################################################
#
# Copyright (c) 2003-2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
msgid ""
msgstr ""
"Project-Id-Version: Meaningless\n"
"POT-Creation-Date: ...-...-... ...:...0\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: Zope 3 Developers <zope-dev@zope.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: zope/app/locales/extract.py\n"
<BLANKLINE>
#: file1.py:3
#: file2.py:2
msgid "msgid1"
msgstr ""
<BLANKLINE>
#: file1.py:5
msgid "msgid2"
msgstr ""
<BLANKLINE>
<BLANKLINE>
>>> f.close()
>>> os.unlink(path)
"""


def test_suite():
return unittest.TestSuite((
doctest.DocTestSuite(),
doctest.DocTestSuite(
optionflags=doctest.NORMALIZE_WHITESPACE|
doctest.ELLIPSIS|
doctest.REPORT_NDIFF,),
doctest.DocTestSuite('zope.app.locales.extract',
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,),
optionflags=doctest.NORMALIZE_WHITESPACE|
doctest.ELLIPSIS|
doctest.REPORT_NDIFF,),
unittest.makeSuite(TestIsUnicodeInAllCatalog),
unittest.makeSuite(ZCMLTest),
))

0 comments on commit 5322982

Please sign in to comment.