cpython/Lib/importlib/test/import_/test_api.py
Brett Cannon 6afbaef2fd Raise TypeError if the name given to importlib.__import__() lacks an rpartition
attribute. Was throwing AttributeError before. Discovered when running
test_builtin against importlib.

This exception change is specific to importlib.__import__() and does not apply to
import_module() as it is being done for compatibility reasons only.
2009-08-30 19:08:58 +00:00

22 lines
531 B
Python

from . import util
import unittest
class APITest(unittest.TestCase):
"""Test API-specific details for __import__ (e.g. raising the right
exception when passing in an int for the module name)."""
def test_name_requires_rparition(self):
# Raise TypeError if a non-string is passed in for the module name.
with self.assertRaises(TypeError):
util.import_(42)
def test_main():
from test.support import run_unittest
run_unittest(APITest)
if __name__ == '__main__':
test_main()