Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(235829)

Side by Side Diff: Lib/test/test_importlib/test_util.py

Issue 23014: Don't have importlib.abc.Loader.create_module() be optional
Patch Set: Created 4 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 from . import util 1 from . import util
2 abc = util.import_importlib('importlib.abc') 2 abc = util.import_importlib('importlib.abc')
3 init = util.import_importlib('importlib') 3 init = util.import_importlib('importlib')
4 machinery = util.import_importlib('importlib.machinery') 4 machinery = util.import_importlib('importlib.machinery')
5 importlib_util = util.import_importlib('importlib.util') 5 importlib_util = util.import_importlib('importlib.util')
6 6
7 import os 7 import os
8 import sys 8 import sys
9 from test import support 9 from test import support
10 import types 10 import types
(...skipping 23 matching lines...) Expand all
34 34
35 35
36 (Frozen_DecodeSourceBytesTests, 36 (Frozen_DecodeSourceBytesTests,
37 Source_DecodeSourceBytesTests 37 Source_DecodeSourceBytesTests
38 ) = util.test_both(DecodeSourceBytesTests, util=importlib_util) 38 ) = util.test_both(DecodeSourceBytesTests, util=importlib_util)
39 39
40 40
41 class ModuleFromSpecTests: 41 class ModuleFromSpecTests:
42 42
43 def test_no_create_module(self): 43 def test_no_create_module(self):
44 class Loader(self.abc.Loader): 44 class Loader:
45 pass 45 def exec_module(self, module):
46 pass
46 spec = self.machinery.ModuleSpec('test', Loader()) 47 spec = self.machinery.ModuleSpec('test', Loader())
47 module = self.util.module_from_spec(spec) 48 with warnings.catch_warnings(record=True) as w:
49 warnings.simplefilter('always')
50 module = self.util.module_from_spec(spec)
51 self.assertEqual(1, len(w))
berkerpeksag 2014/12/12 20:07:45 ``self.assertEqual(len(w), 1)`` looks more readabl
52 self.assertTrue(issubclass(w[0].category, DeprecationWarning))
53 self.assertIn('create_module', str(w[0].message))
48 self.assertIsInstance(module, types.ModuleType) 54 self.assertIsInstance(module, types.ModuleType)
49 self.assertEqual(module.__name__, spec.name) 55 self.assertEqual(module.__name__, spec.name)
50 56
51 def test_create_module_returns_None(self): 57 def test_create_module_returns_None(self):
52 class Loader(self.abc.Loader): 58 class Loader(self.abc.Loader):
53 def create_module(self, spec): 59 def create_module(self, spec):
54 return None 60 return None
55 spec = self.machinery.ModuleSpec('test', Loader()) 61 spec = self.machinery.ModuleSpec('test', Loader())
56 module = self.util.module_from_spec(spec) 62 module = self.util.module_from_spec(spec)
57 self.assertIsInstance(module, types.ModuleType) 63 self.assertIsInstance(module, types.ModuleType)
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 '/foo/bar/foo.cpython-32.foo.pyc') 670 '/foo/bar/foo.cpython-32.foo.pyc')
665 671
666 672
667 (Frozen_PEP3147Tests, 673 (Frozen_PEP3147Tests,
668 Source_PEP3147Tests 674 Source_PEP3147Tests
669 ) = util.test_both(PEP3147Tests, util=importlib_util) 675 ) = util.test_both(PEP3147Tests, util=importlib_util)
670 676
671 677
672 if __name__ == '__main__': 678 if __name__ == '__main__':
673 unittest.main() 679 unittest.main()
OLDNEW

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+