[Python-checkins] r85537 - in python/branches/py3k: Doc/conf.py Lib/inspect.py Lib/pydoc.py Lib/test/encoded_modules Lib/test/encoded_modules/__init__.py Lib/test/encoded_modules/module_iso_8859_1.py Lib/test/encoded_modules/module_koi8_r.py Lib/test/test_csv.py Lib/test/test_doctest2.py Lib/test/test_imp.py Lib/test/test_pep3131.py Lib/test/test_sys.py Lib/test/test_winreg.py Makefile.pre.in Misc/NEWS Tools/ccbench/ccbench.py Tools/i18n/msgfmt.py

alexander.belopolsky python-checkins at python.org
Fri Oct 15 18:28:20 CEST 2010


Author: alexander.belopolsky
Date: Fri Oct 15 18:28:20 2010
New Revision: 85537

Log:
Issue #9308: Removed redundant coding cookies.  Added tests for
importing encoded modules that do not depend on specific stdlib
modules being encoded in a certain way.


Added:
   python/branches/py3k/Lib/test/encoded_modules/
   python/branches/py3k/Lib/test/encoded_modules/__init__.py
   python/branches/py3k/Lib/test/encoded_modules/module_iso_8859_1.py
   python/branches/py3k/Lib/test/encoded_modules/module_koi8_r.py
Modified:
   python/branches/py3k/Doc/conf.py
   python/branches/py3k/Lib/inspect.py
   python/branches/py3k/Lib/pydoc.py
   python/branches/py3k/Lib/test/test_csv.py
   python/branches/py3k/Lib/test/test_doctest2.py
   python/branches/py3k/Lib/test/test_imp.py
   python/branches/py3k/Lib/test/test_pep3131.py
   python/branches/py3k/Lib/test/test_sys.py
   python/branches/py3k/Lib/test/test_winreg.py
   python/branches/py3k/Makefile.pre.in
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Tools/ccbench/ccbench.py
   python/branches/py3k/Tools/i18n/msgfmt.py

Modified: python/branches/py3k/Doc/conf.py
==============================================================================
--- python/branches/py3k/Doc/conf.py	(original)
+++ python/branches/py3k/Doc/conf.py	Fri Oct 15 18:28:20 2010
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 #
 # Python documentation build configuration file
 #

Modified: python/branches/py3k/Lib/inspect.py
==============================================================================
--- python/branches/py3k/Lib/inspect.py	(original)
+++ python/branches/py3k/Lib/inspect.py	Fri Oct 15 18:28:20 2010
@@ -1,4 +1,3 @@
-# -*- coding: iso-8859-1 -*-
 """Get useful information from live Python objects.
 
 This module encapsulates the interface provided by the internal special

Modified: python/branches/py3k/Lib/pydoc.py
==============================================================================
--- python/branches/py3k/Lib/pydoc.py	(original)
+++ python/branches/py3k/Lib/pydoc.py	Fri Oct 15 18:28:20 2010
@@ -1,5 +1,4 @@
 #!/usr/bin/env python3
-# -*- coding: latin-1 -*-
 """Generate Python documentation in HTML or text for interactive use.
 
 In the Python interpreter, do "from pydoc import help" to provide online

Added: python/branches/py3k/Lib/test/encoded_modules/__init__.py
==============================================================================
--- (empty file)
+++ python/branches/py3k/Lib/test/encoded_modules/__init__.py	Fri Oct 15 18:28:20 2010
@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+
+# This is a package that contains a number of modules that are used to
+# test import from the source files that have different encodings.
+# This file (the __init__ module of the package), is encoded in utf-8
+# and contains a list of strings from various unicode planes that are
+# encoded differently to compare them to the same strings encoded
+# differently in submodules.  The following list, test_strings,
+# contains a list of tuples. The first element of each tuple is the
+# suffix that should be prepended with 'module_' to arrive at the
+# encoded submodule name, the second item is the encoding and the last
+# is the test string.  The same string is assigned to the variable
+# named 'test' inside the submodule.  If the decoding of modules works
+# correctly, from module_xyz import test should result in the same
+# string as listed below in the 'xyz' entry.
+
+# module, encoding, test string
+test_strings = (
+    ('iso_8859_1', 'iso-8859-1', "Les hommes ont oublié cette vérité, "
+     "dit le renard. Mais tu ne dois pas l'oublier. Tu deviens "
+     "responsable pour toujours de ce que tu as apprivoisé."),
+    ('koi8_r', 'koi8-r', "Познание бесконечности требует бесконечного времени.")
+)

