Commit a1ef38f9 authored by Jason R. Coombs's avatar Jason R. Coombs

Use contexts.quiet for stdout/stderr trapping

parent f3875aa7
...@@ -451,8 +451,7 @@ class TestScriptHeader: ...@@ -451,8 +451,7 @@ class TestScriptHeader:
mock.Mock(getProperty=mock.Mock(return_value=""))))) mock.Mock(getProperty=mock.Mock(return_value="")))))
@mock.patch('sys.platform', 'java1.5.0_13') @mock.patch('sys.platform', 'java1.5.0_13')
def test_get_script_header_jython_workaround(self): def test_get_script_header_jython_workaround(self):
stdout, stderr = sys.stdout, sys.stderr with contexts.quiet() as (stdout, stderr):
try:
# A mock sys.executable that uses a shebang line (this file) # A mock sys.executable that uses a shebang line (this file)
exe = os.path.normpath(os.path.splitext(__file__)[0] + '.py') exe = os.path.normpath(os.path.splitext(__file__)[0] + '.py')
assert ( assert (
...@@ -463,15 +462,13 @@ class TestScriptHeader: ...@@ -463,15 +462,13 @@ class TestScriptHeader:
# Ensure we generate what is basically a broken shebang line # Ensure we generate what is basically a broken shebang line
# when there's options, with a warning emitted # when there's options, with a warning emitted
sys.stdout = sys.stderr = StringIO()
candidate = get_script_header('#!/usr/bin/python -x', candidate = get_script_header('#!/usr/bin/python -x',
executable=exe) executable=exe)
assert candidate == '#!%s -x\n' % exe assert candidate == '#!%s -x\n' % exe
assert 'Unable to adapt shebang line' in sys.stdout.getvalue() assert 'Unable to adapt shebang line' in stderr.getvalue()
sys.stdout = sys.stderr = StringIO()
with contexts.quiet() as (stdout, stderr):
candidate = get_script_header('#!/usr/bin/python', candidate = get_script_header('#!/usr/bin/python',
executable=self.non_ascii_exe) executable=self.non_ascii_exe)
assert candidate == '#!%s -x\n' % self.non_ascii_exe assert candidate == '#!%s -x\n' % self.non_ascii_exe
assert 'Unable to adapt shebang line' in sys.stdout.getvalue() assert 'Unable to adapt shebang line' in stderr.getvalue()
finally:
sys.stdout, sys.stderr = stdout, stderr
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment