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
692bbc47
Commit
692bbc47
authored
Aug 24, 2007
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port test_frozen to unittest.
parent
9f2b93e0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
27 deletions
+52
-27
Lib/test/output/test_frozen
Lib/test/output/test_frozen
+0
-4
Lib/test/test_frozen.py
Lib/test/test_frozen.py
+36
-23
Lib/test/test_support.py
Lib/test/test_support.py
+16
-0
No files found.
Lib/test/output/test_frozen
deleted
100644 → 0
View file @
9f2b93e0
test_frozen
Hello world...
Hello world...
Hello world...
Lib/test/test_frozen.py
View file @
692bbc47
# Test the frozen module defined in frozen.c.
from
__future__
import
with_statement
from
test.test_support
import
TestFailed
from
test.test_support
import
captured_stdout
,
run_unittest
import
unittest
import
sys
,
os
try
:
import
__hello__
except
ImportError
,
x
:
raise
TestFailed
,
"import __hello__ failed:"
+
str
(
x
)
try
:
import
__phello__
except
ImportError
,
x
:
raise
TestFailed
,
"import __phello__ failed:"
+
str
(
x
)
try
:
import
__phello__.spam
except
ImportError
,
x
:
raise
TestFailed
,
"import __phello__.spam failed:"
+
str
(
x
)
if
sys
.
platform
!=
"mac"
:
# On the Mac this import does succeed.
try
:
import
__phello__.foo
except
ImportError
:
pass
else
:
raise
TestFailed
,
"import __phello__.foo should have failed"
class
FrozenTests
(
unittest
.
TestCase
):
def
test_frozen
(
self
):
with
captured_stdout
()
as
stdout
:
try
:
import
__hello__
except
ImportError
,
x
:
self
.
fail
(
"import __hello__ failed:"
+
str
(
x
))
try
:
import
__phello__
except
ImportError
,
x
:
self
.
fail
(
"import __phello__ failed:"
+
str
(
x
))
try
:
import
__phello__.spam
except
ImportError
,
x
:
self
.
fail
(
"import __phello__.spam failed:"
+
str
(
x
))
if
sys
.
platform
!=
"mac"
:
# On the Mac this import does succeed.
try
:
import
__phello__.foo
except
ImportError
:
pass
else
:
self
.
fail
(
"import __phello__.foo should have failed"
)
self
.
assertEquals
(
stdout
.
getvalue
(),
'Hello world...
\
n
Hello world...
\
n
Hello world...
\
n
'
)
def
test_main
():
run_unittest
(
FrozenTests
)
Lib/test/test_support.py
View file @
692bbc47
...
...
@@ -374,6 +374,22 @@ def transient_internet():
return
contextlib
.
nested
(
time_out
,
socket_peer_reset
,
ioerror_peer_reset
)
@
contextlib
.
contextmanager
def
captured_stdout
():
"""Run the with statement body using a StringIO object as sys.stdout.
Example use::
with captured_stdout() as s:
print "hello"
assert s.getvalue() == "hello"
"""
import
StringIO
orig_stdout
=
sys
.
stdout
sys
.
stdout
=
StringIO
.
StringIO
()
yield
sys
.
stdout
sys
.
stdout
=
orig_stdout
#=======================================================================
# Decorator for running a function in a different locale, correctly resetting
# it afterwards.
...
...
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