test_path_hook.py 1.16 KB
Newer Older
1
from .. import util
2

3 4
machinery = util.import_importlib('importlib.machinery')

5 6 7
import unittest


8
class PathHookTest:
9 10 11

    """Test the path hook for source."""

12
    def path_hook(self):
13 14
        return self.machinery.FileFinder.path_hook((self.machinery.SourceFileLoader,
            self.machinery.SOURCE_SUFFIXES))
15

16
    def test_success(self):
17
        with util.create_modules('dummy') as mapping:
18
            self.assertTrue(hasattr(self.path_hook()(mapping['.root']),
19 20 21 22 23 24
                                    'find_spec'))

    def test_success_legacy(self):
        with util.create_modules('dummy') as mapping:
            self.assertTrue(hasattr(self.path_hook()(mapping['.root']),
                                    'find_module'))
25

26
    def test_empty_string(self):
27 28 29 30
        # The empty string represents the cwd.
        self.assertTrue(hasattr(self.path_hook()(''), 'find_spec'))

    def test_empty_string_legacy(self):
31
        # The empty string represents the cwd.
32
        self.assertTrue(hasattr(self.path_hook()(''), 'find_module'))
33

34 35 36 37

(Frozen_PathHookTest,
 Source_PathHooktest
 ) = util.test_both(PathHookTest, machinery=machinery)
38 39 40


if __name__ == '__main__':
41
    unittest.main()