Commit 08b14a60 authored by Brett Cannon's avatar Brett Cannon

Issue #15168: Move importlb.test to test.test_importlib.

This should make the Linux distros happy as it is now easier to leave
importlib's tests out of their base Python distribution.
parent c24136c5
from importlib.test.__main__ import test_main
if __name__ == '__main__':
test_main()
import os import os
import sys import sys
from .. import support
import unittest import unittest
def test_suite(package=__package__, directory=os.path.dirname(__file__)): def test_suite(package=__package__, directory=os.path.dirname(__file__)):
...@@ -23,3 +24,10 @@ def test_suite(package=__package__, directory=os.path.dirname(__file__)): ...@@ -23,3 +24,10 @@ def test_suite(package=__package__, directory=os.path.dirname(__file__)):
else: else:
continue continue
return suite return suite
def test_main():
start_dir = os.path.dirname(__file__)
top_dir = os.path.dirname(os.path.dirname(start_dir))
test_loader = unittest.TestLoader()
support.run_unittest(test_loader.discover(start_dir, top_level_dir=top_dir))
...@@ -4,17 +4,7 @@ Specifying the ``--builtin`` flag will run tests, where applicable, with ...@@ -4,17 +4,7 @@ Specifying the ``--builtin`` flag will run tests, where applicable, with
builtins.__import__ instead of importlib.__import__. builtins.__import__ instead of importlib.__import__.
""" """
from importlib.test.import_ import util from . import test_main
import os.path
from test.support import run_unittest
import unittest
def test_main():
start_dir = os.path.dirname(__file__)
top_dir = os.path.dirname(os.path.dirname(start_dir))
test_loader = unittest.TestLoader()
run_unittest(test_loader.discover(start_dir, top_level_dir=top_dir))
if __name__ == '__main__': if __name__ == '__main__':
......
import importlib.test from .. import test_suite
import os import os
def test_suite(): def test_suite():
directory = os.path.dirname(__file__) directory = os.path.dirname(__file__)
return importlib.test.test_suite('importlib.test.builtin', directory) return test_suite('importlib.test.builtin', directory)
if __name__ == '__main__': if __name__ == '__main__':
......
import importlib.test from .. import test_suite
import os.path import os.path
import unittest import unittest
def test_suite(): def test_suite():
directory = os.path.dirname(__file__) directory = os.path.dirname(__file__)
return importlib.test.test_suite('importlib.test.source', directory) return test_suite('importlib.test.extension', directory)
if __name__ == '__main__': if __name__ == '__main__':
......
import importlib.test from .. import test_suite
import os.path import os.path
import unittest import unittest
def test_suite(): def test_suite():
directory = os.path.dirname(__file__) directory = os.path.dirname(__file__)
return importlib.test.test_suite('importlib.test.frozen', directory) return test_suite('importlib.test.frozen', directory)
if __name__ == '__main__': if __name__ == '__main__':
......
from ... import machinery from importlib import machinery
from .. import abc from .. import abc
import unittest import unittest
......
import importlib.test from .. import test_suite
import os.path import os.path
import unittest import unittest
def test_suite(): def test_suite():
directory = os.path.dirname(__file__) directory = os.path.dirname(__file__)
return importlib.test.test_suite('importlib.test.import_', directory) return test_suite('importlib.test.import_', directory)
if __name__ == '__main__': if __name__ == '__main__':
......
import importlib.test from .. import test_suite
import os.path import os.path
import unittest import unittest
def test_suite(): def test_suite():
directory = os.path.dirname(__file__) directory = os.path.dirname(__file__)
return importlib.test.test_suite('importlib.test.extension', directory) return test.test_suite('importlib.test.source', directory)
if __name__ == '__main__': if __name__ == '__main__':
......
from ... import _bootstrap from importlib import machinery
import importlib import importlib
import importlib.abc import importlib.abc
from .. import abc from .. import abc
...@@ -62,7 +62,7 @@ class SimpleTest(unittest.TestCase): ...@@ -62,7 +62,7 @@ class SimpleTest(unittest.TestCase):
# [basic] # [basic]
def test_module(self): def test_module(self):
with source_util.create_modules('_temp') as mapping: with source_util.create_modules('_temp') as mapping:
loader = _bootstrap.SourceFileLoader('_temp', mapping['_temp']) loader = machinery.SourceFileLoader('_temp', mapping['_temp'])
module = loader.load_module('_temp') module = loader.load_module('_temp')
self.assertIn('_temp', sys.modules) self.assertIn('_temp', sys.modules)
check = {'__name__': '_temp', '__file__': mapping['_temp'], check = {'__name__': '_temp', '__file__': mapping['_temp'],
...@@ -72,7 +72,7 @@ class SimpleTest(unittest.TestCase): ...@@ -72,7 +72,7 @@ class SimpleTest(unittest.TestCase):
def test_package(self): def test_package(self):
with source_util.create_modules('_pkg.__init__') as mapping: with source_util.create_modules('_pkg.__init__') as mapping:
loader = _bootstrap.SourceFileLoader('_pkg', loader = machinery.SourceFileLoader('_pkg',
mapping['_pkg.__init__']) mapping['_pkg.__init__'])
module = loader.load_module('_pkg') module = loader.load_module('_pkg')
self.assertIn('_pkg', sys.modules) self.assertIn('_pkg', sys.modules)
...@@ -85,7 +85,7 @@ class SimpleTest(unittest.TestCase): ...@@ -85,7 +85,7 @@ class SimpleTest(unittest.TestCase):
def test_lacking_parent(self): def test_lacking_parent(self):
with source_util.create_modules('_pkg.__init__', '_pkg.mod')as mapping: with source_util.create_modules('_pkg.__init__', '_pkg.mod')as mapping:
loader = _bootstrap.SourceFileLoader('_pkg.mod', loader = machinery.SourceFileLoader('_pkg.mod',
mapping['_pkg.mod']) mapping['_pkg.mod'])
module = loader.load_module('_pkg.mod') module = loader.load_module('_pkg.mod')
self.assertIn('_pkg.mod', sys.modules) self.assertIn('_pkg.mod', sys.modules)
...@@ -100,7 +100,7 @@ class SimpleTest(unittest.TestCase): ...@@ -100,7 +100,7 @@ class SimpleTest(unittest.TestCase):
def test_module_reuse(self): def test_module_reuse(self):
with source_util.create_modules('_temp') as mapping: with source_util.create_modules('_temp') as mapping:
loader = _bootstrap.SourceFileLoader('_temp', mapping['_temp']) loader = machinery.SourceFileLoader('_temp', mapping['_temp'])
module = loader.load_module('_temp') module = loader.load_module('_temp')
module_id = id(module) module_id = id(module)
module_dict_id = id(module.__dict__) module_dict_id = id(module.__dict__)
...@@ -125,7 +125,7 @@ class SimpleTest(unittest.TestCase): ...@@ -125,7 +125,7 @@ class SimpleTest(unittest.TestCase):
setattr(orig_module, attr, value) setattr(orig_module, attr, value)
with open(mapping[name], 'w') as file: with open(mapping[name], 'w') as file:
file.write('+++ bad syntax +++') file.write('+++ bad syntax +++')
loader = _bootstrap.SourceFileLoader('_temp', mapping['_temp']) loader = machinery.SourceFileLoader('_temp', mapping['_temp'])
with self.assertRaises(SyntaxError): with self.assertRaises(SyntaxError):
loader.load_module(name) loader.load_module(name)
for attr in attributes: for attr in attributes:
...@@ -136,7 +136,7 @@ class SimpleTest(unittest.TestCase): ...@@ -136,7 +136,7 @@ class SimpleTest(unittest.TestCase):
with source_util.create_modules('_temp') as mapping: with source_util.create_modules('_temp') as mapping:
with open(mapping['_temp'], 'w') as file: with open(mapping['_temp'], 'w') as file:
file.write('=') file.write('=')
loader = _bootstrap.SourceFileLoader('_temp', mapping['_temp']) loader = machinery.SourceFileLoader('_temp', mapping['_temp'])
with self.assertRaises(SyntaxError): with self.assertRaises(SyntaxError):
loader.load_module('_temp') loader.load_module('_temp')
self.assertNotIn('_temp', sys.modules) self.assertNotIn('_temp', sys.modules)
...@@ -149,7 +149,7 @@ class SimpleTest(unittest.TestCase): ...@@ -149,7 +149,7 @@ class SimpleTest(unittest.TestCase):
file.write("# test file for importlib") file.write("# test file for importlib")
try: try:
with util.uncache('_temp'): with util.uncache('_temp'):
loader = _bootstrap.SourceFileLoader('_temp', file_path) loader = machinery.SourceFileLoader('_temp', file_path)
mod = loader.load_module('_temp') mod = loader.load_module('_temp')
self.assertEqual(file_path, mod.__file__) self.assertEqual(file_path, mod.__file__)
self.assertEqual(imp.cache_from_source(file_path), self.assertEqual(imp.cache_from_source(file_path),
...@@ -175,7 +175,7 @@ class SimpleTest(unittest.TestCase): ...@@ -175,7 +175,7 @@ class SimpleTest(unittest.TestCase):
if e.errno != getattr(errno, 'EOVERFLOW', None): if e.errno != getattr(errno, 'EOVERFLOW', None):
raise raise
self.skipTest("cannot set modification time to large integer ({})".format(e)) self.skipTest("cannot set modification time to large integer ({})".format(e))
loader = _bootstrap.SourceFileLoader('_temp', mapping['_temp']) loader = machinery.SourceFileLoader('_temp', mapping['_temp'])
mod = loader.load_module('_temp') mod = loader.load_module('_temp')
# Sanity checks. # Sanity checks.
self.assertEqual(mod.__cached__, compiled) self.assertEqual(mod.__cached__, compiled)
...@@ -290,7 +290,7 @@ class BadBytecodeTest(unittest.TestCase): ...@@ -290,7 +290,7 @@ class BadBytecodeTest(unittest.TestCase):
class SourceLoaderBadBytecodeTest(BadBytecodeTest): class SourceLoaderBadBytecodeTest(BadBytecodeTest):
loader = _bootstrap.SourceFileLoader loader = machinery.SourceFileLoader
@source_util.writes_bytecode_files @source_util.writes_bytecode_files
def test_empty_file(self): def test_empty_file(self):
...@@ -414,7 +414,7 @@ class SourceLoaderBadBytecodeTest(BadBytecodeTest): ...@@ -414,7 +414,7 @@ class SourceLoaderBadBytecodeTest(BadBytecodeTest):
class SourcelessLoaderBadBytecodeTest(BadBytecodeTest): class SourcelessLoaderBadBytecodeTest(BadBytecodeTest):
loader = _bootstrap.SourcelessFileLoader loader = machinery.SourcelessFileLoader
def test_empty_file(self): def test_empty_file(self):
def test(name, mapping, bytecode_path): def test(name, mapping, bytecode_path):
......
...@@ -181,6 +181,8 @@ Documentation ...@@ -181,6 +181,8 @@ Documentation
Tests Tests
----- -----
- Issue #15168: Move importlib.test to test.test_importlib.
- Issue #15091: Reactivate a test on UNIX which was failing thanks to a - Issue #15091: Reactivate a test on UNIX which was failing thanks to a
forgotten importlib.invalidate_caches() call. forgotten importlib.invalidate_caches() call.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment