FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ipython/tests/test_deepreload.py at python-3.14-dev · krassowski/ipython · GitHub
krassowski
ipython
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ipython
/
tests
/
test_deepreload.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (44 loc) · 1.81 KB
Breadcrumbs
ipython
/
tests
/
test_deepreload.py
Copy path
File metadata and controls
57 lines (44 loc) · 1.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
"""Test suite for the deepreload module."""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import
types
from
pathlib
import
Path
import
pytest
from
tempfile
import
TemporaryDirectory
from
IPython
.
lib
.
deepreload
import
modules_reloading
from
IPython
.
lib
.
deepreload
import
reload
as
dreload
from
IPython
.
utils
.
syspathcontext
import
prepended_to_syspath
def
test_deepreload
():
"Test that dreload does deep reloads and skips excluded modules."
with
TemporaryDirectory
()
as
tmpdir
:
with
prepended_to_syspath
(
tmpdir
):
tmpdirpath
=
Path
(
tmpdir
)
with
open
(
tmpdirpath
/
"A.py"
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
"class Object:
\n
pass
\n
ok = True
\n
"
)
with
open
(
tmpdirpath
/
"B.py"
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
"import A
\n
assert A.ok, 'we are fine'
\n
"
)
import
A
import
B
# Test that A is not reloaded.
obj
=
A
.
Object
()
dreload
(
B
,
exclude
=
[
"A"
])
assert
isinstance
(
obj
,
A
.
Object
)
is
True
# 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
# Test that A is reloaded.
obj
=
A
.
Object
()
A
.
ok
=
False
dreload
(
B
)
assert
A
.
ok
assert
isinstance
(
obj
,
A
.
Object
)
is
False
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
)
Back
|
FazBrowse Home
|
New Git URL