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 def test_import_plain(): 23 "Test simple imports" 24 import os 25 26 os2 = import_item("os") 27 assert os is os2 28 29 30 def test_import_nested(): 31 "Test nested imports from the stdlib" 32 from os import path 33 34 path2 = import_item("os.path") 35 assert path is path2 36 37 38 def test_import_raises(): 39 "Test that failing imports raise the right exception" 40 pytest.raises(ImportError, import_item, "IPython.foobar") 41