diff options
author | Brett Cannon <brett@python.org> | 2013-06-16 22:37:53 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-06-16 22:37:53 (GMT) |
commit | f24fecd4ac9050799d02a8354b7acfa12b65b1d3 (patch) | |
tree | 332e7e70c73bfbe61754e95a173aadbbe6e004a4 /Lib/test/test_importlib | |
parent | f4375ef4d458bf24610ffef591f8197a3dbf0b35 (diff) | |
download | cpython-f24fecd4ac9050799d02a8354b7acfa12b65b1d3.zip cpython-f24fecd4ac9050799d02a8354b7acfa12b65b1d3.tar.gz cpython-f24fecd4ac9050799d02a8354b7acfa12b65b1d3.tar.bz2 |
Issue #18076: Introduce imoportlib.util.decode_source().
The helper function makes it easier to implement
imoprtlib.abc.InspectLoader.get_source() by making that function
require just the raw bytes for source code and handling all other
details.
Diffstat (limited to 'Lib/test/test_importlib')
-rw-r--r-- | Lib/test/test_importlib/test_util.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_importlib/test_util.py b/Lib/test/test_importlib/test_util.py index 111607b..5fcbdae 100644 --- a/Lib/test/test_importlib/test_util.py +++ b/Lib/test/test_importlib/test_util.py @@ -9,6 +9,27 @@ import unittest import warnings +class DecodeSourceBytesTests(unittest.TestCase): + + source = "string ='ΓΌ'" + + def test_ut8_default(self): + source_bytes = self.source.encode('utf-8') + self.assertEqual(util.decode_source(source_bytes), self.source) + + def test_specified_encoding(self): + source = '# coding=latin-1\n' + self.source + source_bytes = source.encode('latin-1') + assert source_bytes != source.encode('utf-8') + self.assertEqual(util.decode_source(source_bytes), source) + + def test_universal_newlines(self): + source = '\r\n'.join([self.source, self.source]) + source_bytes = source.encode('utf-8') + self.assertEqual(util.decode_source(source_bytes), + '\n'.join([self.source, self.source])) + + class ModuleToLoadTests(unittest.TestCase): module_name = 'ModuleManagerTest_module' |