[Python-checkins] r57400 - in python/trunk/Lib/test: output/test_frozen test_frozen.py test_support.py
georg.brandl
python-checkins at python.org
Fri Aug 24 20:22:54 CEST 2007
Author: georg.brandl
Date: Fri Aug 24 20:22:54 2007
New Revision: 57400
Removed:
python/trunk/Lib/test/output/test_frozen
Modified:
python/trunk/Lib/test/test_frozen.py
python/trunk/Lib/test/test_support.py
Log:
Port test_frozen to unittest.
Deleted: /python/trunk/Lib/test/output/test_frozen
==============================================================================
--- /python/trunk/Lib/test/output/test_frozen Fri Aug 24 20:22:54 2007
+++ (empty file)
@@ -1,4 +0,0 @@
-test_frozen
-Hello world...
-Hello world...
-Hello world...
Modified: python/trunk/Lib/test/test_frozen.py
==============================================================================
--- python/trunk/Lib/test/test_frozen.py (original)
+++ python/trunk/Lib/test/test_frozen.py Fri Aug 24 20:22:54 2007
@@ -1,27 +1,40 @@
# 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...\nHello world...\nHello world...\n')
+
+
+def test_main():
+ run_unittest(FrozenTests)
Modified: python/trunk/Lib/test/test_support.py
==============================================================================
--- python/trunk/Lib/test/test_support.py (original)
+++ python/trunk/Lib/test/test_support.py Fri Aug 24 20:22:54 2007
@@ -374,6 +374,22 @@
return contextlib.nested(time_out, socket_peer_reset, ioerror_peer_reset)
+ at 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.
More information about the Python-checkins
mailing list