@@ -2115,11 +2115,10 @@ def test_load_config(self):
2115
2115
folder = tempfile .mkdtemp ()
2116
2116
self .addCleanup (shutil .rmtree , folder )
2117
2117
dockercfg_path = os .path .join (folder , '.dockercfg' )
2118
- f = open (dockercfg_path , 'w' )
2119
- auth_ = base64 .b64encode (b'sakuya:izayoi' ).decode ('ascii' )
2120
- f .write ('auth = {0}\n ' .format (auth_ ))
2121
- f .
write (
'email = [email protected] ' )
2122
- f .close ()
2118
+ with open (dockercfg_path , 'w' ) as f :
2119
+ auth_ = base64 .b64encode (b'sakuya:izayoi' ).decode ('ascii' )
2120
+ f .write ('auth = {0}\n ' .format (auth_ ))
2121
+ f .
write (
'email = [email protected] ' )
2123
2122
cfg = docker .auth .load_config (dockercfg_path )
2124
2123
self .assertTrue (docker .auth .INDEX_URL in cfg )
2125
2124
self .assertNotEqual (cfg [docker .auth .INDEX_URL ], None )
@@ -2175,18 +2174,18 @@ def test_tar_with_excludes(self):
2175
2174
(['test/foo' , 'a.txt' ], ['bar' , 'bar/a.txt' , 'bar/b.py' ,
2176
2175
'bar/other.png' , 'test' ]),
2177
2176
):
2178
- archive = docker .utils .tar (base , exclude = exclude )
2179
- tar = tarfile .open (fileobj = archive )
2180
- self .assertEqual (sorted (tar .getnames ()), names )
2177
+ with docker .utils .tar (base , exclude = exclude ) as archive :
2178
+ tar = tarfile .open (fileobj = archive )
2179
+ self .assertEqual (sorted (tar .getnames ()), names )
2181
2180
2182
2181
def test_tar_with_empty_directory (self ):
2183
2182
base = tempfile .mkdtemp ()
2184
2183
self .addCleanup (shutil .rmtree , base )
2185
2184
for d in ['foo' , 'bar' ]:
2186
2185
os .makedirs (os .path .join (base , d ))
2187
- archive = docker .utils .tar (base )
2188
- tar = tarfile .open (fileobj = archive )
2189
- self .assertEqual (sorted (tar .getnames ()), ['bar' , 'foo' ])
2186
+ with docker .utils .tar (base ) as archive :
2187
+ tar = tarfile .open (fileobj = archive )
2188
+ self .assertEqual (sorted (tar .getnames ()), ['bar' , 'foo' ])
2190
2189
2191
2190
def test_tar_with_file_symlinks (self ):
2192
2191
base = tempfile .mkdtemp ()
@@ -2195,19 +2194,19 @@ def test_tar_with_file_symlinks(self):
2195
2194
f .write ("content" )
2196
2195
os .makedirs (os .path .join (base , 'bar' ))
2197
2196
os .symlink ('../foo' , os .path .join (base , 'bar/foo' ))
2198
- archive = docker .utils .tar (base )
2199
- tar = tarfile .open (fileobj = archive )
2200
- self .assertEqual (sorted (tar .getnames ()), ['bar' , 'bar/foo' , 'foo' ])
2197
+ with docker .utils .tar (base ) as archive :
2198
+ tar = tarfile .open (fileobj = archive )
2199
+ self .assertEqual (sorted (tar .getnames ()), ['bar' , 'bar/foo' , 'foo' ])
2201
2200
2202
2201
def test_tar_with_directory_symlinks (self ):
2203
2202
base = tempfile .mkdtemp ()
2204
2203
self .addCleanup (shutil .rmtree , base )
2205
2204
for d in ['foo' , 'bar' ]:
2206
2205
os .makedirs (os .path .join (base , d ))
2207
2206
os .symlink ('../foo' , os .path .join (base , 'bar/foo' ))
2208
- archive = docker .utils .tar (base )
2209
- tar = tarfile .open (fileobj = archive )
2210
- self .assertEqual (sorted (tar .getnames ()), ['bar' , 'bar/foo' , 'foo' ])
2207
+ with docker .utils .tar (base ) as archive :
2208
+ tar = tarfile .open (fileobj = archive )
2209
+ self .assertEqual (sorted (tar .getnames ()), ['bar' , 'bar/foo' , 'foo' ])
2211
2210
2212
2211
2213
2212
class StreamTest (Cleanup , unittest .TestCase ):
@@ -2293,21 +2292,21 @@ def test_early_stream_response(self):
2293
2292
b'\r \n '
2294
2293
) + b'\r \n ' .join (lines )
2295
2294
2296
- client = docker .Client (base_url = "http+unix://" + self .socket_file )
2297
- for i in range ( 5 ) :
2298
- try :
2299
- stream = client . build (
2300
- path = self . build_context ,
2301
- stream = True
2302
- )
2303
- break
2304
- except requests . ConnectionError as e :
2305
- if i == 4 :
2306
- raise e
2307
-
2308
- self . assertEqual ( list ( stream ), [
2309
- str ( i ). encode () for i in range ( 50 )])
2310
-
2295
+ with docker .Client (base_url = "http+unix://" + self .socket_file ) \
2296
+ as client :
2297
+ for i in range ( 5 ) :
2298
+ try :
2299
+ stream = client . build (
2300
+ path = self . build_context ,
2301
+ stream = True
2302
+ )
2303
+ break
2304
+ except requests . ConnectionError as e :
2305
+ if i == 4 :
2306
+ raise e
2307
+
2308
+ self . assertEqual ( list ( stream ), [
2309
+ str ( i ). encode () for i in range ( 50 )])
2311
2310
2312
2311
if __name__ == '__main__' :
2313
2312
unittest .main ()
0 commit comments