From 1e39a5e48651f45369953be1386192918e5442ee Mon Sep 17 00:00:00 2001 From: agraboso Date: Tue, 9 Aug 2016 10:17:56 -0400 Subject: [PATCH] Properly close opened files in three tests --- pandas/io/tests/test_common.py | 11 +++++------ pandas/tests/series/test_io.py | 3 ++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pandas/io/tests/test_common.py b/pandas/io/tests/test_common.py index a443df5dac586..c08d235b07c9e 100644 --- a/pandas/io/tests/test_common.py +++ b/pandas/io/tests/test_common.py @@ -116,8 +116,8 @@ def test_constructor_bad_file(self): tm.assertRaisesRegexp(ValueError, msg, common.MMapWrapper, target) def test_get_attr(self): - target = open(self.mmap_file, 'r') - wrapper = common.MMapWrapper(target) + with open(self.mmap_file, 'r') as target: + wrapper = common.MMapWrapper(target) attrs = dir(wrapper.mmap) attrs = [attr for attr in attrs @@ -130,10 +130,9 @@ def test_get_attr(self): self.assertFalse(hasattr(wrapper, 'foo')) def test_next(self): - target = open(self.mmap_file, 'r') - wrapper = common.MMapWrapper(target) - - lines = target.readlines() + with open(self.mmap_file, 'r') as target: + wrapper = common.MMapWrapper(target) + lines = target.readlines() for line in lines: next_line = next(wrapper) diff --git a/pandas/tests/series/test_io.py b/pandas/tests/series/test_io.py index f89501d39f014..48528dc54adbd 100644 --- a/pandas/tests/series/test_io.py +++ b/pandas/tests/series/test_io.py @@ -64,7 +64,8 @@ def test_to_csv(self): with ensure_clean() as path: self.ts.to_csv(path) - lines = io.open(path, newline=None).readlines() + with io.open(path, newline=None) as f: + lines = f.readlines() assert (lines[1] != '\n') self.ts.to_csv(path, index=False)