From 53229828072fe59b41b57867a0a2e4f42f5d14a9 Mon Sep 17 00:00:00 2001 From: Gediminas Paulauskas Date: Thu, 16 Feb 2012 17:43:02 +0000 Subject: [PATCH] Write POT creation date in standard format. Add a doctest for POTMaker.write --- CHANGES.txt | 2 +- buildout.cfg | 2 +- src/zope/app/locales/extract.py | 3 +- src/zope/app/locales/tests.py | 68 ++++++++++++++++++++++++++++++++- 4 files changed, 70 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 8186218..25b9061 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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) diff --git a/buildout.cfg b/buildout.cfg index e3d8b82..4c09160 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -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 diff --git a/src/zope/app/locales/extract.py b/src/zope/app/locales/extract.py index 2fda8e2..a0425a0 100644 --- a/src/zope/app/locales/extract.py +++ b/src/zope/app/locales/extract.py @@ -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}) diff --git a/src/zope/app/locales/tests.py b/src/zope/app/locales/tests.py index 74d299d..a8d63c7 100644 --- a/src/zope/app/locales/tests.py +++ b/src/zope/app/locales/tests.py @@ -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 @@ -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 \n" + "Language-Team: Zope 3 Developers \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" + + #: file1.py:3 + #: file2.py:2 + msgid "msgid1" + msgstr "" + + #: file1.py:5 + msgid "msgid2" + msgstr "" + + + + >>> 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), ))