mirror of
https://github.com/python/cpython.git
synced 2025-10-26 19:24:34 +00:00
Issue #19712: Update test.test_importlib.source for PEP 451
This commit is contained in:
parent
86aae6a7b3
commit
2f8c83568c
4 changed files with 140 additions and 24 deletions
|
|
@ -4,8 +4,10 @@
|
|||
machinery = util.import_importlib('importlib.machinery')
|
||||
|
||||
import codecs
|
||||
import importlib.util
|
||||
import re
|
||||
import sys
|
||||
import types
|
||||
# Because sys.path gets essentially blanked, need to have unicodedata already
|
||||
# imported for the parser to use.
|
||||
import unicodedata
|
||||
|
|
@ -39,7 +41,7 @@ def run_test(self, source):
|
|||
file.write(source)
|
||||
loader = self.machinery.SourceFileLoader(self.module_name,
|
||||
mapping[self.module_name])
|
||||
return loader.load_module(self.module_name)
|
||||
return self.load(loader)
|
||||
|
||||
def create_source(self, encoding):
|
||||
encoding_line = "# coding={0}".format(encoding)
|
||||
|
|
@ -86,7 +88,24 @@ def test_bom_conflict(self):
|
|||
with self.assertRaises(SyntaxError):
|
||||
self.run_test(source)
|
||||
|
||||
Frozen_EncodingTest, Source_EncodingTest = util.test_both(EncodingTest, machinery=machinery)
|
||||
class EncodingTestPEP451(EncodingTest):
|
||||
|
||||
def load(self, loader):
|
||||
module = types.ModuleType(self.module_name)
|
||||
module.__spec__ = importlib.util.spec_from_loader(self.module_name, loader)
|
||||
loader.exec_module(module)
|
||||
return module
|
||||
|
||||
Frozen_EncodingTestPEP451, Source_EncodingTestPEP451 = util.test_both(
|
||||
EncodingTestPEP451, machinery=machinery)
|
||||
|
||||
class EncodingTestPEP302(EncodingTest):
|
||||
|
||||
def load(self, loader):
|
||||
return loader.load_module(self.module_name)
|
||||
|
||||
Frozen_EncodingTestPEP302, Source_EncodingTestPEP302 = util.test_both(
|
||||
EncodingTestPEP302, machinery=machinery)
|
||||
|
||||
|
||||
class LineEndingTest:
|
||||
|
|
@ -117,8 +136,24 @@ def test_crlf(self):
|
|||
def test_lf(self):
|
||||
self.run_test(b'\n')
|
||||
|
||||
Frozen_LineEndings, Source_LineEndings = util.test_both(LineEndingTest, machinery=machinery)
|
||||
class LineEndingTestPEP451(LineEndingTest):
|
||||
|
||||
def load(self, loader):
|
||||
module = types.ModuleType(self.module_name)
|
||||
module.__spec__ = importlib.util.spec_from_loader(self.module_name, loader)
|
||||
loader.exec_module(module)
|
||||
return module
|
||||
|
||||
Frozen_LineEndingTestPEP451, Source_LineEndingTestPEP451 = util.test_both(
|
||||
LineEndingTestPEP451, machinery=machinery)
|
||||
|
||||
class LineEndingTestPEP302(LineEndingTest):
|
||||
|
||||
def load(self, loader):
|
||||
return loader.load_module(self.module_name)
|
||||
|
||||
Frozen_LineEndingTestPEP302, Source_LineEndingTestPEP302 = util.test_both(
|
||||
LineEndingTestPEP302, machinery=machinery)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue