|
| 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