##// END OF EJS Templates
Remove deprecated submodule IPython.nbconvert....
Remove deprecated submodule IPython.nbconvert. This has been deprecated since IPython 4.0, pre python 3.6

File last commit:

r27044:7f364bb8
r27210:1d6d1ab9
Show More
test_deepreload.py
56 lines | 1.8 KiB | text/x-python | PythonLexer
/ IPython / lib / tests / test_deepreload.py
Bradley M. Froehle
Reformat test to a standard style.
r6534 # -*- coding: utf-8 -*-
Bradley M. Froehle
Add deepreload unit test....
r6533 """Test suite for the deepreload module."""
Thomas Kluyver
numpy no longer seems amenable to deep reloading...
r22971 # Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
Bradley M. Froehle
Reformat test to a standard style.
r6534
Nikita Kniazev
Port `deepreload` to `importlib`...
r27044 import pytest
import types
dswij
use pathlib on test_deepreload
r26042 from pathlib import Path
Bradley M. Froehle
Add deepreload functionality test.
r6535
Bradley M. Froehle
Clean up sys.path entry.
r6541 from IPython.utils.syspathcontext import prepended_to_syspath
Bradley M. Froehle
Add deepreload functionality test.
r6535 from IPython.utils.tempdir import TemporaryDirectory
Nikita Kniazev
Port `deepreload` to `importlib`...
r27044 from IPython.lib.deepreload import reload as dreload, modules_reloading
Bradley M. Froehle
Add deepreload unit test....
r6533
dswij
run black
r26043
Bradley M. Froehle
Add deepreload functionality test.
r6535 def test_deepreload():
"Test that dreload does deep reloads and skips excluded modules."
with TemporaryDirectory() as tmpdir:
Bradley M. Froehle
Clean up sys.path entry.
r6541 with prepended_to_syspath(tmpdir):
dswij
use pathlib on test_deepreload
r26042 tmpdirpath = Path(tmpdir)
dswij
run black
r26043 with open(tmpdirpath / "A.py", "w") as f:
Nikita Kniazev
Port `deepreload` to `importlib`...
r27044 f.write("class Object:\n pass\nok = True\n")
dswij
run black
r26043 with open(tmpdirpath / "B.py", "w") as f:
Nikita Kniazev
Port `deepreload` to `importlib`...
r27044 f.write("import A\nassert A.ok, 'we are fine'\n")
Bradley M. Froehle
Clean up sys.path entry.
r6541 import A
import B
# Test that A is not reloaded.
obj = A.Object()
dswij
run black
r26043 dreload(B, exclude=["A"])
Samuel Gaist
[lib][tests][deepreload] Remove nose
r26913 assert isinstance(obj, A.Object) is True
Bradley M. Froehle
Clean up sys.path entry.
r6541
Nikita Kniazev
Port `deepreload` to `importlib`...
r27044 # Test that an import failure will not blow-up us.
A.ok = False
with pytest.raises(AssertionError, match="we are fine"):
dreload(B, exclude=["A"])
assert len(modules_reloading) == 0
assert not A.ok
Bradley M. Froehle
Clean up sys.path entry.
r6541 # Test that A is reloaded.
obj = A.Object()
Nikita Kniazev
Port `deepreload` to `importlib`...
r27044 A.ok = False
Bradley M. Froehle
Clean up sys.path entry.
r6541 dreload(B)
Nikita Kniazev
Port `deepreload` to `importlib`...
r27044 assert A.ok
Samuel Gaist
[lib][tests][deepreload] Remove nose
r26913 assert isinstance(obj, A.Object) is False
Nikita Kniazev
Port `deepreload` to `importlib`...
r27044
def test_not_module():
pytest.raises(TypeError, dreload, "modulename")
def test_not_in_sys_modules():
fake_module = types.ModuleType("fake_module")
with pytest.raises(ImportError, match="not in sys.modules"):
dreload(fake_module)