test_importstring.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """Tests for IPython.utils.importstring."""
  2. #-----------------------------------------------------------------------------
  3. # Copyright (C) 2013 The IPython Development Team
  4. #
  5. # Distributed under the terms of the BSD License. The full license is in
  6. # the file COPYING, distributed as part of this software.
  7. #-----------------------------------------------------------------------------
  8. #-----------------------------------------------------------------------------
  9. # Imports
  10. #-----------------------------------------------------------------------------
  11. import nose.tools as nt
  12. from IPython.utils.importstring import import_item
  13. #-----------------------------------------------------------------------------
  14. # Tests
  15. #-----------------------------------------------------------------------------
  16. def test_import_plain():
  17. "Test simple imports"
  18. import os
  19. os2 = import_item('os')
  20. nt.assert_true(os is os2)
  21. def test_import_nested():
  22. "Test nested imports from the stdlib"
  23. from os import path
  24. path2 = import_item('os.path')
  25. nt.assert_true(path is path2)
  26. def test_import_raises():
  27. "Test that failing imports raise the right exception"
  28. nt.assert_raises(ImportError, import_item, 'IPython.foobar')