Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e8f5832

Browse files
committed
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.
1 parent c01537f commit e8f5832

16 files changed

Lines changed: 59 additions & 21 deletions

Doc/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# Python documentation build configuration file
43
#

Lib/inspect.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: iso-8859-1 -*-
21
"""Get useful information from live Python objects.
32
43
This module encapsulates the interface provided by the internal special

Lib/pydoc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# -*- coding: latin-1 -*-
32
"""Generate Python documentation in HTML or text for interactive use.
43
54
In the Python interpreter, do "from pydoc import help" to provide online
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- encoding: utf-8 -*-
2+
3+
# This is a package that contains a number of modules that are used to
4+
# test import from the source files that have different encodings.
5+
# This file (the __init__ module of the package), is encoded in utf-8
6+
# and contains a list of strings from various unicode planes that are
7+
# encoded differently to compare them to the same strings encoded
8+
# differently in submodules. The following list, test_strings,
9+
# contains a list of tuples. The first element of each tuple is the
10+
# suffix that should be prepended with 'module_' to arrive at the
11+
# encoded submodule name, the second item is the encoding and the last
12+
# is the test string. The same string is assigned to the variable
13+
# named 'test' inside the submodule. If the decoding of modules works
14+
# correctly, from module_xyz import test should result in the same
15+
# string as listed below in the 'xyz' entry.
16+
17+
# module, encoding, test string
18+
test_strings = (
19+
('iso_8859_1', 'iso-8859-1', "Les hommes ont oublié cette vérité, "
20+
"dit le renard. Mais tu ne dois pas l'oublier. Tu deviens "
21+
"responsable pour toujours de ce que tu as apprivoisé."),
22+
('koi8_r', 'koi8-r', "Познание бесконечности требует бесконечного времени.")
23+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# test iso-8859-1 encoding
2+
# -*- encoding: iso-8859-1 -*-
3+
test = ("Les hommes ont oublié cette vérité, "
4+
"dit le renard. Mais tu ne dois pas l'oublier. Tu deviens "
5+
"responsable pour toujours de ce que tu as apprivoisé.")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# test koi8-r encoding
2+
# -*- encoding: koi8-r -*-
3+
test = "Познание бесконечности требует бесконечного времени."

Lib/test/test_csv.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright (C) 2001,2002 Python Software Foundation
32
# csv package unit tests
43

Lib/test/test_doctest2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""A module to test whether doctest recognizes some 2.2 features,
32
like static and class methods.
43

Lib/test/test_imp.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
import unittest
77
from test import support
8-
8+
import importlib
99

1010
class LockTests(unittest.TestCase):
1111

@@ -42,18 +42,32 @@ def testLock(self):
4242
"RuntimeError")
4343

4444
class ImportTests(unittest.TestCase):
45+
def setUp(self):
46+
mod = importlib.import_module('test.encoded_modules')
47+
self.test_strings = mod.test_strings
48+
self.test_path = mod.__path__
49+
50+
def test_import_encoded_module(self):
51+
for modname, encoding, teststr in self.test_strings:
52+
mod = importlib.import_module('test.encoded_modules.'
53+
'module_' + modname)
54+
self.assertEqual(teststr, mod.test)
4555

4656
def test_find_module_encoding(self):
47-
fd = imp.find_module("pydoc")[0]
48-
self.assertEqual(fd.encoding, "iso-8859-1")
57+
for mod, encoding, _ in self.test_strings:
58+
fd = imp.find_module('module_' + mod, self.test_path)[0]
59+
self.assertEqual(fd.encoding, encoding)
4960

5061
def test_issue1267(self):
51-
fp, filename, info = imp.find_module("pydoc")
52-
self.assertNotEqual(fp, None)
53-
self.assertEqual(fp.encoding, "iso-8859-1")
54-
self.assertEqual(fp.tell(), 0)
55-
self.assertEqual(fp.readline(), '#!/usr/bin/env python3\n')
56-
fp.close()
62+
for mod, encoding, _ in self.test_strings:
63+
fp, filename, info = imp.find_module('module_' + mod,
64+
self.test_path)
65+
self.assertNotEqual(fp, None)
66+
self.assertEqual(fp.encoding, encoding)
67+
self.assertEqual(fp.tell(), 0)
68+
self.assertEqual(fp.readline(), '# test %s encoding\n'
69+
% encoding)
70+
fp.close()
5771

5872
fp, filename, info = imp.find_module("tokenize")
5973
self.assertNotEqual(fp, None)

Lib/test/test_pep3131.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import unittest
32
from test import support
43

0 commit comments

Comments
 (0)