← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-translations-utilities-doctests-future-imports into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-translations-utilities-doctests-future-imports into launchpad:master.

Commit message:
Convert lp.translations.utilities doctests to __future__ imports

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/397979
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-translations-utilities-doctests-future-imports into launchpad:master.
diff --git a/lib/lp/translations/utilities/doc/gettext_po_exporter.txt b/lib/lp/translations/utilities/doc/gettext_po_exporter.txt
index 4d3a74c..51536cf 100644
--- a/lib/lp/translations/utilities/doc/gettext_po_exporter.txt
+++ b/lib/lp/translations/utilities/doc/gettext_po_exporter.txt
@@ -151,7 +151,7 @@ It's time to test the wrapping with the '-' char:
     ...     TranslationConstants.SINGULAR_FORM,
     ...     u"WARNUNG: Unsichere Zugriffsrechte des umgebenden Verzeichnisses"
     ...         u" des Home-Verzeichnisses `%s'\n")
-    >>> print export_translation_message(translation_message)
+    >>> print(export_translation_message(translation_message))
     msgid "WARNING: unsafe enclosing directory permissions on homedir `%s'\n"
     msgstr ""
     "WARNUNG: Unsichere Zugriffsrechte des umgebenden Verzeichnisses des Home-"
@@ -163,7 +163,7 @@ When we changed the wrapping code, we got a bug with this string.
     >>> translation_message.msgid_singular = (
     ...     u"The location and hierarchy of the Evolution contact folders has"
     ...         u" changed since Evolution 1.x.\n\n")
-    >>> print export_translation_message(translation_message)
+    >>> print(export_translation_message(translation_message))
     msgid ""
     "The location and hierarchy of the Evolution contact folders has changed "
     "since Evolution 1.x.\n"
@@ -177,7 +177,7 @@ creating a broken PO message.  This is the test for bug #46156.
     >>> translation_message = TranslationMessageData()
     >>> translation_message.msgid_singular = (
     ...     u"1234567890abcde word\"1234567890abcdefghij")
-    >>> print export_translation_message(translation_message, wrap_width=20)
+    >>> print(export_translation_message(translation_message, wrap_width=20))
     msgid ""
     "1234567890abcde "
     "word\"1234567890abcd"
@@ -191,7 +191,7 @@ like \" or \\:
     >>> translation_message = TranslationMessageData()
     >>> translation_message.msgid_singular = (
     ...     u"1234567890abcdefghij\\klmno")
-    >>> print export_translation_message(translation_message, wrap_width=20)
+    >>> print(export_translation_message(translation_message, wrap_width=20))
     msgid ""
     "1234567890abcdefghij"
     "\\klmno"
@@ -200,7 +200,7 @@ like \" or \\:
     >>> translation_message = TranslationMessageData()
     >>> translation_message.msgid_singular = (
     ...     u"1234567890abcdefgh\\ijklmno")
-    >>> print export_translation_message(translation_message, wrap_width=20)
+    >>> print(export_translation_message(translation_message, wrap_width=20))
     msgid ""
     "1234567890abcdefgh\\"
     "ijklmno"
@@ -209,7 +209,7 @@ like \" or \\:
     >>> translation_message = TranslationMessageData()
     >>> translation_message.msgid_singular = (
     ...     u"1234567890abcdefg\\\\hijklmno")
-    >>> print export_translation_message(translation_message, wrap_width=20)
+    >>> print(export_translation_message(translation_message, wrap_width=20))
     msgid ""
     "1234567890abcdefg\\"
     "\\hijklmno"
@@ -220,14 +220,14 @@ For compatibility with msgcat -w, it also wraps on \\ properly.
     >>> translation_message = TranslationMessageData()
     >>> translation_message.msgid_singular = (
     ...     u"\\\\\\\\\\")
-    >>> print export_translation_message(translation_message, wrap_width=5)
+    >>> print(export_translation_message(translation_message, wrap_width=5))
     msgid ""
     "\\\\"
     "\\\\"
     "\\"
     msgstr ""
 