Added: python/branches/py3k/Lib/test/encoded_modules/module_iso_8859_1.py
==============================================================================
--- (empty file)
+++ python/branches/py3k/Lib/test/encoded_modules/module_iso_8859_1.py	Fri Oct 15 18:28:20 2010
@@ -0,0 +1,5 @@
+# test iso-8859-1 encoding
+# -*- encoding: iso-8859-1 -*-
+test = ("Les hommes ont oublié cette vérité, "
+        "dit le renard. Mais tu ne dois pas l'oublier. Tu deviens "
+        "responsable pour toujours de ce que tu as apprivoisé.")

Added: python/branches/py3k/Lib/test/encoded_modules/module_koi8_r.py
==============================================================================
--- (empty file)
+++ python/branches/py3k/Lib/test/encoded_modules/module_koi8_r.py	Fri Oct 15 18:28:20 2010
@@ -0,0 +1,3 @@
+# test koi8-r encoding
+# -*- encoding: koi8-r  -*-
+test = "ðÏÚÎÁÎÉÅ ÂÅÓËÏÎÅÞÎÏÓÔÉ ÔÒÅÂÕÅÔ ÂÅÓËÏÎÅÞÎÏÇÏ ×ÒÅÍÅÎÉ."

Modified: python/branches/py3k/Lib/test/test_csv.py
==============================================================================
--- python/branches/py3k/Lib/test/test_csv.py	(original)
+++ python/branches/py3k/Lib/test/test_csv.py	Fri Oct 15 18:28:20 2010
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 # Copyright (C) 2001,2002 Python Software Foundation
 # csv package unit tests
 

