Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ def __repr__(self):


def requires_crt(reason=None):
if callable(reason):
raise TypeError(
"Use @requires_crt() with parentheses, not bare @requires_crt"
)
if reason is None:
reason = "Test requires awscrt to be installed"

Expand Down
4 changes: 2 additions & 2 deletions tests/functional/s3/test_cp_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,15 +735,15 @@ def test_upload_with_checksum_algorithm_crc32(self):
self.assertEqual(self.operations_called[0][0].name, 'PutObject')
self.assertEqual(self.operations_called[0][1]['ChecksumAlgorithm'], 'CRC32')

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

@requires_crt
@requires_crt()
def test_upload_with_checksum_algorithm_crc64nvme(self):
full_path = self.files.create_file('foo.txt', 'contents')
cmdline = f'{self.prefix} {full_path} s3://bucket/key.txt --checksum-algorithm CRC64NVME'
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/s3/test_mv_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def test_mv_works_if_outpost_access_point_arn_resolves_to_different_bucket(self)
self.assertEqual(self.operations_called[2][0].name, 'CopyObject')
self.assertEqual(self.operations_called[3][0].name, 'DeleteObject')

@requires_crt
@requires_crt()
def test_mv_works_if_mrap_arn_resolves_to_different_bucket(self):
cmdline = (f"{self.prefix} s3://bucket/key "
"s3://arn:aws:s3::123456789012:accesspoint/foobar.mrap/key "
Expand Down Expand Up @@ -429,7 +429,7 @@ def test_skips_validation_if_keys_are_different_outpost_alias(self):
"--validate-same-s3-paths")
self.assert_runs_mv_without_validation(cmdline)

@requires_crt
@requires_crt()
def test_skips_validation_if_keys_are_different_mrap_arn(self):
cmdline = (f"{self.prefix} s3://bucket/key "
"s3://arn:aws:s3::123456789012:accesspoint/foobar.mrap/key2 "
Expand Down
45 changes: 45 additions & 0 deletions tests/unit/test_decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from unittest import mock

import pytest

from tests import requires_crt


class TestRequiresCrt:
def test_bare_requires_crt_fails_immediately(self):
with pytest.raises(TypeError):

@requires_crt
def my_test():
pass

def test_requires_crt_skips_when_no_crt(self):
with mock.patch('tests.HAS_CRT', False):

@requires_crt()
def my_test():
assert False

assert getattr(my_test, '__unittest_skip__', False) is True

def test_requires_crt_runs_when_crt_available(self):
with mock.patch('tests.HAS_CRT', True):

@requires_crt()
def my_test():
pass

assert getattr(my_test, '__unittest_skip__', False) is False
Loading