@@ -30,9 +30,8 @@ def test_zip(self):
30
30
expected = self .read_csv (self .csv1 )
31
31
32
32
with tm .ensure_clean ('test_file.zip' ) as path :
33
- tmp = zipfile .ZipFile (path , mode = 'w' )
34
- tmp .writestr ('test_file' , data )
35
- tmp .close ()
33
+ with zipfile .ZipFile (path , mode = 'w' ) as tmp :
34
+ tmp .writestr ('test_file' , data )
36
35
37
36
result = self .read_csv (path , compression = 'zip' )
38
37
tm .assert_frame_equal (result , expected )
@@ -47,10 +46,9 @@ def test_zip(self):
47
46
48
47
with tm .ensure_clean ('combined_zip.zip' ) as path :
49
48
inner_file_names = ['test_file' , 'second_file' ]
50
- tmp = zipfile .ZipFile (path , mode = 'w' )
51
- for file_name in inner_file_names :
52
- tmp .writestr (file_name , data )
53
- tmp .close ()
49
+ with zipfile .ZipFile (path , mode = 'w' ) as tmp :
50
+ for file_name in inner_file_names :
51
+ tmp .writestr (file_name , data )
54
52
55
53
tm .assert_raises_regex (ValueError , 'Multiple files' ,
56
54
self .read_csv , path , compression = 'zip' )
@@ -60,8 +58,8 @@ def test_zip(self):
60
58
compression = 'infer' )
61
59
62
60
with tm .ensure_clean () as path :
63
- tmp = zipfile .ZipFile (path , mode = 'w' )
64
- tmp . close ()
61
+ with zipfile .ZipFile (path , mode = 'w' ) as tmp :
62
+ pass
65
63
66
64
tm .assert_raises_regex (ValueError , 'Zero files' ,
67
65
self .read_csv , path , compression = 'zip' )
@@ -84,9 +82,8 @@ def test_other_compression(self, compress_type, compress_method, ext):
84
82
expected = self .read_csv (self .csv1 )
85
83
86
84
with tm .ensure_clean () as path :
87
- tmp = compress_method (path , mode = 'wb' )
88
- tmp .write (data )
89
- tmp .close ()
85
+ with compress_method (path , mode = 'wb' ) as tmp :
86
+ tmp .write (data )
90
87
91
88
result = self .read_csv (path , compression = compress_type )
92
89
tm .assert_frame_equal (result , expected )
@@ -100,9 +97,8 @@ def test_other_compression(self, compress_type, compress_method, ext):
100
97
tm .assert_frame_equal (result , expected )
101
98
102
99
with tm .ensure_clean ('test.{}' .format (ext )) as path :
103
- tmp = compress_method (path , mode = 'wb' )
104
- tmp .write (data )
105
- tmp .close ()
100
+ with compress_method (path , mode = 'wb' ) as tmp :
101
+ tmp .write (data )
106
102
result = self .read_csv (path , compression = 'infer' )
107
103
tm .assert_frame_equal (result , expected )
108
104
0 commit comments