Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
55b4a4a1
Commit
55b4a4a1
authored
Feb 25, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a proper unit test for xreload.py.
parent
221085de
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
0 deletions
+103
-0
Lib/test/test_xreload.py
Lib/test/test_xreload.py
+103
-0
No files found.
Lib/test/test_xreload.py
0 → 100644
View file @
55b4a4a1
"""Doctests for module reloading.
>>> from xreload import xreload
>>> from test.test_xreload import make_mod
>>> make_mod()
>>> import x
>>> C = x.C
>>> Cfoo = C.foo
>>> Cbar = C.bar
>>> Cstomp = C.stomp
>>> b = C()
>>> bfoo = b.foo
>>> b.foo()
42
>>> bfoo()
42
>>> Cfoo(b)
42
>>> Cbar()
42 42
>>> Cstomp()
42 42 42
>>> make_mod(repl="42", subst="24")
>>> xreload(x)
<module 'x' (built-in)>
>>> b.foo()
24
>>> bfoo()
24
>>> Cfoo(b)
24
>>> Cbar()
24 24
>>> Cstomp()
24 24 24
"""
SAMPLE_CODE
=
"""
class C:
def foo(self):
print(42)
@classmethod
def bar(cls):
print(42, 42)
@staticmethod
def stomp():
print (42, 42, 42)
"""
import
os
import
sys
import
shutil
import
doctest
import
xreload
import
tempfile
from
test.test_support
import
run_unittest
tempdir
=
None
save_path
=
None
def
setUp
(
unused
=
None
):
global
tempdir
,
save_path
tempdir
=
tempfile
.
mkdtemp
()
save_path
=
list
(
sys
.
path
)
sys
.
path
.
append
(
tempdir
)
def
tearDown
(
unused
=
None
):
global
tempdir
,
save_path
if
save_path
is
not
None
:
sys
.
path
=
save_path
save_path
=
None
if
tempdir
is
not
None
:
shutil
.
rmtree
(
tempdir
)
tempdir
=
None
def
make_mod
(
name
=
"x"
,
repl
=
None
,
subst
=
None
):
if
not
tempdir
:
setUp
()
assert
tempdir
fn
=
os
.
path
.
join
(
tempdir
,
name
+
".py"
)
f
=
open
(
fn
,
"w"
)
sample
=
SAMPLE_CODE
if
repl
is
not
None
and
subst
is
not
None
:
sample
=
sample
.
replace
(
repl
,
subst
)
try
:
f
.
write
(
sample
)
finally
:
f
.
close
()
def
test_suite
():
return
doctest
.
DocTestSuite
(
setUp
=
setUp
,
tearDown
=
tearDown
)
def
test_main
():
run_unittest
(
test_suite
())
if
__name__
==
"__main__"
:
test_main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment