mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 09:13:23 +00:00
fix tornado related warnings
This commit is contained in:
@@ -13,10 +13,6 @@ markers = ["online"]
|
|||||||
filterwarnings = [
|
filterwarnings = [
|
||||||
"error",
|
"error",
|
||||||
'''ignore:datetime\.datetime\.utcfromtimestamp\(\) is deprecated and scheduled for removal in a future version.*:DeprecationWarning''',
|
'''ignore:datetime\.datetime\.utcfromtimestamp\(\) is deprecated and scheduled for removal in a future version.*:DeprecationWarning''',
|
||||||
'''ignore:There is no current event loop:DeprecationWarning''',
|
|
||||||
'''ignore:make_current is deprecated; start the event loop first:DeprecationWarning''',
|
|
||||||
'''ignore:clear_current is deprecated:DeprecationWarning''',
|
|
||||||
'''ignore:the \(type, exc, tb\) signature of throw\(\) is deprecated, use the single-arg signature instead.:DeprecationWarning''',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
|
|||||||
1
setup.py
1
setup.py
@@ -67,7 +67,6 @@ extras_require = {
|
|||||||
"pytest-asyncio",
|
"pytest-asyncio",
|
||||||
"pytest-cov",
|
"pytest-cov",
|
||||||
"pytest-httpbin",
|
"pytest-httpbin",
|
||||||
"pytest-tornado",
|
|
||||||
"pytest",
|
"pytest",
|
||||||
"requests>=2.22.0",
|
"requests>=2.22.0",
|
||||||
"tornado",
|
"tornado",
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
"""Test requests' interaction with vcr"""
|
"""Test requests' interaction with vcr"""
|
||||||
|
import asyncio
|
||||||
|
import functools
|
||||||
|
import inspect
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -10,6 +12,7 @@ from vcr.errors import CannotOverwriteExistingCassetteException
|
|||||||
from ..assertions import assert_cassette_empty, assert_is_json_bytes
|
from ..assertions import assert_cassette_empty, assert_is_json_bytes
|
||||||
|
|
||||||
tornado = pytest.importorskip("tornado")
|
tornado = pytest.importorskip("tornado")
|
||||||
|
gen = pytest.importorskip("tornado.gen")
|
||||||
http = pytest.importorskip("tornado.httpclient")
|
http = pytest.importorskip("tornado.httpclient")
|
||||||
|
|
||||||
# whether the current version of Tornado supports the raise_error argument for
|
# whether the current version of Tornado supports the raise_error argument for
|
||||||
@@ -18,6 +21,20 @@ supports_raise_error = tornado.version_info >= (4,)
|
|||||||
raise_error_for_response_code_only = tornado.version_info >= (6,)
|
raise_error_for_response_code_only = tornado.version_info >= (6,)
|
||||||
|
|
||||||
|
|
||||||
|
def gen_test(func):
|
||||||
|
@functools.wraps(func)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
async def coro():
|
||||||
|
return await gen.coroutine(func)(*args, **kwargs)
|
||||||
|
|
||||||
|
return asyncio.run(coro())
|
||||||
|
|
||||||
|
# Patch the signature so pytest can inject fixtures
|
||||||
|
# we can't use wrapt.decorator because it returns a generator function
|
||||||
|
wrapper.__signature__ = inspect.signature(func)
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=["https", "http"])
|
@pytest.fixture(params=["https", "http"])
|
||||||
def scheme(request):
|
def scheme(request):
|
||||||
"""Fixture that returns both http and https."""
|
"""Fixture that returns both http and https."""
|
||||||
@@ -52,7 +69,7 @@ def post(client, url, data=None, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_status_code(get_client, scheme, tmpdir):
|
def test_status_code(get_client, scheme, tmpdir):
|
||||||
"""Ensure that we can read the status code"""
|
"""Ensure that we can read the status code"""
|
||||||
url = scheme + "://httpbin.org/"
|
url = scheme + "://httpbin.org/"
|
||||||
@@ -65,7 +82,7 @@ def test_status_code(get_client, scheme, tmpdir):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_headers(get_client, scheme, tmpdir):
|
def test_headers(get_client, scheme, tmpdir):
|
||||||
"""Ensure that we can read the headers back"""
|
"""Ensure that we can read the headers back"""
|
||||||
url = scheme + "://httpbin.org/"
|
url = scheme + "://httpbin.org/"
|
||||||
@@ -78,7 +95,7 @@ def test_headers(get_client, scheme, tmpdir):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_body(get_client, tmpdir, scheme):
|
def test_body(get_client, tmpdir, scheme):
|
||||||
"""Ensure the responses are all identical enough"""
|
"""Ensure the responses are all identical enough"""
|
||||||
|
|
||||||
@@ -91,7 +108,7 @@ def test_body(get_client, tmpdir, scheme):
|
|||||||
assert 1 == cass.play_count
|
assert 1 == cass.play_count
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_effective_url(get_client, tmpdir, httpbin):
|
def test_effective_url(get_client, tmpdir, httpbin):
|
||||||
"""Ensure that the effective_url is captured"""
|
"""Ensure that the effective_url is captured"""
|
||||||
url = httpbin.url + "/redirect/1"
|
url = httpbin.url + "/redirect/1"
|
||||||
@@ -105,7 +122,7 @@ def test_effective_url(get_client, tmpdir, httpbin):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_auth(get_client, tmpdir, scheme):
|
def test_auth(get_client, tmpdir, scheme):
|
||||||
"""Ensure that we can handle basic auth"""
|
"""Ensure that we can handle basic auth"""
|
||||||
auth = ("user", "passwd")
|
auth = ("user", "passwd")
|
||||||
@@ -121,7 +138,7 @@ def test_auth(get_client, tmpdir, scheme):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_auth_failed(get_client, tmpdir, scheme):
|
def test_auth_failed(get_client, tmpdir, scheme):
|
||||||
"""Ensure that we can save failed auth statuses"""
|
"""Ensure that we can save failed auth statuses"""
|
||||||
auth = ("user", "wrongwrongwrong")
|
auth = ("user", "wrongwrongwrong")
|
||||||
@@ -145,7 +162,7 @@ def test_auth_failed(get_client, tmpdir, scheme):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_post(get_client, tmpdir, scheme):
|
def test_post(get_client, tmpdir, scheme):
|
||||||
"""Ensure that we can post and cache the results"""
|
"""Ensure that we can post and cache the results"""
|
||||||
data = {"key1": "value1", "key2": "value2"}
|
data = {"key1": "value1", "key2": "value2"}
|
||||||
@@ -160,7 +177,7 @@ def test_post(get_client, tmpdir, scheme):
|
|||||||
assert 1 == cass.play_count
|
assert 1 == cass.play_count
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_redirects(get_client, tmpdir, httpbin):
|
def test_redirects(get_client, tmpdir, httpbin):
|
||||||
"""Ensure that we can handle redirects"""
|
"""Ensure that we can handle redirects"""
|
||||||
url = httpbin + "/redirect-to?url=bytes/1024&status_code=301"
|
url = httpbin + "/redirect-to?url=bytes/1024&status_code=301"
|
||||||
@@ -173,7 +190,7 @@ def test_redirects(get_client, tmpdir, httpbin):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_cross_scheme(get_client, tmpdir, scheme):
|
def test_cross_scheme(get_client, tmpdir, scheme):
|
||||||
"""Ensure that requests between schemes are treated separately"""
|
"""Ensure that requests between schemes are treated separately"""
|
||||||
# First fetch a url under http, and then again under https and then
|
# First fetch a url under http, and then again under https and then
|
||||||
@@ -193,7 +210,7 @@ def test_cross_scheme(get_client, tmpdir, scheme):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_gzip(get_client, tmpdir, scheme):
|
def test_gzip(get_client, tmpdir, scheme):
|
||||||
"""
|
"""
|
||||||
Ensure that httpclient is able to automatically decompress the response
|
Ensure that httpclient is able to automatically decompress the response
|
||||||
@@ -219,7 +236,7 @@ def test_gzip(get_client, tmpdir, scheme):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_https_with_cert_validation_disabled(get_client, tmpdir):
|
def test_https_with_cert_validation_disabled(get_client, tmpdir):
|
||||||
cass_path = str(tmpdir.join("cert_validation_disabled.yaml"))
|
cass_path = str(tmpdir.join("cert_validation_disabled.yaml"))
|
||||||
|
|
||||||
@@ -231,7 +248,7 @@ def test_https_with_cert_validation_disabled(get_client, tmpdir):
|
|||||||
assert 1 == cass.play_count
|
assert 1 == cass.play_count
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_unsupported_features_raises_in_future(get_client, tmpdir):
|
def test_unsupported_features_raises_in_future(get_client, tmpdir):
|
||||||
"""Ensure that the exception for an AsyncHTTPClient feature not being
|
"""Ensure that the exception for an AsyncHTTPClient feature not being
|
||||||
supported is raised inside the future."""
|
supported is raised inside the future."""
|
||||||
@@ -253,7 +270,7 @@ def test_unsupported_features_raises_in_future(get_client, tmpdir):
|
|||||||
raise_error_for_response_code_only,
|
raise_error_for_response_code_only,
|
||||||
reason="raise_error only ignores HTTPErrors due to response code",
|
reason="raise_error only ignores HTTPErrors due to response code",
|
||||||
)
|
)
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_unsupported_features_raise_error_disabled(get_client, tmpdir):
|
def test_unsupported_features_raise_error_disabled(get_client, tmpdir):
|
||||||
"""Ensure that the exception for an AsyncHTTPClient feature not being
|
"""Ensure that the exception for an AsyncHTTPClient feature not being
|
||||||
supported is not raised if raise_error=False."""
|
supported is not raised if raise_error=False."""
|
||||||
@@ -273,7 +290,7 @@ def test_unsupported_features_raise_error_disabled(get_client, tmpdir):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_cannot_overwrite_cassette_raises_in_future(get_client, tmpdir):
|
def test_cannot_overwrite_cassette_raises_in_future(get_client, tmpdir):
|
||||||
"""Ensure that CannotOverwriteExistingCassetteException is raised inside
|
"""Ensure that CannotOverwriteExistingCassetteException is raised inside
|
||||||
the future."""
|
the future."""
|
||||||
@@ -293,7 +310,7 @@ def test_cannot_overwrite_cassette_raises_in_future(get_client, tmpdir):
|
|||||||
raise_error_for_response_code_only,
|
raise_error_for_response_code_only,
|
||||||
reason="raise_error only ignores HTTPErrors due to response code",
|
reason="raise_error only ignores HTTPErrors due to response code",
|
||||||
)
|
)
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_cannot_overwrite_cassette_raise_error_disabled(get_client, tmpdir):
|
def test_cannot_overwrite_cassette_raise_error_disabled(get_client, tmpdir):
|
||||||
"""Ensure that CannotOverwriteExistingCassetteException is not raised if
|
"""Ensure that CannotOverwriteExistingCassetteException is not raised if
|
||||||
raise_error=False in the fetch() call."""
|
raise_error=False in the fetch() call."""
|
||||||
@@ -307,14 +324,14 @@ def test_cannot_overwrite_cassette_raise_error_disabled(get_client, tmpdir):
|
|||||||
assert isinstance(response.error, CannotOverwriteExistingCassetteException)
|
assert isinstance(response.error, CannotOverwriteExistingCassetteException)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
@vcr.use_cassette(path_transformer=vcr.default_vcr.ensure_suffix(".yaml"))
|
@vcr.use_cassette(path_transformer=vcr.default_vcr.ensure_suffix(".yaml"))
|
||||||
def test_tornado_with_decorator_use_cassette(get_client):
|
def test_tornado_with_decorator_use_cassette(get_client):
|
||||||
response = yield get_client().fetch(http.HTTPRequest("http://www.google.com/", method="GET"))
|
response = yield get_client().fetch(http.HTTPRequest("http://www.google.com/", method="GET"))
|
||||||
assert response.body.decode("utf-8") == "not actually google"
|
assert response.body.decode("utf-8") == "not actually google"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
@vcr.use_cassette(path_transformer=vcr.default_vcr.ensure_suffix(".yaml"))
|
@vcr.use_cassette(path_transformer=vcr.default_vcr.ensure_suffix(".yaml"))
|
||||||
def test_tornado_exception_can_be_caught(get_client):
|
def test_tornado_exception_can_be_caught(get_client):
|
||||||
try:
|
try:
|
||||||
@@ -329,7 +346,7 @@ def test_tornado_exception_can_be_caught(get_client):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_existing_references_get_patched(tmpdir):
|
def test_existing_references_get_patched(tmpdir):
|
||||||
from tornado.httpclient import AsyncHTTPClient
|
from tornado.httpclient import AsyncHTTPClient
|
||||||
|
|
||||||
@@ -343,7 +360,7 @@ def test_existing_references_get_patched(tmpdir):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_existing_instances_get_patched(get_client, tmpdir):
|
def test_existing_instances_get_patched(get_client, tmpdir):
|
||||||
"""Ensure that existing instances of AsyncHTTPClient get patched upon
|
"""Ensure that existing instances of AsyncHTTPClient get patched upon
|
||||||
entering VCR context."""
|
entering VCR context."""
|
||||||
@@ -359,7 +376,7 @@ def test_existing_instances_get_patched(get_client, tmpdir):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.gen_test
|
@gen_test
|
||||||
def test_request_time_is_set(get_client, tmpdir):
|
def test_request_time_is_set(get_client, tmpdir):
|
||||||
"""Ensures that the request_time on HTTPResponses is set."""
|
"""Ensures that the request_time on HTTPResponses is set."""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user