-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from ericpre/lazy_import
Lazy import
- Loading branch information
Showing
5 changed files
with
82 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,49 @@ | ||
import unittest | ||
import pytest | ||
|
||
import hyperspy.api as hs | ||
import hyperspy.ui_registry | ||
|
||
|
||
class Test(unittest.TestCase): | ||
|
||
def test_registry(self): | ||
if "traitsui" in hyperspy.ui_registry.TOOLKIT_REGISTRY: | ||
self.assertTrue("traitsui" in hyperspy.ui_registry.TOOLKIT_REGISTRY) | ||
def test_ui_registry(): | ||
if "traitsui" in hyperspy.ui_registry.TOOLKIT_REGISTRY: | ||
assert "traitsui" in hyperspy.ui_registry.TOOLKIT_REGISTRY | ||
else: | ||
if "ipywidgets" in hyperspy.ui_registry.TOOLKIT_REGISTRY: | ||
with pytest.raises(ValueError): | ||
hs.preferences.gui(toolkit="traitsui") | ||
else: | ||
if "ipywidgets" in hyperspy.ui_registry.TOOLKIT_REGISTRY: | ||
with self.assertRaises(ValueError): | ||
hs.preferences.gui(toolkit="traitsui") | ||
else: | ||
# As ipywidgets is not installed it should raise an import error | ||
with self.assertRaises(ImportError): | ||
hs.preferences.gui(toolkit="traitsui") | ||
# As ipywidgets is not installed it should raise an import error | ||
with pytest.raises(ImportError): | ||
hs.preferences.gui(toolkit="traitsui") | ||
|
||
|
||
def test_import_version(): | ||
from hyperspy_gui_traitsui import __version__ | ||
|
||
|
||
def test_import(): | ||
import hyperspy_gui_traitsui | ||
for obj_name in hyperspy_gui_traitsui.__all__: | ||
getattr(hyperspy_gui_traitsui, obj_name) | ||
|
||
|
||
def test_import_import_error(): | ||
import hyperspy_gui_traitsui | ||
try: | ||
hyperspy_gui_traitsui.inexisting_module | ||
except AttributeError: | ||
pass | ||
|
||
|
||
def test_dir(): | ||
import hyperspy_gui_traitsui | ||
d = dir(hyperspy_gui_traitsui) | ||
assert d == [ | ||
'__version__', | ||
'axes', | ||
'messages', | ||
'microscope_parameters', | ||
'model', | ||
'preferences', | ||
'tools', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters