|
| 1 | +# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 | +# may not use this file except in compliance with the License. A copy of |
| 5 | +# the License is located at |
| 6 | +# |
| 7 | +# http://aws.amazon.com/apache2.0/ |
| 8 | +# |
| 9 | +# or in the "license" file accompanying this file. This file is |
| 10 | +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 | +# ANY KIND, either express or implied. See the License for the specific |
| 12 | +# language governing permissions and limitations under the License. |
| 13 | +"""Unit test suite for ensuring the Python Runtime is supported.""" |
| 14 | +import datetime |
| 15 | +import sys |
| 16 | + |
| 17 | +import mock |
| 18 | +import pytest |
| 19 | + |
| 20 | +from aws_encryption_sdk import check_python_version |
| 21 | +from aws_encryption_sdk.identifiers import PythonVersionSupport |
| 22 | + |
| 23 | +pytestmark = [pytest.mark.unit, pytest.mark.local] |
| 24 | + |
| 25 | + |
| 26 | +class TestBeforeErrorDate: |
| 27 | + def test_happy_version(self): |
| 28 | + with mock.patch.object(sys, "version_info") as v_info: |
| 29 | + v_info.major = PythonVersionSupport.WARN_BELOW_MAJOR |
| 30 | + v_info.minor = PythonVersionSupport.WARN_BELOW_MINOR |
| 31 | + with pytest.warns(None) as record: |
| 32 | + check_python_version(error_date=datetime.datetime.now() + datetime.timedelta(days=1)) |
| 33 | + assert len(record) == 0 |
| 34 | + |
| 35 | + def test_below_warn(self): |
| 36 | + with mock.patch.object(sys, "version_info") as v_info: |
| 37 | + v_info.major = PythonVersionSupport.WARN_BELOW_MAJOR - 1 |
| 38 | + v_info.minor = PythonVersionSupport.WARN_BELOW_MINOR |
| 39 | + with pytest.warns(DeprecationWarning): |
| 40 | + check_python_version(error_date=datetime.datetime.now() + datetime.timedelta(days=1)) |
| 41 | + |
| 42 | + |
| 43 | +class TestAfterErrorDate: |
| 44 | + def test_happy_version(self, capsys): |
| 45 | + with mock.patch.object(sys, "version_info") as v_info: |
| 46 | + v_info.major = PythonVersionSupport.WARN_BELOW_MAJOR |
| 47 | + v_info.minor = PythonVersionSupport.WARN_BELOW_MINOR |
| 48 | + with pytest.warns(None) as record: |
| 49 | + check_python_version(error_date=datetime.datetime.now() - datetime.timedelta(days=1)) |
| 50 | + assert len(record) == 0 |
| 51 | + captured = capsys.readouterr().err |
| 52 | + assert "ERROR" not in captured |
| 53 | + |
| 54 | + def test_below_error(self, capsys): |
| 55 | + with mock.patch.object(sys, "version_info") as v_info: |
| 56 | + v_info.major = PythonVersionSupport.ERROR_BELOW_MAJOR |
| 57 | + v_info.minor = PythonVersionSupport.ERROR_BELOW_MINOR - 1 |
| 58 | + with pytest.warns(None) as record: |
| 59 | + check_python_version(error_date=datetime.datetime.now() - datetime.timedelta(days=1)) |
| 60 | + assert len(record) == 0 |
| 61 | + captured = capsys.readouterr().err |
| 62 | + assert "ERROR" in captured |
0 commit comments