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

Side by Side Diff: Lib/test/test_pkgutil.py

Issue 23014: Don't have importlib.abc.Loader.create_module() be optional
Patch Set: Created 4 years, 7 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 test.support import run_unittest, unload, check_warnings, CleanImport 1 from test.support import run_unittest, unload, check_warnings, CleanImport
2 import unittest 2 import unittest
3 import sys 3 import sys
4 import importlib 4 import importlib
5 from importlib.util import spec_from_file_location 5 from importlib.util import spec_from_file_location
6 import pkgutil 6 import pkgutil
7 import os 7 import os
8 import os.path 8 import os.path
9 import tempfile 9 import tempfile
10 import types 10 import types
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 # this does not appear to create an unreadable dir on Windows 97 # this does not appear to create an unreadable dir on Windows
98 # but the test should not fail anyway 98 # but the test should not fail anyway
99 os.mkdir(d, 0) 99 os.mkdir(d, 0)
100 self.addCleanup(os.rmdir, d) 100 self.addCleanup(os.rmdir, d)
101 for t in pkgutil.walk_packages(path=[self.dirname]): 101 for t in pkgutil.walk_packages(path=[self.dirname]):
102 self.fail("unexpected package found") 102 self.fail("unexpected package found")
103 103
104 class PkgutilPEP302Tests(unittest.TestCase): 104 class PkgutilPEP302Tests(unittest.TestCase):
105 105
106 class MyTestLoader(object): 106 class MyTestLoader(object):
107 def create_module(self, spec):
108 return None
109
107 def exec_module(self, mod): 110 def exec_module(self, mod):
108 # Count how many times the module is reloaded 111 # Count how many times the module is reloaded
109 mod.__dict__['loads'] = mod.__dict__.get('loads', 0) + 1 112 mod.__dict__['loads'] = mod.__dict__.get('loads', 0) + 1
110 113
111 def get_data(self, path): 114 def get_data(self, path):
112 return "Hello, world!" 115 return "Hello, world!"
113 116
114 class MyTestImporter(object): 117 class MyTestImporter(object):
115 def find_spec(self, fullname, path=None, target=None): 118 def find_spec(self, fullname, path=None, target=None):
116 loader = PkgutilPEP302Tests.MyTestLoader() 119 loader = PkgutilPEP302Tests.MyTestLoader()
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 NestedNamespacePackageTest, ImportlibMigrationTests) 404 NestedNamespacePackageTest, ImportlibMigrationTests)
402 # this is necessary if test is run repeated (like when finding leaks) 405 # this is necessary if test is run repeated (like when finding leaks)
403 import zipimport 406 import zipimport
404 import importlib 407 import importlib
405 zipimport._zip_directory_cache.clear() 408 zipimport._zip_directory_cache.clear()
406 importlib.invalidate_caches() 409 importlib.invalidate_caches()
407 410
408 411
409 if __name__ == '__main__': 412 if __name__ == '__main__':
410 test_main() 413 test_main()
OLDNEW
« Lib/test/test_importlib/test_util.py ('K') | « Lib/test/test_importlib/test_util.py ('k') | no next file » | no next file with comments »

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