summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-05-16 14:59:49 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-05-16 14:59:49 (GMT)
commit45323a890ac4ecbf62c5d62bd17df5633b4ac952 (patch)
tree66f60a92329012b02b0bbd0be207589a4a913088 /Lib/importlib
parentb67cf161bc5f2f581ac2c04546396ca9e149b4de (diff)
parent272e24356eea6b2ded4cb4f0a8617e31ebb0196d (diff)
downloadcpython-45323a890ac4ecbf62c5d62bd17df5633b4ac952.zip
cpython-45323a890ac4ecbf62c5d62bd17df5633b4ac952.tar.gz
cpython-45323a890ac4ecbf62c5d62bd17df5633b4ac952.tar.bz2
(Merge 3.1) Issue #11614: Fix importlib tests for the new __hello__ module
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/test/frozen/test_loader.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/Lib/importlib/test/frozen/test_loader.py b/Lib/importlib/test/frozen/test_loader.py
index c05e22c..b685ef5 100644
--- a/Lib/importlib/test/frozen/test_loader.py
+++ b/Lib/importlib/test/frozen/test_loader.py
@@ -3,20 +3,21 @@ import imp
import unittest
from .. import abc
from .. import util
-
+from test.support import captured_stdout
class LoaderTests(abc.LoaderTests):
def test_module(self):
- with util.uncache('__hello__'):
+ with util.uncache('__hello__'), captured_stdout() as stdout:
module = machinery.FrozenImporter.load_module('__hello__')
check = {'__name__': '__hello__', '__file__': '<frozen>',
'__package__': '', '__loader__': machinery.FrozenImporter}
for attr, value in check.items():
self.assertEqual(getattr(module, attr), value)
+ self.assertEqual(stdout.getvalue(), 'Hello world!\n')
def test_package(self):
- with util.uncache('__phello__'):
+ with util.uncache('__phello__'), captured_stdout() as stdout:
module = machinery.FrozenImporter.load_module('__phello__')
check = {'__name__': '__phello__', '__file__': '<frozen>',
'__package__': '__phello__', '__path__': ['__phello__'],
@@ -26,9 +27,11 @@ class LoaderTests(abc.LoaderTests):
self.assertEqual(attr_value, value,
"for __phello__.%s, %r != %r" %
(attr, attr_value, value))
+ self.assertEqual(stdout.getvalue(), 'Hello world!\n')
def test_lacking_parent(self):
- with util.uncache('__phello__', '__phello__.spam'):
+ with util.uncache('__phello__', '__phello__.spam'), \
+ captured_stdout() as stdout:
module = machinery.FrozenImporter.load_module('__phello__.spam')
check = {'__name__': '__phello__.spam', '__file__': '<frozen>',
'__package__': '__phello__',
@@ -38,12 +41,15 @@ class LoaderTests(abc.LoaderTests):
self.assertEqual(attr_value, value,
"for __phello__.spam.%s, %r != %r" %
(attr, attr_value, value))
+ self.assertEqual(stdout.getvalue(), 'Hello world!\n')
def test_module_reuse(self):
- with util.uncache('__hello__'):
+ with util.uncache('__hello__'), captured_stdout() as stdout:
module1 = machinery.FrozenImporter.load_module('__hello__')
module2 = machinery.FrozenImporter.load_module('__hello__')
self.assertTrue(module1 is module2)
+ self.assertEqual(stdout.getvalue(),
+ 'Hello world!\nHello world!\n')
def test_state_after_failure(self):
# No way to trigger an error in a frozen module.
@@ -62,10 +68,12 @@ class InspectLoaderTests(unittest.TestCase):
def test_get_code(self):
# Make sure that the code object is good.
name = '__hello__'
- code = machinery.FrozenImporter.get_code(name)
- mod = imp.new_module(name)
- exec(code, mod.__dict__)
- self.assertTrue(hasattr(mod, 'initialized'))
+ with captured_stdout() as stdout:
+ code = machinery.FrozenImporter.get_code(name)
+ mod = imp.new_module(name)
+ exec(code, mod.__dict__)
+ self.assertTrue(hasattr(mod, 'initialized'))
+ self.assertEqual(stdout.getvalue(), 'Hello world!\n')
def test_get_source(self):
# Should always return None.