@@ -127,35 +127,36 @@ def patch_indexed_gzip(state):
127
127
yield
128
128
129
129
130
- def test_Opener_gzip_type ():
131
- # Test that BufferedGzipFile or IndexedGzipFile are used as appropriate
132
-
133
- data = 'this is some test data'
134
- fname = 'test.gz'
135
-
136
- with InTemporaryDirectory ():
137
-
138
- # make some test data
139
- with GzipFile (fname , mode = 'wb' ) as f :
140
- f .write (data .encode ())
141
-
142
- # Each test is specified by a tuple containing:
143
- # (indexed_gzip present, Opener kwargs, expected file type)
144
- tests = [
145
- (False , {'mode' : 'rb' , 'keep_open' : True }, GzipFile ),
146
- (False , {'mode' : 'rb' , 'keep_open' : False }, GzipFile ),
147
- (False , {'mode' : 'wb' , 'keep_open' : True }, GzipFile ),
148
- (False , {'mode' : 'wb' , 'keep_open' : False }, GzipFile ),
149
- (True , {'mode' : 'rb' , 'keep_open' : True }, MockIndexedGzipFile ),
150
- (True , {'mode' : 'rb' , 'keep_open' : False }, MockIndexedGzipFile ),
151
- (True , {'mode' : 'wb' , 'keep_open' : True }, GzipFile ),
152
- (True , {'mode' : 'wb' , 'keep_open' : False }, GzipFile ),
153
- ]
154
-
155
- for test in tests :
156
- igzip_present , kwargs , expected = test
157
- with patch_indexed_gzip (igzip_present ):
158
- assert isinstance (Opener (fname , ** kwargs ).fobj , expected )
130
+ def test_Opener_gzip_type (tmp_path ):
131
+ # Test that GzipFile or IndexedGzipFile are used as appropriate
132
+
133
+ data = b'this is some test data'
134
+ fname = tmp_path / 'test.gz'
135
+
136
+ # make some test data
137
+ with GzipFile (fname , mode = 'wb' ) as f :
138
+ f .write (data )
139
+
140
+ # Each test is specified by a tuple containing:
141
+ # (indexed_gzip present, Opener kwargs, expected file type)
142
+ tests = [
143
+ (False , {'mode' : 'rb' , 'keep_open' : True }, GzipFile ),
144
+ (False , {'mode' : 'rb' , 'keep_open' : False }, GzipFile ),
145
+ (False , {'mode' : 'wb' , 'keep_open' : True }, GzipFile ),
146
+ (False , {'mode' : 'wb' , 'keep_open' : False }, GzipFile ),
147
+ (True , {'mode' : 'rb' , 'keep_open' : True }, MockIndexedGzipFile ),
148
+ (True , {'mode' : 'rb' , 'keep_open' : False }, MockIndexedGzipFile ),
149
+ (True , {'mode' : 'wb' , 'keep_open' : True }, GzipFile ),
150
+ (True , {'mode' : 'wb' , 'keep_open' : False }, GzipFile ),
151
+ ]
152
+
153
+ for test in tests :
154
+ igzip_present , kwargs , expected = test
155
+ with patch_indexed_gzip (igzip_present ):
156
+ opener = Opener (fname , ** kwargs )
157
+ assert isinstance (opener .fobj , expected )
158
+ # Explicit close to appease Windows
159
+ del opener
159
160
160
161
161
162
class TestImageOpener (unittest .TestCase ):
0 commit comments