Debian Codegraph @

tests/test_importstring.py

raw
1 """Tests for IPython.utils.importstring."""
2
3 # -----------------------------------------------------------------------------
4 # Copyright (C) 2013 The IPython Development Team
5 #
6 # Distributed under the terms of the BSD License. The full license is in
7 # the file COPYING, distributed as part of this software.
8 # -----------------------------------------------------------------------------
9
10 # -----------------------------------------------------------------------------
11 # Imports
12 # -----------------------------------------------------------------------------
13
14 import pytest
15
16 from IPython.utils.importstring import import_item
17
18 # -----------------------------------------------------------------------------
19 # Tests
20 # -----------------------------------------------------------------------------
21
22
23 def test_import_plain():
24 "Test simple imports"
25 import os
26
27 os2 = import_item("os")
28 assert os is os2
29
30
31 def test_import_nested():
32 "Test nested imports from the stdlib"
33 from os import path
34
35 path2 = import_item("os.path")
36 assert path is path2
37
38
39 def test_import_raises():
40 "Test that failing imports raise the right exception"
41 pytest.raises(ImportError, import_item, "IPython.foobar")