Modified: python/branches/py3k/Lib/test/test_doctest2.py
==============================================================================
--- python/branches/py3k/Lib/test/test_doctest2.py	(original)
+++ python/branches/py3k/Lib/test/test_doctest2.py	Fri Oct 15 18:28:20 2010
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 """A module to test whether doctest recognizes some 2.2 features,
 like static and class methods.
 

Modified: python/branches/py3k/Lib/test/test_imp.py
==============================================================================
--- python/branches/py3k/Lib/test/test_imp.py	(original)
+++ python/branches/py3k/Lib/test/test_imp.py	Fri Oct 15 18:28:20 2010
@@ -5,7 +5,7 @@
 import sys
 import unittest
 from test import support
-
+import importlib
 
 class LockTests(unittest.TestCase):
 
@@ -42,18 +42,32 @@
                             "RuntimeError")
 
 class ImportTests(unittest.TestCase):
+    def setUp(self):
+        mod = importlib.import_module('test.encoded_modules')
+        self.test_strings = mod.test_strings
+        self.test_path = mod.__path__
+
+    def test_import_encoded_module(self):
+        for modname, encoding, teststr in self.test_strings:
+            mod = importlib.import_module('test.encoded_modules.'
+                                          'module_' + modname)
+            self.assertEqual(teststr, mod.test)
 
     def test_find_module_encoding(self):
-        fd = imp.find_module("pydoc")[0]
-        self.assertEqual(fd.encoding, "iso-8859-1")
+        for mod, encoding, _ in self.test_strings:
+            fd = imp.find_module('module_' + mod, self.test_path)[0]
+            self.assertEqual(fd.encoding, encoding)
 
     def test_issue1267(self):
-        fp, filename, info  = imp.find_module("pydoc")
-        self.assertNotEqual(fp, None)
-        self.assertEqual(fp.encoding, "iso-8859-1")
-        self.assertEqual(fp.tell(), 0)
-        self.assertEqual(fp.readline(), '#!/usr/bin/env python3\n')
-        fp.close()
+        for mod, encoding, _ in self.test_strings:
+            fp, filename, info  = imp.find_module('module_' + mod,
+                                                  self.test_path)
+            self.assertNotEqual(fp, None)
+            self.assertEqual(fp.encoding, encoding)
+            self.assertEqual(fp.tell(), 0)
+            self.assertEqual(fp.readline(), '# test %s encoding\n'
+                             % encoding)
+            fp.close()
 
         fp, filename, info = imp.find_module("tokenize")
         self.assertNotEqual(fp, None)

Modified: python/branches/py3k/Lib/test/test_pep3131.py
==============================================================================
--- python/branches/py3k/Lib/test/test_pep3131.py	(original)
+++ python/branches/py3k/Lib/test/test_pep3131.py	Fri Oct 15 18:28:20 2010
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 import unittest
 from test import support
 

Modified: python/branches/py3k/Lib/test/test_sys.py
==============================================================================
--- python/branches/py3k/Lib/test/test_sys.py	(original)
+++ python/branches/py3k/Lib/test/test_sys.py	Fri Oct 15 18:28:20 2010
@@ -1,4 +1,3 @@
-# -*- coding: iso-8859-1 -*-
 import unittest, test.support
 import sys, io, os
 import struct

Modified: python/branches/py3k/Lib/test/test_winreg.py
==============================================================================
--- python/branches/py3k/Lib/test/test_winreg.py	(original)
+++ python/branches/py3k/Lib/test/test_winreg.py	Fri Oct 15 18:28:20 2010
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 # Test the windows specific win32reg module.
 # Only win32reg functions not hit here: FlushKey, LoadKey and SaveKey
 

Modified: python/branches/py3k/Makefile.pre.in
==============================================================================
--- python/branches/py3k/Makefile.pre.in	(original)
+++ python/branches/py3k/Makefile.pre.in	Fri Oct 15 18:28:20 2010
@@ -872,7 +872,7 @@
 LIBSUBDIRS=	tkinter tkinter/test tkinter/test/test_tkinter \
                 tkinter/test/test_ttk site-packages test \
 		test/decimaltestdata test/xmltestdata \
-		test/tracedmodules \
+		test/tracedmodules test/encoded_modules \
 		concurrent encodings \
 		email email/mime email/test email/test/data \
 		html json json/tests http dbm xmlrpc \

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Fri Oct 15 18:28:20 2010
@@ -403,6 +403,9 @@
 Tests
 -----
 
+- Issue #9308: Added tests for importing encoded modules that do not
+  depend on specific stdlib modules being encoded in a certain way.
+
 - Issue #1051: Add a script (Lib/test/make_ssl_certs.py) to generate the custom
   certificate and private key files used by SSL-related certs.
 

Modified: python/branches/py3k/Tools/ccbench/ccbench.py
==============================================================================
--- python/branches/py3k/Tools/ccbench/ccbench.py	(original)
+++ python/branches/py3k/Tools/ccbench/ccbench.py	Fri Oct 15 18:28:20 2010
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 # This file should be kept compatible with both Python 2.6 and Python >= 3.0.
 
 from __future__ import division

Modified: python/branches/py3k/Tools/i18n/msgfmt.py
==============================================================================
--- python/branches/py3k/Tools/i18n/msgfmt.py	(original)
+++ python/branches/py3k/Tools/i18n/msgfmt.py	Fri Oct 15 18:28:20 2010
@@ -1,6 +1,5 @@
 #! /usr/bin/env python3
-# -*- coding: iso-8859-1 -*-
-# Written by Martin v. Löwis <loewis at informatik.hu-berlin.de>
+# Written by Martin v. Löwis <loewis at informatik.hu-berlin.de>
 
 """Generate binary message catalog from textual translation description.
 


More information about the Python-checkins mailing list