From b3d6afff2be489a6e6aefbd0826eeacbe565f6d7 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 25 Oct 2013 12:33:59 -0400 Subject: [PATCH] Issue #16803: Stop having test.test_importlib.abc ABCs inherit from unittest.TestCase in prep of running tests under frozen and source importlib. --- Lib/test/test_importlib/abc.py | 4 ++-- Lib/test/test_importlib/builtin/test_finder.py | 9 ++------- Lib/test/test_importlib/builtin/test_loader.py | 2 +- Lib/test/test_importlib/extension/test_finder.py | 2 +- Lib/test/test_importlib/extension/test_loader.py | 2 +- Lib/test/test_importlib/frozen/test_finder.py | 2 +- Lib/test/test_importlib/frozen/test_loader.py | 2 +- Lib/test/test_importlib/source/test_file_loader.py | 7 ++++++- Lib/test/test_importlib/source/test_finder.py | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Lib/test/test_importlib/abc.py b/Lib/test/test_importlib/abc.py index 2c17ac329bc..b9ff3448f7c 100644 --- a/Lib/test/test_importlib/abc.py +++ b/Lib/test/test_importlib/abc.py @@ -2,7 +2,7 @@ import abc import unittest -class FinderTests(unittest.TestCase, metaclass=abc.ABCMeta): +class FinderTests(metaclass=abc.ABCMeta): """Basic tests for a finder to pass.""" @@ -39,7 +39,7 @@ class FinderTests(unittest.TestCase, metaclass=abc.ABCMeta): pass -class LoaderTests(unittest.TestCase, metaclass=abc.ABCMeta): +class LoaderTests(metaclass=abc.ABCMeta): @abc.abstractmethod def test_module(self): diff --git a/Lib/test/test_importlib/builtin/test_finder.py b/Lib/test/test_importlib/builtin/test_finder.py index 146538d891d..4280217cdc6 100644 --- a/Lib/test/test_importlib/builtin/test_finder.py +++ b/Lib/test/test_importlib/builtin/test_finder.py @@ -6,7 +6,7 @@ from . import util as builtin_util import sys import unittest -class FinderTests(abc.FinderTests): +class FinderTests(unittest.TestCase, abc.FinderTests): """Test find_module() for built-in modules.""" @@ -46,10 +46,5 @@ class FinderTests(abc.FinderTests): -def test_main(): - from test.support import run_unittest - run_unittest(FinderTests) - - if __name__ == '__main__': - test_main() + unittest.main() diff --git a/Lib/test/test_importlib/builtin/test_loader.py b/Lib/test/test_importlib/builtin/test_loader.py index 8e186e71560..8eba4e8be42 100644 --- a/Lib/test/test_importlib/builtin/test_loader.py +++ b/Lib/test/test_importlib/builtin/test_loader.py @@ -9,7 +9,7 @@ import types import unittest -class LoaderTests(abc.LoaderTests): +class LoaderTests(unittest.TestCase, abc.LoaderTests): """Test load_module() for built-in modules.""" diff --git a/Lib/test/test_importlib/extension/test_finder.py b/Lib/test/test_importlib/extension/test_finder.py index a63cfdb9b46..8fa32708609 100644 --- a/Lib/test/test_importlib/extension/test_finder.py +++ b/Lib/test/test_importlib/extension/test_finder.py @@ -4,7 +4,7 @@ from . import util import unittest -class FinderTests(abc.FinderTests): +class FinderTests(unittest.TestCase, abc.FinderTests): """Test the finder for extension modules.""" diff --git a/Lib/test/test_importlib/extension/test_loader.py b/Lib/test/test_importlib/extension/test_loader.py index ca5af201c4d..12576252a2d 100644 --- a/Lib/test/test_importlib/extension/test_loader.py +++ b/Lib/test/test_importlib/extension/test_loader.py @@ -8,7 +8,7 @@ import sys import unittest -class LoaderTests(abc.LoaderTests): +class LoaderTests(unittest.TestCase, abc.LoaderTests): """Test load_module() for extension modules.""" diff --git a/Lib/test/test_importlib/frozen/test_finder.py b/Lib/test/test_importlib/frozen/test_finder.py index fa0c2a037e9..1d37c72821d 100644 --- a/Lib/test/test_importlib/frozen/test_finder.py +++ b/Lib/test/test_importlib/frozen/test_finder.py @@ -4,7 +4,7 @@ from .. import abc import unittest -class FinderTests(abc.FinderTests): +class FinderTests(unittest.TestCase, abc.FinderTests): """Test finding frozen modules.""" diff --git a/Lib/test/test_importlib/frozen/test_loader.py b/Lib/test/test_importlib/frozen/test_loader.py index 3e801388d45..eb1f016656d 100644 --- a/Lib/test/test_importlib/frozen/test_loader.py +++ b/Lib/test/test_importlib/frozen/test_loader.py @@ -7,7 +7,7 @@ from test.support import captured_stdout import types -class LoaderTests(abc.LoaderTests): +class LoaderTests(unittest.TestCase, abc.LoaderTests): def test_module(self): with util.uncache('__hello__'), captured_stdout() as stdout: diff --git a/Lib/test/test_importlib/source/test_file_loader.py b/Lib/test/test_importlib/source/test_file_loader.py index 66ad96e68e3..9e035ea97be 100644 --- a/Lib/test/test_importlib/source/test_file_loader.py +++ b/Lib/test/test_importlib/source/test_file_loader.py @@ -19,7 +19,7 @@ import unittest from test.support import make_legacy_pyc, unload -class SimpleTest(unittest.TestCase): +class SimpleTest(unittest.TestCase, abc.LoaderTests): """Should have no issue importing a source module [basic]. And if there is a syntax error, it should raise a SyntaxError [syntax error]. @@ -177,6 +177,11 @@ class SimpleTest(unittest.TestCase): # The pyc file was created. os.stat(compiled) + def test_unloadable(self): + loader = machinery.SourceFileLoader('good name', {}) + with self.assertRaises(ImportError): + loader.load_module('bad name') + class BadBytecodeTest(unittest.TestCase): diff --git a/Lib/test/test_importlib/source/test_finder.py b/Lib/test/test_importlib/source/test_finder.py index 2d70691e5ab..9d6cec05103 100644 --- a/Lib/test/test_importlib/source/test_finder.py +++ b/Lib/test/test_importlib/source/test_finder.py @@ -13,7 +13,7 @@ import unittest import warnings -class FinderTests(abc.FinderTests): +class FinderTests(unittest.TestCase, abc.FinderTests): """For a top-level module, it should just be found directly in the directory being searched. This is true for a directory with source