-    >>> print export_translation_message(translation_message, wrap_width=6)
+    >>> print(export_translation_message(translation_message, wrap_width=6))
     msgid ""
     "\\\\\\"
     "\\\\"
@@ -237,7 +237,7 @@ There are a couple of other characters that will be escaped in the
 output, too.
 
     >>> translation_message.msgid_singular = (u'"\t\r')
-    >>> print export_translation_message(translation_message, wrap_width=10)
+    >>> print(export_translation_message(translation_message, wrap_width=10))
     msgid ""
     "\"\t\r"
     msgstr ""
diff --git a/lib/lp/translations/utilities/doc/gettext_po_parser.txt b/lib/lp/translations/utilities/doc/gettext_po_parser.txt
index 8ce9e60..34b3082 100644
--- a/lib/lp/translations/utilities/doc/gettext_po_parser.txt
+++ b/lib/lp/translations/utilities/doc/gettext_po_parser.txt
@@ -99,14 +99,14 @@ POHeader.
 
 Plural forms are now the default ones. No plural forms.
 
-    >>> print new_header.plural_form_expression
+    >>> print(new_header.plural_form_expression)
     0
     >>> new_header.number_plural_forms
     1
 
 And the translation_revision_date is exactly the one in the header string.
 
-    >>> print new_header.translation_revision_date
+    >>> print(new_header.translation_revision_date)
     2005-08-18 13:22:00+00:00
 
 
@@ -140,7 +140,7 @@ It defaults to None.
     ... Content-Type: text/plain; charset=UTF-8
     ... Content-Transfer-Encoding: 8bit
     ... """)
-    >>> print header.translation_revision_date
+    >>> print(header.translation_revision_date)
     None
 
 
@@ -157,7 +157,7 @@ valid header but no revision date.
     ... Content-Type: text/plain; charset=UTF-8
     ... Content-Transfer-Encoding: 8bit
     ... """)
-    >>> print header.translation_revision_date
+    >>> print(header.translation_revision_date)
     None
 
 
@@ -174,7 +174,7 @@ Likewise, if the PO-Revision-Date header is semantically nonsensical
     ... Content-Type: text/plain; charset=UTF-8
     ... Content-Transfer-Encoding: 8bit
     ... """)
-    >>> print header.translation_revision_date
+    >>> print(header.translation_revision_date)
     None
 
 
@@ -214,7 +214,7 @@ and a translation header with some fields set.
 Once we do the update, the resulting output will be a mix between both headers.
 
     >>> translation_header.updateFromTemplateHeader(template_header)
-    >>> print translation_header.getRawContent()
+    >>> print(translation_header.getRawContent())
     Project-Id-Version: PACKAGE VERSION
     Report-Msgid-Bugs-To:
     POT-Creation-Date: 2007-07-09 03:39+0100
@@ -231,7 +231,7 @@ If the header knows there are plural forms, the plural form information
 will appear in the export.
 
     >>> translation_header.has_plural_forms = True
-    >>> print translation_header.getRawContent()
+    >>> print(translation_header.getRawContent())
     Project-Id-Version: PACKAGE VERSION
     Report-Msgid-Bugs-To:
     POT-Creation-Date: 2007-07-09 03:39+0100
@@ -263,7 +263,7 @@ template.
     ...     Domain: blahdomain
     ...     """)
     >>> translation_header.updateFromTemplateHeader(template_header)
-    >>> print translation_header.getRawContent()
+    >>> print(translation_header.getRawContent())
     Project-Id-Version: PACKAGE VERSION
     Report-Msgid-Bugs-To:
     POT-Creation-Date: 2007-07-09 03:39+0100
@@ -305,7 +305,7 @@ Parsing a PO template:
 
     >>> len(translation_file.messages)
     1
-    >>> print translation_file.messages[0].msgid_singular
+    >>> print(translation_file.messages[0].msgid_singular)
     Foo
 
 PO templates, and other PO files that do not specify their encoding,
