|
3 | 3 |
|
4 | 4 | """Tests for the raise statement.""" |
5 | 5 |
|
6 | | -from test import support, script_helper |
| 6 | +from test import support |
7 | 7 | import re |
8 | 8 | import sys |
9 | 9 | import types |
10 | 10 | import unittest |
11 | 11 |
|
12 | 12 |
|
13 | | -try: |
14 | | - from resource import setrlimit, RLIMIT_CORE, error as resource_error |
15 | | -except ImportError: |
16 | | - prepare_subprocess = None |
17 | | -else: |
18 | | - def prepare_subprocess(): |
19 | | - # don't create core file |
20 | | - try: |
21 | | - setrlimit(RLIMIT_CORE, (0, 0)) |
22 | | - except (ValueError, resource_error): |
23 | | - pass |
24 | | - |
25 | | - |
26 | | - |
27 | 13 | def get_tb(): |
28 | 14 | try: |
29 | 15 | raise OSError() |
@@ -224,43 +210,6 @@ def __init__(self): |
224 | 210 |
|
225 | 211 | class TestTraceback(unittest.TestCase): |
226 | 212 |
|
227 | | - def get_output(self, code, filename=None): |
228 | | - """ |
229 | | - Run the specified code in Python (in a new child process) and read the |
230 | | - output from the standard error or from a file (if filename is set). |
231 | | - Return the output lines as a list. |
232 | | - """ |
233 | | - options = {} |
234 | | - if prepare_subprocess: |
235 | | - options['preexec_fn'] = prepare_subprocess |
236 | | - process = script_helper.spawn_python('-c', code, **options) |
237 | | - stdout, stderr = process.communicate() |
238 | | - exitcode = process.wait() |
239 | | - output = support.strip_python_stderr(stdout) |
240 | | - output = output.decode('ascii', 'backslashreplace') |
241 | | - if filename: |
242 | | - self.assertEqual(output, '') |
243 | | - with open(filename, "rb") as fp: |
244 | | - output = fp.read() |
245 | | - output = output.decode('ascii', 'backslashreplace') |
246 | | - output = re.sub('Current thread 0x[0-9a-f]+', |
247 | | - 'Current thread XXX', |
248 | | - output) |
249 | | - return output.splitlines(), exitcode |
250 | | - |
251 | | - def test_traceback_verbiage(self): |
252 | | - code = """ |
253 | | -try: |
254 | | - raise ValueError |
255 | | -except: |
256 | | - raise NameError from None |
257 | | -""" |
258 | | - text, exitcode = self.get_output(code) |
259 | | - self.assertEqual(len(text), 3) |
260 | | - self.assertTrue(text[0].startswith('Traceback')) |
261 | | - self.assertTrue(text[1].startswith(' File ')) |
262 | | - self.assertTrue(text[2].startswith('NameError')) |
263 | | - |
264 | 213 | def test_sets_traceback(self): |
265 | 214 | try: |
266 | 215 | raise IndexError() |
|
0 commit comments