diff options
author | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-10-15 16:28:20 (GMT) |
---|---|---|
committer | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-10-15 16:28:20 (GMT) |
commit | e8f583244acd61d7ba43d0f98c06d57c25977039 (patch) | |
tree | 3cbdcba9f0121ade8913e07cd83c8ee324999de1 /Lib | |
parent | c01537f742c3d2591016ef29bb20e3a26482be78 (diff) | |
download | cpython-e8f583244acd61d7ba43d0f98c06d57c25977039.zip cpython-e8f583244acd61d7ba43d0f98c06d57c25977039.tar.gz cpython-e8f583244acd61d7ba43d0f98c06d57c25977039.tar.bz2 |
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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/inspect.py | 1 | ||||
-rwxr-xr-x | Lib/pydoc.py | 1 | ||||
-rw-r--r-- | Lib/test/encoded_modules/__init__.py | 23 | ||||
-rw-r--r-- | Lib/test/encoded_modules/module_iso_8859_1.py | 5 | ||||
-rw-r--r-- | Lib/test/encoded_modules/module_koi8_r.py | 3 | ||||
-rw-r--r-- | Lib/test/test_csv.py | 1 | ||||
-rw-r--r-- | Lib/test/test_doctest2.py | 1 | ||||
-rw-r--r-- | Lib/test/test_imp.py | 32 | ||||
-rw-r--r-- | Lib/test/test_pep3131.py | 1 | ||||
-rw-r--r-- | Lib/test/test_sys.py | 1 | ||||
-rw-r--r-- | Lib/test/test_winreg.py | 1 |
11 files changed, 54 insertions, 16 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 3596014..35bc263 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -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 diff --git a/Lib/pydoc.py b/Lib/pydoc.py index acee7b7..5e54468 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -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 diff --git a/Lib/test/encoded_modules/__init__.py b/Lib/test/encoded_modules/__init__.py new file mode 100644 index 0000000..ec43252 --- /dev/null +++ b/Lib/test/encoded_modules/__init__.py @@ -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', "Познание бесконечности требует бесконечного времени.") +) diff --git a/Lib/test/encoded_modules/module_iso_8859_1.py b/Lib/test/encoded_modules/module_iso_8859_1.py new file mode 100644 index 0000000..8f4a15c --- /dev/null +++ b/Lib/test/encoded_modules/module_iso_8859_1.py @@ -0,0 +1,5 @@ +# test iso-8859-1 encoding +# -*- encoding: iso-8859-1 -*- +test = ("Les hommes ont oubli cette vrit, " + "dit le renard. Mais tu ne dois pas l'oublier. Tu deviens " + "responsable pour toujours de ce que tu as apprivois.") diff --git a/Lib/test/encoded_modules/module_koi8_r.py b/Lib/test/encoded_modules/module_koi8_r.py new file mode 100644 index 0000000..9b23a5a --- /dev/null +++ b/Lib/test/encoded_modules/module_koi8_r.py @@ -0,0 +1,3 @@ +# test koi8-r encoding +# -*- encoding: koi8-r -*- +test = " ." diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index ca67ac6..97800af 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (C) 2001,2002 Python Software Foundation # csv package unit tests diff --git a/Lib/test/test_doctest2.py b/Lib/test/test_doctest2.py index 8500ed5..347a143 100644 --- a/Lib/test/test_doctest2.py +++ b/Lib/test/test_doctest2.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """A module to test whether doctest recognizes some 2.2 features, like static and class methods. diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py index c71a4c7..b291ded 100644 --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -5,7 +5,7 @@ import shutil import sys import unittest from test import support - +import importlib class LockTests(unittest.TestCase): @@ -42,18 +42,32 @@ class LockTests(unittest.TestCase): "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) diff --git a/Lib/test/test_pep3131.py b/Lib/test/test_pep3131.py index e4c2d03..fba1297 100644 --- a/Lib/test/test_pep3131.py +++ b/Lib/test/test_pep3131.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import unittest from test import support diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 8c3a1db..6203061 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1,4 +1,3 @@ -# -*- coding: iso-8859-1 -*- import unittest, test.support import sys, io, os import struct diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py index 4757038..b4524db 100644 --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Test the windows specific win32reg module. # Only win32reg functions not hit here: FlushKey, LoadKey and SaveKey |