diff --git a/lib/lp/translations/utilities/doc/gettext_po_parser_context.txt b/lib/lp/translations/utilities/doc/gettext_po_parser_context.txt
index 09e061d..f096aa6 100644
--- a/lib/lp/translations/utilities/doc/gettext_po_parser_context.txt
+++ b/lib/lp/translations/utilities/doc/gettext_po_parser_context.txt
@@ -86,7 +86,7 @@ This file can now be correctly imported:
 
     >>> entry = import_pofile_or_potemplate(potemplate_contents, carlos,
     ...                                     potemplate=potemplate)
-    >>> print entry.status.name
+    >>> print(entry.status.name)
     IMPORTED
     >>> flush_database_caches() # replace date SQL constant with real date
 
@@ -94,40 +94,40 @@ The method getPOTMsgSetByMsgIDText returns a message without context if
 no context is specified.
 
     >>> potmsgset = potemplate.getPOTMsgSetByMsgIDText(u'bar')
-    >>> print potmsgset.singular_text
+    >>> print(potmsgset.singular_text)
     bar
-    >>> print potmsgset.context
+    >>> print(potmsgset.context)
     None
 
 And if all the messages have a context, getPOTMsgSetByMsgIDText returns
 nothing when context is not specified.
 
     >>> potmsgset = potemplate.getPOTMsgSetByMsgIDText(u'%d file')
-    >>> print potmsgset
+    >>> print(potmsgset)
     None
 
 To get a message with a context, we pass a context parameter.
 
     >>> potmsgset = potemplate.getPOTMsgSetByMsgIDText(u'bar',
     ...                                                context=u'context')
-    >>> print potmsgset.singular_text
+    >>> print(potmsgset.singular_text)
     bar
-    >>> print potmsgset.context
+    >>> print(potmsgset.context)
     context
 
 It also works for plural form messages.
 
     >>> potmsgset = potemplate.getPOTMsgSetByMsgIDText(u'%d file',
     ...                                                context=u'First message')
-    >>> print potmsgset.singular_text
+    >>> print(potmsgset.singular_text)
     %d file
-    >>> print potmsgset.context
+    >>> print(potmsgset.context)
     First message
     >>> potmsgset = potemplate.getPOTMsgSetByMsgIDText(u'%d file', u'%d files',
     ...                                                context=u'Second message')
-    >>> print potmsgset.singular_text
+    >>> print(potmsgset.singular_text)
     %d file
-    >>> print potmsgset.context
+    >>> print(potmsgset.context)
     Second message
 
 Importing a PO template with two messages with identical strings, but no
@@ -156,7 +156,7 @@ Importing this file fails because of conflicting messages.
     ...                                     potemplate=potemplate)
     INFO We got an error import...
     ...duplicate msgid...
-    >>> print entry.status.name
+    >>> print(entry.status.name)
     FAILED
 
 == Importing PO files ==
@@ -199,7 +199,7 @@ Importing this file succeeds.
 
     >>> entry = import_pofile_or_potemplate(pofile_contents, carlos,
     ...                                     pofile=pofile)
-    >>> print entry.status.name
+    >>> print(entry.status.name)
     IMPORTED
     >>> flush_database_caches() # replace date SQL constant with real date
 
@@ -225,7 +225,7 @@ a message with context.
 If message has a context, you cannot get it without specifying the context:
 
     >>> potmsgset = potemplate.getPOTMsgSetByMsgIDText(u'%file')
-    >>> print potmsgset
+    >>> print(potmsgset)
     None
 
 If you specify context, it actually works.
@@ -251,7 +251,7 @@ And for messages with plural forms, it gets all the translations.
 Make sure exported files are correct.  Exporting a POT file returns exactly
 the same contents, except that header is marked fuzzy.
 
-    >>> print potemplate.export()
+    >>> print(potemplate.export())
     #, fuzzy
     msgid ""
     msgstr ""
@@ -293,7 +293,7 @@ And a Serbian PO file is exported using regular export_pofile call.
 It's different from the imported file only in a few headers.
 
     >>> pofile = potemplate.getPOFileByLang('sr')
-    >>> print pofile.export().decode('UTF-8')
+    >>> print(pofile.export().decode('UTF-8'))
     msgid ""
     msgstr ""
     "Project-Id-Version: PACKAGE VERSION\n"
