test_deepreload.py
34 lines
| 1.1 KiB
| text/x-python
|
PythonLexer
Bradley M. Froehle
|
r6534 | # -*- coding: utf-8 -*- | ||
Bradley M. Froehle
|
r6533 | """Test suite for the deepreload module.""" | ||
Thomas Kluyver
|
r22971 | # Copyright (c) IPython Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||||
Bradley M. Froehle
|
r6534 | |||
dswij
|
r26042 | from pathlib import Path | ||
Bradley M. Froehle
|
r6535 | |||
Bradley M. Froehle
|
r6541 | from IPython.utils.syspathcontext import prepended_to_syspath | ||
Bradley M. Froehle
|
r6535 | from IPython.utils.tempdir import TemporaryDirectory | ||
Bradley M. Froehle
|
r6533 | from IPython.lib.deepreload import reload as dreload | ||
dswij
|
r26043 | |||
Bradley M. Froehle
|
r6535 | def test_deepreload(): | ||
"Test that dreload does deep reloads and skips excluded modules." | ||||
with TemporaryDirectory() as tmpdir: | ||||
Bradley M. Froehle
|
r6541 | with prepended_to_syspath(tmpdir): | ||
dswij
|
r26042 | tmpdirpath = Path(tmpdir) | ||
dswij
|
r26043 | with open(tmpdirpath / "A.py", "w") as f: | ||
Bradley M. Froehle
|
r6541 | f.write("class Object(object):\n pass\n") | ||
dswij
|
r26043 | with open(tmpdirpath / "B.py", "w") as f: | ||
Bradley M. Froehle
|
r6541 | f.write("import A\n") | ||
import A | ||||
import B | ||||
# Test that A is not reloaded. | ||||
obj = A.Object() | ||||
dswij
|
r26043 | dreload(B, exclude=["A"]) | ||
Samuel Gaist
|
r26913 | assert isinstance(obj, A.Object) is True | ||
Bradley M. Froehle
|
r6541 | |||
# Test that A is reloaded. | ||||
obj = A.Object() | ||||
dreload(B) | ||||
Samuel Gaist
|
r26913 | assert isinstance(obj, A.Object) is False | ||