From f254a75176928e1d1228a5d20d49fbe2fe9f290a Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 30 Jan 2009 00:22:35 +0000 Subject: Merge testing ABCs for importlib into importlib.test.abc. --- Lib/importlib/test/abc.py | 98 +++++++++++++++++++++++++++++ Lib/importlib/test/builtin/test_finder.py | 4 +- Lib/importlib/test/extension/test_finder.py | 4 +- Lib/importlib/test/finder_tests.py | 39 ------------ Lib/importlib/test/frozen/test_finder.py | 4 +- Lib/importlib/test/loader_tests.py | 61 ------------------ Lib/importlib/test/source/test_finder.py | 4 +- 7 files changed, 106 insertions(+), 108 deletions(-) create mode 100644 Lib/importlib/test/abc.py delete mode 100644 Lib/importlib/test/finder_tests.py delete mode 100644 Lib/importlib/test/loader_tests.py diff --git a/Lib/importlib/test/abc.py b/Lib/importlib/test/abc.py new file mode 100644 index 0000000..4acbfc9 --- /dev/null +++ b/Lib/importlib/test/abc.py @@ -0,0 +1,98 @@ +import abc +import unittest + + +class FinderTests(unittest.TestCase, metaclass=abc.ABCMeta): + + """Basic tests for a finder to pass.""" + + @abc.abstractmethod + def test_module(self): + # Test importing a top-level module. + pass + + @abc.abstractmethod + def test_package(self): + # Test importing a package. + pass + + @abc.abstractmethod + def test_module_in_package(self): + # Test importing a module contained within a package. + # A value for 'path' should be used if for a meta_path finder. + pass + + @abc.abstractmethod + def test_package_in_package(self): + # Test importing a subpackage. + # A value for 'path' should be used if for a meta_path finder. + pass + + @abc.abstractmethod + def test_package_over_module(self): + # Test that packages are chosen over modules. + pass + + @abc.abstractmethod + def test_failure(self): + # Test trying to find a module that cannot be handled. + pass + + +class LoaderTests(unittest.TestCase, metaclass=abc.ABCMeta): + + @abc.abstractmethod + def test_module(self): + """A module should load without issue. + + After the loader returns the module should be in sys.modules. + + Attributes to verify: + + * __file__ + * __loader__ + * __name__ + * No __path__ + + """ + pass + + @abc.abstractmethod + def test_package(self): + """Loading a package should work. + + After the loader returns the module should be in sys.modules. + + Attributes to verify: + + * __file__ + * __loader__ + * __name__ + * __path__ + + """ + pass + + @abc.abstractmethod + def test_lacking_parent(self): + """A loader should not be dependent on it's parent package being + imported.""" + pass + + @abc.abstractmethod + def test_module_reuse(self): + """If a module is already in sys.modules, it should be reused.""" + pass + + @abc.abstractmethod + def test_state_after_failure(self): + """If a module is already in sys.modules and a reload fails + (e.g. a SyntaxError), the module should be in the state it was before + the reload began.""" + pass + + @abc.abstractmethod + def test_unloadable(self): + """Test ImportError is raised when the loader is asked to load a module + it can't.""" + pass diff --git a/Lib/importlib/test/builtin/test_finder.py b/Lib/importlib/test/builtin/test_finder.py index 5849b5e..70aed97 100644 --- a/Lib/importlib/test/builtin/test_finder.py +++ b/Lib/importlib/test/builtin/test_finder.py @@ -1,11 +1,11 @@ from importlib import machinery -from .. import finder_tests +from .. import abc from .. import support import sys import unittest -class FinderTests(finder_tests.FinderTests): +class FinderTests(abc.FinderTests): """Test find_module() for built-in modules.""" diff --git a/Lib/importlib/test/extension/test_finder.py b/Lib/importlib/test/extension/test_finder.py index 1daa97a..c22186c 100644 --- a/Lib/importlib/test/extension/test_finder.py +++ b/Lib/importlib/test/extension/test_finder.py @@ -1,10 +1,10 @@ import importlib -from .. import finder_tests +from .. import abc from . import test_path_hook import unittest -class FinderTests(finder_tests.FinderTests): +class FinderTests(abc.FinderTests): """Test the finder for extension modules.""" diff --git a/Lib/importlib/test/finder_tests.py b/Lib/importlib/test/finder_tests.py deleted file mode 100644 index 3cf2c95..0000000 --- a/Lib/importlib/test/finder_tests.py +++ /dev/null @@ -1,39 +0,0 @@ -import abc -import unittest - - -class FinderTests(unittest.TestCase, metaclass=abc.ABCMeta): - - """Basic tests for a finder to pass.""" - - @abc.abstractmethod - def test_module(self): - # Test importing a top-level module. - pass - - @abc.abstractmethod - def test_package(self): - # Test importing a package. - pass - - @abc.abstractmethod - def test_module_in_package(self): - # Test importing a module contained within a package. - # A value for 'path' should be used if for a meta_path finder. - pass - - @abc.abstractmethod - def test_package_in_package(self): - # Test importing a subpackage. - # A value for 'path' should be used if for a meta_path finder. - pass - - @abc.abstractmethod - def test_package_over_module(self): - # Test that packages are chosen over modules. - pass - - @abc.abstractmethod - def test_failure(self): - # Test trying to find a module that cannot be handled. - pass diff --git a/Lib/importlib/test/frozen/test_finder.py b/Lib/importlib/test/frozen/test_finder.py index 9dd54b4..8caac48 100644 --- a/Lib/importlib/test/frozen/test_finder.py +++ b/Lib/importlib/test/frozen/test_finder.py @@ -1,10 +1,10 @@ from ... import machinery -from .. import finder_tests +from .. import abc import unittest -class FinderTests(finder_tests.FinderTests): +class FinderTests(abc.FinderTests): """Test finding frozen modules.""" diff --git a/Lib/importlib/test/loader_tests.py b/Lib/importlib/test/loader_tests.py deleted file mode 100644 index 15faf0b..0000000 --- a/Lib/importlib/test/loader_tests.py +++ /dev/null @@ -1,61 +0,0 @@ -import abc -import unittest - - -class LoaderTests(unittest.TestCase, metaclass=abc.ABCMeta): - - @abc.abstractmethod - def test_module(self): - """A module should load without issue. - - After the loader returns the module should be in sys.modules. - - Attributes to verify: - - * __file__ - * __loader__ - * __name__ - * No __path__ - - """ - pass - - @abc.abstractmethod - def test_package(self): - """Loading a package should work. - - After the loader returns the module should be in sys.modules. - - Attributes to verify: - - * __file__ - * __loader__ - * __name__ - * __path__ - - """ - pass - - @abc.abstractmethod - def test_lacking_parent(self): - """A loader should not be dependent on it's parent package being - imported.""" - pass - - @abc.abstractmethod - def test_module_reuse(self): - """If a module is already in sys.modules, it should be reused.""" - pass - - @abc.abstractmethod - def test_state_after_failure(self): - """If a module is already in sys.modules and a reload fails - (e.g. a SyntaxError), the module should be in the state it was before - the reload began.""" - pass - - @abc.abstractmethod - def test_unloadable(self): - """Test ImportError is raised when the loader is asked to load a module - it can't.""" - pass diff --git a/Lib/importlib/test/source/test_finder.py b/Lib/importlib/test/source/test_finder.py index cf80799..63cb436 100644 --- a/Lib/importlib/test/source/test_finder.py +++ b/Lib/importlib/test/source/test_finder.py @@ -1,5 +1,5 @@ import importlib -from .. import finder_tests +from .. import abc from .. import support import os import py_compile @@ -7,7 +7,7 @@ import unittest import warnings -class FinderTests(finder_tests.FinderTests): +class FinderTests(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 -- cgit v0.12