Skip to content

Commit

Permalink
Properly close opened files in three tests
Browse files Browse the repository at this point in the history
  • Loading branch information
agraboso committed Aug 9, 2016
1 parent d759156 commit 1e39a5e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
11 changes: 5 additions & 6 deletions pandas/io/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/series/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1e39a5e

Please sign in to comment.