-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify implementation of lazy modules and add tests for it
- Loading branch information
1 parent
3292155
commit 509a79a
Showing
2 changed files
with
74 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
# ----------------------------------------------------------------------------- | ||
# Copyright (c) 2009- Spyder Kernels Contributors | ||
# | ||
# Licensed under the terms of the MIT License | ||
# (see spyder_kernels/__init__.py for details) | ||
# ----------------------------------------------------------------------------- | ||
|
||
import pytest | ||
|
||
from spyder_kernels.utils.lazymodules import _LazyModuleLoader, FakeObject | ||
|
||
|
||
def test_non_existent_module(): | ||
"""Test that we retun FakeObject's for non-existing modules.""" | ||
mod = _LazyModuleLoader('no_module', second_level_attrs=['a']) | ||
|
||
# First level attributes must return FakeObject | ||
assert mod.foo is FakeObject | ||
|
||
# Second level attributes in second_level_attrs should return | ||
# FakeObject too. | ||
assert mod.foo.a is FakeObject | ||
|
||
# Other second level attributes should raise an error. | ||
with pytest.raises(AttributeError): | ||
mod.foo.b | ||
|
||
|
||
def test_existing_modules(): | ||
"""Test that lazy modules work for existing modules.""" | ||
np = _LazyModuleLoader('numpy') | ||
import numpy | ||
|
||
# Both the lazy and actual modules should return the same. | ||
assert np.ndarray == numpy.ndarray | ||
|
||
# The lazy module should have these extra attributes | ||
assert np.__spy_mod__ | ||
assert np.__spy_modname__ |