@@ -358,7 +358,7 @@ This file can now be correctly imported:
 
     >>> entry = import_pofile_or_potemplate(potemplate_contents, carlos,
     ...                                     potemplate=potemplate)
-    >>> print entry.status.name
+    >>> print(entry.status.name)
     IMPORTED
     >>> flush_database_caches() # replace date SQL constant with real date
 
@@ -366,16 +366,16 @@ The method getPOTMsgSetByMsgIDText returns a message without context if
 no context is specified.
 
     >>> potmsgset = potemplate.getPOTMsgSetByMsgIDText(u'bar')
-    >>> print potmsgset.singular_text
+    >>> print(potmsgset.singular_text)
     bar
-    >>> print potmsgset.context
+    >>> print(potmsgset.context)
     None
 
 The method getPOTMsgSetByMsgIDText returns a message with empty context
 if empty context is specified, and not the message with None context.
 
     >>> potmsgset = potemplate.getPOTMsgSetByMsgIDText(u'bar', context=u'')
-    >>> print potmsgset.singular_text
+    >>> print(potmsgset.singular_text)
     bar
     >>> print(potmsgset.context)
     <BLANKLINE>
diff --git a/lib/lp/translations/utilities/doc/kde-po-file-format.txt b/lib/lp/translations/utilities/doc/kde-po-file-format.txt
index d7311b7..bb7a636 100644
--- a/lib/lp/translations/utilities/doc/kde-po-file-format.txt
+++ b/lib/lp/translations/utilities/doc/kde-po-file-format.txt
@@ -64,10 +64,10 @@ Importing this file works, but the format is set to Gettext PO.
 
     >>> entry = import_pofile_or_potemplate(non_kde_template, carlos,
     ...                                     potemplate=firefox_potemplate)
-    >>> print entry.status.name
+    >>> print(entry.status.name)
     IMPORTED
     >>> flush_database_caches()
-    >>> print entry.format.title
+    >>> print(entry.format.title)
     PO format
 
 == Plural forms support ==
@@ -118,10 +118,10 @@ to KDE PO format.
 
     >>> entry = import_pofile_or_potemplate(plural_forms_template, carlos,
     ...                                     potemplate=firefox_potemplate)
-    >>> print entry.status.name
+    >>> print(entry.status.name)
     IMPORTED
     >>> flush_database_caches()
-    >>> print entry.format.title
+    >>> print(entry.format.title)
     KDE PO format
 
 Messages which are preceded with just '_n:' and no space after it are
@@ -129,10 +129,10 @@ not considered plural forms messages.
 
     >>> potmsgset = firefox_potemplate.getPOTMsgSetByMsgIDText(
     ...     u'_n:bar\nbars')
-    >>> print potmsgset.singular_text
+    >>> print(potmsgset.singular_text)
     _n:bar
     bars
-    >>> print potmsgset.plural_text
+    >>> print(potmsgset.plural_text)
     None
 
 Proper format in messages is to use '_n: ' and separate singular and
@@ -140,9 +140,9 @@ plural with a newline.
 
     >>> potmsgset = firefox_potemplate.getPOTMsgSetByMsgIDText(
     ...     u'%d foo', plural_text=u'%d foos')
-    >>> print potmsgset.singular_text
+    >>> print(potmsgset.singular_text)
     %d foo
-    >>> print potmsgset.plural_text
+    >>> print(potmsgset.plural_text)
     %d foos
 
 To get a non-plural message, we can either not specify plural_text or
@@ -150,9 +150,9 @@ set it as None:
 
     >>> potmsgset = firefox_potemplate.getPOTMsgSetByMsgIDText(
     ...     u'%d foo', plural_text=None)
-    >>> print potmsgset.singular_text
+    >>> print(potmsgset.singular_text)
     %d foo
-    >>> print potmsgset.plural_text
+    >>> print(potmsgset.plural_text)
     None
 
 For translations, a specially formatted msgstr is used to hold all plural
@@ -201,10 +201,10 @@ format support.
     >>> entry = import_pofile_or_potemplate(firefox_serbian_pofile_contents,
     ...                                     carlos,
     ...                                     pofile=firefox_serbian_pofile)
-    >>> print entry.status.name
+    >>> print(entry.status.name)
     IMPORTED
     >>> flush_database_caches()
-    >>> print entry.format.title
+    >>> print(entry.format.title)
     KDE PO format
 
 Non-KDE style messages get their translations in the usual way.
@@ -256,8 +256,8 @@ Make sure all the date constants are replaced with real values in database:
 
 Template export turns it back into a KDE-style PO file:
 
-    >>> print export_with_format(
-    ...     firefox_potemplate, TranslationFileFormat.KDEPO)
+    >>> print(export_with_format(
+    ...     firefox_potemplate, TranslationFileFormat.KDEPO))
     #, fuzzy
     msgid ""
     msgstr ""
@@ -307,8 +307,8 @@ But, we can also export it as a regular gettext PO file.  This format
 does not support messages that are identical in all but the plural, so
 those are stripped out.
 
-    >>> print export_with_format(firefox_potemplate,
-    ...                          TranslationFileFormat.PO)
+    >>> print(export_with_format(firefox_potemplate,
+    ...                          TranslationFileFormat.PO))
     #, fuzzy
     msgid ""
     msgstr ""
@@ -343,7 +343,7 @@ those are stripped out.
 
 Exporting a translation is possible in a very similar way.
 
-    >>> print firefox_serbian_pofile.export().decode('utf8')
+    >>> print(firefox_serbian_pofile.export().decode('utf8'))
     msgid ""
     msgstr ""
     ...
@@ -424,26 +424,26 @@ Importing this template works and the format is recognized as a KDE PO format.
 
     >>> entry = import_pofile_or_potemplate(kde_context_template, carlos,
     ...                                     potemplate=firefox_potemplate)
-    >>> print entry.status.name
+    >>> print(entry.status.name)
     IMPORTED
     >>> flush_database_caches()
-    >>> print entry.format.title
+    >>> print(entry.format.title)
     KDE PO format
 
 Message with context is properly split into msgid and context fields.
 
     >>> potmsgset = firefox_potemplate.getPOTMsgSetByMsgIDText(
     ...     u'Message', context='Context')
-    >>> print potmsgset.singular_text
+    >>> print(potmsgset.singular_text)
     Message
-    >>> print potmsgset.context
+    >>> print(potmsgset.context)
     Context
 
 If we ask for a message without specifying context, we get no results:
 
     >>> potmsgset = firefox_potemplate.getPOTMsgSetByMsgIDText(
     ...     u'Message')
-    >>> print potmsgset
+    >>> print(potmsgset)
     None
 
 We can also import a translated file with message contexts:
