File: test_loader.py

package info (click to toggle)
python3.2 3.2.3-7
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 62,476 kB
  • sloc: python: 344,518; ansic: 315,782; sh: 11,910; asm: 10,846; makefile: 3,564; objc: 775; cpp: 432; exp: 416; xml: 73
file content (59 lines) | stat: -rw-r--r-- 1,784 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from importlib import _bootstrap
from . import util as ext_util
from .. import abc
from .. import util

import sys
import unittest


class LoaderTests(abc.LoaderTests):

    """Test load_module() for extension modules."""

    def load_module(self, fullname):
        loader = _bootstrap._ExtensionFileLoader(ext_util.NAME,
                                                ext_util.FILEPATH)
        return loader.load_module(fullname)

    def test_module(self):
        with util.uncache(ext_util.NAME):
            module = self.load_module(ext_util.NAME)
            for attr, value in [('__name__', ext_util.NAME),
                                ('__file__', ext_util.FILEPATH),
                                ('__package__', '')]:
                self.assertEqual(getattr(module, attr), value)
            self.assertTrue(ext_util.NAME in sys.modules)
            self.assertTrue(isinstance(module.__loader__,
                                    _bootstrap._ExtensionFileLoader))

    def test_package(self):
        # Extensions are not found in packages.
        pass

    def test_lacking_parent(self):
        # Extensions are not found in packages.
        pass

    def test_module_reuse(self):
        with util.uncache(ext_util.NAME):
            module1 = self.load_module(ext_util.NAME)
            module2 = self.load_module(ext_util.NAME)
            self.assertTrue(module1 is module2)

    def test_state_after_failure(self):
        # No easy way to trigger a failure after a successful import.
        pass

    def test_unloadable(self):
        with self.assertRaises(ImportError):
            self.load_module('asdfjkl;')


def test_main():
    from test.support import run_unittest
    run_unittest(LoaderTests)


if __name__ == '__main__':
    test_main()