10
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
11
# ANY KIND, either express or implied. See the License for the specific
12
12
# language governing permissions and limitations under the License.
13
+ import pytest
14
+
13
15
from tests import unittest
14
16
15
17
import botocore
@@ -26,36 +28,26 @@ class TestS3MethodInjection(unittest.TestCase):
26
28
def test_transfer_methods_injected_to_client (self ):
27
29
session = boto3 .session .Session (region_name = 'us-west-2' )
28
30
client = session .client ('s3' )
29
- self .assertTrue (hasattr (client , 'upload_file' ),
30
- 'upload_file was not injected onto S3 client' )
31
- self .assertTrue (hasattr (client , 'download_file' ),
32
- 'download_file was not injected onto S3 client' )
33
- self .assertTrue (hasattr (client , 'copy' ),
34
- 'copy was not injected onto S3 client' )
31
+ assert hasattr (client , 'upload_file' )
32
+ assert hasattr (client , 'download_file' )
33
+ assert hasattr (client , 'copy' )
35
34
36
35
def test_bucket_resource_has_load_method (self ):
37
36
session = boto3 .session .Session (region_name = 'us-west-2' )
38
37
bucket = session .resource ('s3' ).Bucket ('fakebucket' )
39
- self .assertTrue (hasattr (bucket , 'load' ),
40
- 'load() was not injected onto S3 Bucket resource.' )
38
+ assert hasattr (bucket , 'load' )
41
39
42
40
def test_transfer_methods_injected_to_bucket (self ):
43
41
bucket = boto3 .resource ('s3' ).Bucket ('my_bucket' )
44
- self .assertTrue (hasattr (bucket , 'upload_file' ),
45
- 'upload_file was not injected onto S3 bucket' )
46
- self .assertTrue (hasattr (bucket , 'download_file' ),
47
- 'download_file was not injected onto S3 bucket' )
48
- self .assertTrue (hasattr (bucket , 'copy' ),
49
- 'copy was not injected onto S3 bucket' )
42
+ assert hasattr (bucket , 'upload_file' )
43
+ assert hasattr (bucket , 'download_file' )
44
+ assert hasattr (bucket , 'copy' )
50
45
51
46
def test_transfer_methods_injected_to_object (self ):
52
47
obj = boto3 .resource ('s3' ).Object ('my_bucket' , 'my_key' )
53
- self .assertTrue (hasattr (obj , 'upload_file' ),
54
- 'upload_file was not injected onto S3 object' )
55
- self .assertTrue (hasattr (obj , 'download_file' ),
56
- 'download_file was not injected onto S3 object' )
57
- self .assertTrue (hasattr (obj , 'copy' ),
58
- 'copy was not injected onto S3 object' )
48
+ assert hasattr (obj , 'upload_file' )
49
+ assert hasattr (obj , 'download_file' )
50
+ assert hasattr (obj , 'copy' )
59
51
60
52
61
53
class BaseTransferTest (unittest .TestCase ):
@@ -208,22 +200,22 @@ def test_client_copy(self):
208
200
response = self .s3 .meta .client .copy (
209
201
self .copy_source , self .bucket , self .key )
210
202
# The response will be none on a successful transfer.
211
- self . assertIsNone ( response )
203
+ assert response is None
212
204
213
205
def test_bucket_copy (self ):
214
206
self .stub_single_part_copy ()
215
207
bucket = self .s3 .Bucket (self .bucket )
216
208
with self .stubber :
217
209
response = bucket .copy (self .copy_source , self .key )
218
210
# The response will be none on a successful transfer.
219
- self . assertIsNone ( response )
211
+ assert response is None
220
212
221
213
def test_object_copy (self ):
222
214
self .stub_single_part_copy ()
223
215
obj = self .s3 .Object (self .bucket , self .key )
224
216
with self .stubber :
225
217
response = obj .copy (self .copy_source )
226
- self . assertIsNone ( response )
218
+ assert response is None
227
219
228
220
def test_copy_progress (self ):
229
221
chunksize = 8 * (1024 ** 2 )
@@ -243,8 +235,8 @@ def progress_callback(amount):
243
235
244
236
# Assert that the progress callback was called the correct number of
245
237
# times with the correct amounts.
246
- self .assertEqual ( self . progress_times_called , 3 )
247
- self .assertEqual ( self . progress , chunksize * 3 )
238
+ assert self .progress_times_called == 3
239
+ assert self .progress == chunksize * 3
248
240
249
241
250
242
class TestUploadFileobj (BaseTransferTest ):
@@ -310,7 +302,7 @@ def test_client_upload(self):
310
302
311
303
def test_raises_value_error_on_invalid_fileobj (self ):
312
304
with self .stubber :
313
- with self . assertRaises (ValueError ):
305
+ with pytest . raises (ValueError ):
314
306
self .s3 .meta .client .upload_fileobj (
315
307
Fileobj = 'foo' , Bucket = self .bucket , Key = self .key )
316
308
@@ -427,12 +419,12 @@ def test_client_download(self):
427
419
self .s3 .meta .client .download_fileobj (
428
420
Bucket = self .bucket , Key = self .key , Fileobj = self .fileobj )
429
421
430
- self .assertEqual ( self . fileobj .getvalue (), self .contents )
422
+ assert self .fileobj .getvalue () == self .contents
431
423
self .stubber .assert_no_pending_responses ()
432
424
433
425
def test_raises_value_error_on_invalid_fileobj (self ):
434
426
with self .stubber :
435
- with self . assertRaises (ValueError ):
427
+ with pytest . raises (ValueError ):
436
428
self .s3 .meta .client .download_fileobj (
437
429
Bucket = self .bucket , Key = self .key , Fileobj = 'foo' )
438
430
@@ -442,7 +434,7 @@ def test_bucket_download(self):
442
434
with self .stubber :
443
435
bucket .download_fileobj (Key = self .key , Fileobj = self .fileobj )
444
436
445
- self .assertEqual ( self . fileobj .getvalue (), self .contents )
437
+ assert self .fileobj .getvalue () == self .contents
446
438
self .stubber .assert_no_pending_responses ()
447
439
448
440
def test_object_download (self ):
@@ -451,7 +443,7 @@ def test_object_download(self):
451
443
with self .stubber :
452
444
obj .download_fileobj (Fileobj = self .fileobj )
453
445
454
- self .assertEqual ( self . fileobj .getvalue (), self .contents )
446
+ assert self .fileobj .getvalue () == self .contents
455
447
self .stubber .assert_no_pending_responses ()
456
448
457
449
def test_multipart_download (self ):
@@ -467,7 +459,7 @@ def test_multipart_download(self):
467
459
Bucket = self .bucket , Key = self .key , Fileobj = self .fileobj ,
468
460
Config = transfer_config )
469
461
470
- self .assertEqual ( self . fileobj .getvalue (), self .contents )
462
+ assert self .fileobj .getvalue () == self .contents
471
463
self .stubber .assert_no_pending_responses ()
472
464
473
465
def test_download_progress (self ):
@@ -489,8 +481,8 @@ def progress_callback(amount):
489
481
490
482
# Assert that the progress callback was called the correct number of
491
483
# times with the correct amounts.
492
- self .assertEqual ( self . progress_times_called , 11 )
493
- self .assertEqual ( self . progress , 55 )
484
+ assert self .progress_times_called == 11
485
+ assert self .progress == 55
494
486
self .stubber .assert_no_pending_responses ()
495
487
496
488
@@ -520,19 +512,19 @@ def tearDown(self):
520
512
self .stubber .deactivate ()
521
513
522
514
def test_has_load (self ):
523
- self . assertTrue ( hasattr ( self . obj_summary , ' load' ),
524
- 'load() was not injected onto ObjectSummary resource. ' )
515
+ # Validate load was injected onto ObjectSummary.
516
+ assert hasattr ( self . obj_summary , 'load' )
525
517
526
518
def test_autoloads_correctly (self ):
527
519
# In HeadObject the parameter returned is ContentLength, this
528
520
# should get mapped to Size of ListObject since the resource uses
529
521
# the shape returned to by ListObjects.
530
- self .assertEqual ( self . obj_summary .size , self .obj_summary_size )
522
+ assert self .obj_summary .size == self .obj_summary_size
531
523
532
524
def test_cannot_access_other_non_related_parameters (self ):
533
525
# Even though an HeadObject was used to load this, it should
534
526
# only expose the attributes from its shape defined in ListObjects.
535
- self . assertFalse ( hasattr (self .obj_summary , 'content_length' ) )
527
+ assert not hasattr (self .obj_summary , 'content_length' )
536
528
537
529
538
530
class TestServiceResource (unittest .TestCase ):
@@ -542,7 +534,5 @@ def setUp(self):
542
534
def test_unsigned_signature_version_is_not_corrupted (self ):
543
535
config = Config (signature_version = botocore .UNSIGNED )
544
536
resource = self .session .resource ('s3' , config = config )
545
- self .assertIs (
546
- resource .meta .client .meta .config .signature_version ,
547
- botocore .UNSIGNED
548
- )
537
+ sig_version = resource .meta .client .meta .config .signature_version
538
+ assert sig_version is botocore .UNSIGNED
0 commit comments