|
5 | 5 | import sys |
6 | 6 | import unittest |
7 | 7 | from test import support |
8 | | - |
| 8 | +import importlib |
9 | 9 |
|
10 | 10 | class LockTests(unittest.TestCase): |
11 | 11 |
|
@@ -42,18 +42,32 @@ def testLock(self): |
42 | 42 | "RuntimeError") |
43 | 43 |
|
44 | 44 | 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) |
45 | 55 |
|
46 | 56 | 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) |
49 | 60 |
|
50 | 61 | 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() |
57 | 71 |
|
58 | 72 | fp, filename, info = imp.find_module("tokenize") |
59 | 73 | self.assertNotEqual(fp, None) |
|
0 commit comments