Skip to content

Commit 1e39a5e

Browse files
committed
Properly close opened files in three tests
1 parent d759156 commit 1e39a5e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

pandas/io/tests/test_common.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def test_constructor_bad_file(self):
116116
tm.assertRaisesRegexp(ValueError, msg, common.MMapWrapper, target)
117117

118118
def test_get_attr(self):
119-
target = open(self.mmap_file, 'r')
120-
wrapper = common.MMapWrapper(target)
119+
with open(self.mmap_file, 'r') as target:
120+
wrapper = common.MMapWrapper(target)
121121

122122
attrs = dir(wrapper.mmap)
123123
attrs = [attr for attr in attrs
@@ -130,10 +130,9 @@ def test_get_attr(self):
130130
self.assertFalse(hasattr(wrapper, 'foo'))
131131

132132
def test_next(self):
133-
target = open(self.mmap_file, 'r')
134-
wrapper = common.MMapWrapper(target)
135-
136-
lines = target.readlines()
133+
with open(self.mmap_file, 'r') as target:
134+
wrapper = common.MMapWrapper(target)
135+
lines = target.readlines()
137136

138137
for line in lines:
139138
next_line = next(wrapper)

pandas/tests/series/test_io.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ def test_to_csv(self):
6464
with ensure_clean() as path:
6565
self.ts.to_csv(path)
6666

67-
lines = io.open(path, newline=None).readlines()
67+
with io.open(path, newline=None) as f:
68+
lines = f.readlines()
6869
assert (lines[1] != '\n')
6970

7071
self.ts.to_csv(path, index=False)

0 commit comments

Comments
 (0)