@@ -463,10 +463,10 @@ We can also import a translated file with message contexts:
     ... ''' % ISO_FORMATTED_DATE).encode('UTF-8')
     >>> entry = import_pofile_or_potemplate(kde_context_translation, carlos,
     ...                                     pofile=firefox_serbian_pofile)
-    >>> print entry.status.name
+    >>> print(entry.status.name)
     IMPORTED
     >>> flush_database_caches()
-    >>> print entry.format.title
+    >>> print(entry.format.title)
     KDE PO format
 
 
@@ -497,8 +497,8 @@ other message and its translation:
 
 Exporting a PO template as a KDE PO file joins the context back together:
 
-    >>> print export_with_format(firefox_potemplate,
-    ...                          TranslationFileFormat.KDEPO)
+    >>> print(export_with_format(firefox_potemplate,
+    ...                          TranslationFileFormat.KDEPO))
     #, fuzzy
     msgid ""
     msgstr ""
@@ -520,7 +520,7 @@ Exporting a PO template as a KDE PO file joins the context back together:
 
 And the same happens with a translation:
 
-    >>> print firefox_serbian_pofile.export().decode('utf8')
+    >>> print(firefox_serbian_pofile.export().decode('utf8'))
     msgid ""
     msgstr ""
     ...
diff --git a/lib/lp/translations/utilities/doc/pluralforms.txt b/lib/lp/translations/utilities/doc/pluralforms.txt
index e5f6bf5..5b6ba20 100644
--- a/lib/lp/translations/utilities/doc/pluralforms.txt
+++ b/lib/lp/translations/utilities/doc/pluralforms.txt
@@ -28,7 +28,7 @@ It's also known that Serbian has 3 plural forms.
     ...     expression, pluralforms_count)
 
     >>> for form_dict in friendly_plural_forms:
-    ...     print form_dict['form'], ":", form_dict['examples']
+    ...     print(form_dict['form'], ":", form_dict['examples'])
     0 : [1, 21, 31, 41, 51, 61]
     1 : [2, 3, 4, 22, 23, 24]
     2 : [0, 5, 6, 7, 8, 9]
diff --git a/lib/lp/translations/utilities/doc/templatenames.txt b/lib/lp/translations/utilities/doc/templatenames.txt
index cc69bd9..55bef11 100644
--- a/lib/lp/translations/utilities/doc/templatenames.txt
+++ b/lib/lp/translations/utilities/doc/templatenames.txt
@@ -9,18 +9,18 @@ also know how to detect xpi templates and generic template file names and
 derive translation domains from directory names, if possible.
 
     >>> from lp.translations.utilities.template import make_domain
-    >>> print make_domain("po/my_domain.pot")
+    >>> print(make_domain("po/my_domain.pot"))
     my_domain
-    >>> print make_domain("po/my_domain/messages.pot")
+    >>> print(make_domain("po/my_domain/messages.pot"))
     my_domain
-    >>> print make_domain("my_module/po/messages.pot")
+    >>> print(make_domain("my_module/po/messages.pot"))
     my_module
-    >>> print make_domain("my_domain/en-US.xpi")
+    >>> print(make_domain("my_domain/en-US.xpi"))
     my_domain
 
 If a template path is generic, no translation domain can be derived.
 
-    >>> print make_domain("po/messages.pot")
+    >>> print(make_domain("po/messages.pot"))
     <BLANKLINE>
 
 The conversion from domain to template name replaces underscores (_) with
@@ -28,15 +28,15 @@ dashes (-) and makes all characters lower case. Invalid characters are
 removed.
 
     >>> from lp.translations.utilities.template import make_name
-    >>> print make_name("My_Domain")
+    >>> print(make_name("My_Domain"))
     my-domain
-    >>> print make_name("my #domain@home")
+    >>> print(make_name("my #domain@home"))
     mydomainhome
 
 Finally, the convenience function make_name_from_path chains the first two
 methods.
 
     >>> from lp.translations.utilities.template import make_name_from_path
-    >>> print make_name_from_path("po/MyDomain/messages.pot")
+    >>> print(make_name_from_path("po/MyDomain/messages.pot"))
     mydomain
 
diff --git a/lib/lp/translations/utilities/tests/test_system_documentation.py b/lib/lp/translations/utilities/tests/test_system_documentation.py
index a65ee84..8f1af4f 100644
--- a/lib/lp/translations/utilities/tests/test_system_documentation.py
+++ b/lib/lp/translations/utilities/tests/test_system_documentation.py
@@ -25,7 +25,8 @@ here = os.path.dirname(os.path.realpath(__file__))
 # Files that have special needs can construct their own suite
 special = {
     'gettext_po_parser.txt': LayeredDocFileSuite(
-        '../doc/gettext_po_parser.txt', setUp=setGlobs, stdout_logging=False)
+        '../doc/gettext_po_parser.txt',
+        setUp=lambda test: setGlobs(test, future=True), stdout_logging=False)
     }
 
 
@@ -58,7 +59,8 @@ def test_suite():
     for filename in filenames:
         path = os.path.join('../doc/', filename)
         one_test = LayeredDocFileSuite(
-            path, setUp=setUp, tearDown=tearDown,
+            path,
+            setUp=lambda test: setUp(test, future=True), tearDown=tearDown,
             layer=LaunchpadFunctionalLayer,
             stdout_logging_level=logging.WARNING
             )