diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-19 15:24:27 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-19 15:24:27 +0200 |
commit | 4f418d36714787fa85652806c93405e4874bca61 (patch) | |
tree | f4240a7d9a132352f1106f0c0f14fd0729e6f96b /Lib/test/test_tempfile.py | |
parent | 41ce610d4ca12ce96aa3a9b9139e416039b18f7b (diff) | |
parent | 56cefa69ee919559cf3ca2388d12371c24402df3 (diff) | |
download | cpython-git-4f418d36714787fa85652806c93405e4874bca61.tar.gz |
Issue #23700: Iterator of NamedTemporaryFile now keeps a reference to
NamedTemporaryFile instance. Patch by Bohuslav Kabrda.
Diffstat (limited to 'Lib/test/test_tempfile.py')
-rw-r--r-- | Lib/test/test_tempfile.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index 2e10fddae0..576cf4d450 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -707,6 +707,19 @@ class TestNamedTemporaryFile(BaseTestCase): # No reference cycle was created. self.assertIsNone(wr()) + def test_iter(self): + # Issue #23700: getting iterator from a temporary file should keep + # it alive as long as it's being iterated over + lines = [b'spam\n', b'eggs\n', b'beans\n'] + def make_file(): + f = tempfile.NamedTemporaryFile(mode='w+b') + f.write(b''.join(lines)) + f.seek(0) + return f + for i, l in enumerate(make_file()): + self.assertEqual(l, lines[i]) + self.assertEqual(i, len(lines) - 1) + def test_creates_named(self): # NamedTemporaryFile creates files with names f = tempfile.NamedTemporaryFile() |