test_importstring.py 883 B

123456789101112131415161718192021222324252627282930
  1. # encoding: utf-8
  2. # Copyright (c) IPython Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. #
  5. # Adapted from enthought.traits, Copyright (c) Enthought, Inc.,
  6. # also under the terms of the Modified BSD License.
  7. """Tests for traitlets.utils.importstring."""
  8. import os
  9. from unittest import TestCase
  10. from ..importstring import import_item
  11. class TestImportItem(TestCase):
  12. def test_import_unicode(self):
  13. self.assertIs(os, import_item(u'os'))
  14. self.assertIs(os.path, import_item(u'os.path'))
  15. self.assertIs(os.path.join, import_item(u'os.path.join'))
  16. def test_bad_input(self):
  17. class NotAString(object):
  18. pass
  19. msg = (
  20. "import_item accepts strings, "
  21. "not '%s'." % NotAString
  22. )
  23. with self.assertRaisesRegexp(TypeError, msg):
  24. import_item(NotAString())