Skip to content

Commit f2bfd41

Browse files
authored
Raise TypeError on bare @requires_crt usage, fix existing bare @requires_crt usages, and add regression tests (aws#10129)
1 parent 812a53d commit f2bfd41

4 files changed

Lines changed: 53 additions & 4 deletions

File tree

tests/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ def __repr__(self):
327327

328328

329329
def requires_crt(reason=None):
330+
if callable(reason):
331+
raise TypeError(
332+
"Use @requires_crt() with parentheses, not bare @requires_crt"
333+
)
330334
if reason is None:
331335
reason = "Test requires awscrt to be installed"
332336

tests/functional/s3/test_cp_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,15 +735,15 @@ def test_upload_with_checksum_algorithm_crc32(self):
735735
self.assertEqual(self.operations_called[0][0].name, 'PutObject')
736736
self.assertEqual(self.operations_called[0][1]['ChecksumAlgorithm'], 'CRC32')
737737

738-
@requires_crt
738+
@requires_crt()
739739
def test_upload_with_checksum_algorithm_crc32c(self):
740740
full_path = self.files.create_file('foo.txt', 'contents')
741741
cmdline = f'{self.prefix} {full_path} s3://bucket/key.txt --checksum-algorithm CRC32C'
742742
self.run_cmd(cmdline, expected_rc=0)
743743
self.assertEqual(self.operations_called[0][0].name, 'PutObject')
744744
self.assertEqual(self.operations_called[0][1]['ChecksumAlgorithm'], 'CRC32C')
745745

746-
@requires_crt
746+
@requires_crt()
747747
def test_upload_with_checksum_algorithm_crc64nvme(self):
748748
full_path = self.files.create_file('foo.txt', 'contents')
749749
cmdline = f'{self.prefix} {full_path} s3://bucket/key.txt --checksum-algorithm CRC64NVME'

tests/functional/s3/test_mv_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def test_mv_works_if_outpost_access_point_arn_resolves_to_different_bucket(self)
370370
self.assertEqual(self.operations_called[2][0].name, 'CopyObject')
371371
self.assertEqual(self.operations_called[3][0].name, 'DeleteObject')
372372

373-
@requires_crt
373+
@requires_crt()
374374
def test_mv_works_if_mrap_arn_resolves_to_different_bucket(self):
375375
cmdline = (f"{self.prefix} s3://bucket/key "
376376
"s3://arn:aws:s3::123456789012:accesspoint/foobar.mrap/key "
@@ -429,7 +429,7 @@ def test_skips_validation_if_keys_are_different_outpost_alias(self):
429429
"--validate-same-s3-paths")
430430
self.assert_runs_mv_without_validation(cmdline)
431431

432-
@requires_crt
432+
@requires_crt()
433433
def test_skips_validation_if_keys_are_different_mrap_arn(self):
434434
cmdline = (f"{self.prefix} s3://bucket/key "
435435
"s3://arn:aws:s3::123456789012:accesspoint/foobar.mrap/key2 "

tests/unit/test_decorators.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License").
4+
# You may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from unittest import mock
15+
16+
import pytest
17+
18+
from tests import requires_crt
19+
20+
21+
class TestRequiresCrt:
22+
def test_bare_requires_crt_fails_immediately(self):
23+
with pytest.raises(TypeError):
24+
25+
@requires_crt
26+
def my_test():
27+
pass
28+
29+
def test_requires_crt_skips_when_no_crt(self):
30+
with mock.patch('tests.HAS_CRT', False):
31+
32+
@requires_crt()
33+
def my_test():
34+
assert False
35+
36+
assert getattr(my_test, '__unittest_skip__', False) is True
37+
38+
def test_requires_crt_runs_when_crt_available(self):
39+
with mock.patch('tests.HAS_CRT', True):
40+
41+
@requires_crt()
42+
def my_test():
43+
pass
44+
45+
assert getattr(my_test, '__unittest_skip__', False) is False

0 commit comments

Comments
 (0)