diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-05-26 00:49:14 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-05-26 00:49:14 +0200 |
commit | 6a0ee2b7dbe20b058f85b598645f97d24f091e45 (patch) | |
tree | 0b05a68df4c71210e984ffc16435cf9527fd115f /Lib/test/test_tokenize.py | |
parent | aea8fa357b06123d1e76590803be3e2d4dca1a8d (diff) | |
parent | 24d262af0b16f76415baa6187c8892de1682c8a6 (diff) | |
download | cpython-git-6a0ee2b7dbe20b058f85b598645f97d24f091e45.tar.gz |
(Merge 3.6) Issue #23840: tokenize.open() now closes the temporary binary file
on error to fix a resource warning.
Diffstat (limited to 'Lib/test/test_tokenize.py')
-rw-r--r-- | Lib/test/test_tokenize.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py index 43fadaf1a3..b4e114c844 100644 --- a/Lib/test/test_tokenize.py +++ b/Lib/test/test_tokenize.py @@ -834,7 +834,7 @@ from tokenize import (tokenize, _tokenize, untokenize, NUMBER, NAME, OP, STRING, ENDMARKER, ENCODING, tok_name, detect_encoding, open as tokenize_open, Untokenizer) from io import BytesIO -from unittest import TestCase +from unittest import TestCase, mock import os, sys, glob import token @@ -1246,6 +1246,14 @@ class TestDetectEncoding(TestCase): ins = Bunk(lines, path) detect_encoding(ins.readline) + def test_open_error(self): + # Issue #23840: open() must close the binary file on error + m = BytesIO(b'#coding:xxx') + with mock.patch('tokenize._builtin_open', return_value=m): + self.assertRaises(SyntaxError, tokenize_open, 'foobar') + self.assertTrue(m.closed) + + class TestTokenize(TestCase): |