| 1 |
# (C) Copyright 2007-2025 Enthought, Inc., Austin, TX |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# This software is provided without warranty under the terms of the BSD |
| 5 |
# license included in LICENSE.txt and may be redistributed only under |
| 6 |
# the conditions described in the aforementioned license. The license |
| 7 |
# is also available online at http://www.enthought.com/licenses/BSD.txt |
| 8 |
# |
| 9 |
# Thanks for using Enthought open source! |
| 10 |
""" Tests for the import manager. """ |
| 11 |
|
| 12 |
# Standard library imports. |
| 13 |
import unittest |
| 14 |
|
| 15 |
# Enthought library imports. |
| 16 |
from envisage.api import Application, ImportManager |
| 17 |
|
| 18 |
|
| 19 |
class ImportManagerTestCase(unittest.TestCase): |
| 20 |
"""Tests for the import manager.""" |
| 21 |
|
| 22 |
def setUp(self): |
| 23 |
"""Prepares the test fixture before each test method is called.""" |
| 24 |
|
| 25 |
# We do all of the testing via the application to make sure it offers |
| 26 |
# the same interface! |
| 27 |
self.import_manager = Application(import_manager=ImportManager()) |
| 28 |
|
| 29 |
def test_import_dotted_symbol(self): |
| 30 |
"""import dotted symbol""" |
| 31 |
|
| 32 |
import tarfile |
| 33 |
|
| 34 |
symbol = self.import_manager.import_symbol("tarfile.TarFile") |
| 35 |
self.assertEqual(symbol, tarfile.TarFile) |
| 36 |
|
| 37 |
def test_import_nested_symbol(self): |
| 38 |
"""import nested symbol""" |
| 39 |
|
| 40 |
import tarfile |
| 41 |
|
| 42 |
symbol = self.import_manager.import_symbol("tarfile:TarFile.open") |
| 43 |
self.assertEqual(symbol, tarfile.TarFile.open) |
| 44 |
|
| 45 |
def test_import_dotted_module(self): |
| 46 |
"""import dotted module""" |
| 47 |
|
| 48 |
symbol = self.import_manager.import_symbol( |
| 49 |
"envisage.api:ImportManager" |
| 50 |
) |
| 51 |
self.assertEqual(symbol, ImportManager) |