|
| 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.utils.s3transfer import ( |
| 19 | + requires_crt, |
| 20 | + skip_if_using_serial_implementation, |
| 21 | + skip_if_windows, |
| 22 | +) |
| 23 | + |
| 24 | + |
| 25 | +class TestSkipIfWindows: |
| 26 | + def test_bare_skip_if_windows_fails_immediately(self): |
| 27 | + with pytest.raises(TypeError): |
| 28 | + |
| 29 | + @skip_if_windows |
| 30 | + def my_test(): |
| 31 | + pass |
| 32 | + |
| 33 | + def test_skip_if_windows_skips_on_windows(self): |
| 34 | + with mock.patch('tests.utils.s3transfer.platform') as mock_platform: |
| 35 | + mock_platform.system.return_value = 'Windows' |
| 36 | + |
| 37 | + @skip_if_windows('Not supported on Windows') |
| 38 | + def my_test(): |
| 39 | + assert False |
| 40 | + |
| 41 | + assert getattr(my_test, '__unittest_skip__', False) is True |
| 42 | + |
| 43 | + def test_skip_if_windows_runs_on_non_windows(self): |
| 44 | + with mock.patch('tests.utils.s3transfer.platform') as mock_platform: |
| 45 | + mock_platform.system.return_value = 'Linux' |
| 46 | + |
| 47 | + @skip_if_windows('Not supported on Windows') |
| 48 | + def my_test(): |
| 49 | + pass |
| 50 | + |
| 51 | + assert getattr(my_test, '__unittest_skip__', False) is False |
| 52 | + |
| 53 | + |
| 54 | +class TestSkipIfUsingSerialImplementation: |
| 55 | + def test_bare_skip_if_using_serial_implementation_fails_immediately(self): |
| 56 | + with pytest.raises(TypeError): |
| 57 | + |
| 58 | + @skip_if_using_serial_implementation |
| 59 | + def my_test(): |
| 60 | + pass |
| 61 | + |
| 62 | + def test_skip_if_using_serial_implementation_skips_when_serial(self): |
| 63 | + with mock.patch( |
| 64 | + 'tests.utils.s3transfer.is_serial_implementation', |
| 65 | + return_value=True, |
| 66 | + ): |
| 67 | + |
| 68 | + @skip_if_using_serial_implementation( |
| 69 | + 'Not supported in serial mode' |
| 70 | + ) |
| 71 | + def my_test(): |
| 72 | + assert False |
| 73 | + |
| 74 | + assert getattr(my_test, '__unittest_skip__', False) is True |
| 75 | + |
| 76 | + def test_skip_if_using_serial_implementation_runs_when_not_serial(self): |
| 77 | + with mock.patch( |
| 78 | + 'tests.utils.s3transfer.is_serial_implementation', |
| 79 | + return_value=False, |
| 80 | + ): |
| 81 | + |
| 82 | + @skip_if_using_serial_implementation( |
| 83 | + 'Not supported in serial mode' |
| 84 | + ) |
| 85 | + def my_test(): |
| 86 | + pass |
| 87 | + |
| 88 | + assert getattr(my_test, '__unittest_skip__', False) is False |
| 89 | + |
| 90 | + |
| 91 | +class TestRequiresCrt: |
| 92 | + def test_bare_requires_crt_fails_immediately(self): |
| 93 | + with pytest.raises(TypeError): |
| 94 | + |
| 95 | + @requires_crt |
| 96 | + def my_test(): |
| 97 | + pass |
| 98 | + |
| 99 | + def test_requires_crt_skips_when_no_crt(self): |
| 100 | + with mock.patch('tests.utils.s3transfer.HAS_CRT', False): |
| 101 | + |
| 102 | + @requires_crt() |
| 103 | + def my_test(): |
| 104 | + assert False |
| 105 | + |
| 106 | + assert getattr(my_test, '__unittest_skip__', False) is True |
| 107 | + |
| 108 | + def test_requires_crt_runs_when_crt_available(self): |
| 109 | + with mock.patch('tests.utils.s3transfer.HAS_CRT', True): |
| 110 | + |
| 111 | + @requires_crt() |
| 112 | + def my_test(): |
| 113 | + pass |
| 114 | + |
| 115 | + assert getattr(my_test, '__unittest_skip__', False) is False |
0 commit comments