diff -r 3328e388cb28 Lib/test/test_raise.py --- a/Lib/test/test_raise.py Tue Feb 28 08:06:01 2012 +0000 +++ b/Lib/test/test_raise.py Tue Feb 28 02:31:44 2012 -0800 @@ -4,26 +4,13 @@ """Tests for the raise statement.""" from test import support, script_helper +import textwrap import re import sys import types import unittest -try: - from resource import setrlimit, RLIMIT_CORE, error as resource_error -except ImportError: - prepare_subprocess = None -else: - def prepare_subprocess(): - # don't create core file - try: - setrlimit(RLIMIT_CORE, (0, 0)) - except (ValueError, resource_error): - pass - - - def get_tb(): try: raise OSError() @@ -221,42 +208,19 @@ class TestTraceback(unittest.TestCase): - def get_output(self, code, filename=None): - """ - Run the specified code in Python (in a new child process) and read the - output from the standard error or from a file (if filename is set). - Return the output lines as a list. - """ - options = {} - if prepare_subprocess: - options['preexec_fn'] = prepare_subprocess - process = script_helper.spawn_python('-c', code, **options) - stdout, stderr = process.communicate() - exitcode = process.wait() - output = support.strip_python_stderr(stdout) - output = output.decode('ascii', 'backslashreplace') - if filename: - self.assertEqual(output, '') - with open(filename, "rb") as fp: - output = fp.read() - output = output.decode('ascii', 'backslashreplace') - output = re.sub('Current thread 0x[0-9a-f]+', - 'Current thread XXX', - output) - return output.splitlines(), exitcode - def test_traceback_verbiage(self): - code = """ -try: - raise ValueError -except: - raise NameError from None -""" - text, exitcode = self.get_output(code) - self.assertEqual(len(text), 3) + testfn = script_helper.make_script('', support.TESTFN, textwrap.dedent("""\ + try: + raise ValueError + except: + raise NameError from None + """)) + exitcode, stdout, stderr = script_helper.assert_python_failure(testfn) + text = stderr.decode('ascii').split('\n') + self.assertEqual(len(text), 4) self.assertTrue(text[0].startswith('Traceback')) self.assertTrue(text[1].startswith(' File ')) - self.assertTrue(text[2].startswith('NameError')) + self.assertTrue(text[3].startswith('NameError')) def test_sets_traceback(self): try: