Added support for recent CPython and PyPy versions; Droped Python v2.7 Support (#680)

This commit is contained in:
Andreas Motl
2022-10-08 02:28:36 +02:00
committed by GitHub
parent f7244cce3d
commit 00afe4e5b6
164 changed files with 746 additions and 2787 deletions

View File

@@ -23,16 +23,9 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import six
import time
import pytest
try:
# Python 3.x
from unittest import mock
except ImportError:
# Python 2.7
import mock
from unittest import mock
import requests
from apprise.common import ConfigFormat
@@ -86,7 +79,7 @@ def test_config_http(mock_post):
# Our default content
default_content = """taga,tagb=good://server01"""
class DummyResponse(object):
class DummyResponse:
"""
A dummy response used to manage our object
"""
@@ -122,8 +115,8 @@ def test_config_http(mock_post):
results = ConfigHTTP.parse_url('http://user:pass@localhost?+key=value')
assert isinstance(results, dict)
ch = ConfigHTTP(**results)
assert isinstance(ch.url(), six.string_types) is True
assert isinstance(ch.read(), six.string_types) is True
assert isinstance(ch.url(), str) is True
assert isinstance(ch.read(), str) is True
# one entry added
assert len(ch) == 1
@@ -131,8 +124,8 @@ def test_config_http(mock_post):
results = ConfigHTTP.parse_url('http://localhost:8080/path/')
assert isinstance(results, dict)
ch = ConfigHTTP(**results)
assert isinstance(ch.url(), six.string_types) is True
assert isinstance(ch.read(), six.string_types) is True
assert isinstance(ch.url(), str) is True
assert isinstance(ch.read(), str) is True
# one entry added
assert len(ch) == 1
@@ -143,16 +136,16 @@ def test_config_http(mock_post):
# Cache Handling; cache each request for 30 seconds
results = ConfigHTTP.parse_url('http://localhost:8080/path/?cache=30')
assert mock_post.call_count == 0
assert isinstance(ch.url(), six.string_types) is True
assert isinstance(ch.url(), str) is True
assert isinstance(results, dict)
ch = ConfigHTTP(**results)
assert mock_post.call_count == 0
assert isinstance(ch.url(), six.string_types) is True
assert isinstance(ch.url(), str) is True
assert mock_post.call_count == 0
assert isinstance(ch.read(), six.string_types) is True
assert isinstance(ch.read(), str) is True
assert mock_post.call_count == 1
# Clear all our mock counters
@@ -210,7 +203,7 @@ def test_config_http(mock_post):
# Invalid cache
results = ConfigHTTP.parse_url('http://localhost:8080/path/?cache=False')
assert isinstance(results, dict)
assert isinstance(ch.url(), six.string_types) is True
assert isinstance(ch.url(), str) is True
results = ConfigHTTP.parse_url('http://localhost:8080/path/?cache=-10')
assert isinstance(results, dict)
@@ -220,8 +213,8 @@ def test_config_http(mock_post):
results = ConfigHTTP.parse_url('http://user@localhost?format=text')
assert isinstance(results, dict)
ch = ConfigHTTP(**results)
assert isinstance(ch.url(), six.string_types) is True
assert isinstance(ch.read(), six.string_types) is True
assert isinstance(ch.url(), str) is True
assert isinstance(ch.read(), str) is True
# one entry added
assert len(ch) == 1
@@ -229,8 +222,8 @@ def test_config_http(mock_post):
results = ConfigHTTP.parse_url('https://localhost')
assert isinstance(results, dict)
ch = ConfigHTTP(**results)
assert isinstance(ch.url(), six.string_types) is True
assert isinstance(ch.read(), six.string_types) is True
assert isinstance(ch.url(), str) is True
assert isinstance(ch.read(), str) is True
# one entry added
assert len(ch) == 1
@@ -265,7 +258,7 @@ def test_config_http(mock_post):
# Test a buffer size limit reach
ch.max_buffer_size = len(dummy_response.text)
assert isinstance(ch.read(), six.string_types) is True
assert isinstance(ch.read(), str) is True
# Test YAML detection
yaml_supported_types = (
@@ -274,7 +267,7 @@ def test_config_http(mock_post):
for st in yaml_supported_types:
dummy_response.headers['Content-Type'] = st
ch.default_config_format = None
assert isinstance(ch.read(), six.string_types) is True
assert isinstance(ch.read(), str) is True
# Set to YAML
assert ch.default_config_format == ConfigFormat.YAML
@@ -284,7 +277,7 @@ def test_config_http(mock_post):
for st in text_supported_types:
dummy_response.headers['Content-Type'] = st
ch.default_config_format = None
assert isinstance(ch.read(), six.string_types) is True
assert isinstance(ch.read(), str) is True
# Set to TEXT
assert ch.default_config_format == ConfigFormat.TEXT
@@ -294,14 +287,14 @@ def test_config_http(mock_post):
for st in ukwn_supported_types:
dummy_response.headers['Content-Type'] = st
ch.default_config_format = None
assert isinstance(ch.read(), six.string_types) is True
assert isinstance(ch.read(), str) is True
# Remains unchanged
assert ch.default_config_format is None
# When the entry is missing; we handle this too
del dummy_response.headers['Content-Type']
ch.default_config_format = None
assert isinstance(ch.read(), six.string_types) is True
assert isinstance(ch.read(), str) is True
# Remains unchanged
assert ch.default_config_format is None
@@ -321,16 +314,16 @@ def test_config_http(mock_post):
# Our content is still within the limits, so we're okay
dummy_response.headers['Content-Length'] = 'garbage'
assert isinstance(ch.read(), six.string_types) is True
assert isinstance(ch.read(), str) is True
dummy_response.headers['Content-Length'] = 'None'
# Our content is still within the limits, so we're okay
assert isinstance(ch.read(), six.string_types) is True
assert isinstance(ch.read(), str) is True
# Handle cases where the content length is exactly at our limit
dummy_response.text = 'a' * ch.max_buffer_size
# This is acceptable
assert isinstance(ch.read(), six.string_types) is True
assert isinstance(ch.read(), str) is True
# If we are over our limit though..
dummy_response.text = 'b' * (ch.max_buffer_size + 1)