Fix asyncio warnings/markers. (#574)
* Fix asyncio warnings/markers. Signed-off-by: dblock <[email protected]> * Allow some flexibility in codecov. Signed-off-by: dblock <[email protected]> --------- Signed-off-by: dblock <[email protected]>
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
coverage:
|
||||||
|
status:
|
||||||
|
project:
|
||||||
|
default:
|
||||||
|
threshold: 0.1%
|
||||||
@@ -30,15 +30,12 @@ from typing import Any
|
|||||||
|
|
||||||
import mock
|
import mock
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest.mark.structures import MarkDecorator
|
|
||||||
from multidict import CIMultiDict
|
from multidict import CIMultiDict
|
||||||
|
|
||||||
from opensearchpy._async._extra_imports import aiohttp # type: ignore
|
from opensearchpy._async._extra_imports import aiohttp # type: ignore
|
||||||
from opensearchpy._async.compat import get_running_loop
|
from opensearchpy._async.compat import get_running_loop
|
||||||
from opensearchpy.connection.http_async import AsyncHttpConnection
|
from opensearchpy.connection.http_async import AsyncHttpConnection
|
||||||
|
|
||||||
pytestmark: MarkDecorator = pytest.mark.asyncio
|
|
||||||
|
|
||||||
|
|
||||||
class TestAsyncHttpConnection:
|
class TestAsyncHttpConnection:
|
||||||
def test_auth_as_tuple(self) -> None:
|
def test_auth_as_tuple(self) -> None:
|
||||||
@@ -60,6 +57,7 @@ class TestAsyncHttpConnection:
|
|||||||
c = AsyncHttpConnection(http_auth=auth_fn)
|
c = AsyncHttpConnection(http_auth=auth_fn)
|
||||||
assert callable(c._http_auth)
|
assert callable(c._http_auth)
|
||||||
|
|
||||||
|
@pytest.mark.asyncio # type: ignore
|
||||||
@mock.patch("aiohttp.ClientSession.request", new_callable=mock.Mock)
|
@mock.patch("aiohttp.ClientSession.request", new_callable=mock.Mock)
|
||||||
async def test_basicauth_in_request_session(self, mock_request: Any) -> None:
|
async def test_basicauth_in_request_session(self, mock_request: Any) -> None:
|
||||||
async def do_request(*args: Any, **kwargs: Any) -> Any:
|
async def do_request(*args: Any, **kwargs: Any) -> Any:
|
||||||
@@ -91,6 +89,7 @@ class TestAsyncHttpConnection:
|
|||||||
fingerprint=None,
|
fingerprint=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@pytest.mark.asyncio # type: ignore
|
||||||
@mock.patch("aiohttp.ClientSession.request", new_callable=mock.Mock)
|
@mock.patch("aiohttp.ClientSession.request", new_callable=mock.Mock)
|
||||||
async def test_callable_in_request_session(self, mock_request: Any) -> None:
|
async def test_callable_in_request_session(self, mock_request: Any) -> None:
|
||||||
def auth_fn(*args: Any, **kwargs: Any) -> Any:
|
def auth_fn(*args: Any, **kwargs: Any) -> Any:
|
||||||
|
|||||||
@@ -8,18 +8,24 @@
|
|||||||
# Modifications Copyright OpenSearch Contributors. See
|
# Modifications Copyright OpenSearch Contributors. See
|
||||||
# GitHub history for details.
|
# GitHub history for details.
|
||||||
|
|
||||||
from unittest import TestCase
|
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from _pytest.mark.structures import MarkDecorator
|
||||||
|
|
||||||
from opensearchpy._async.client import AsyncOpenSearch
|
from opensearchpy._async.client import AsyncOpenSearch
|
||||||
|
|
||||||
|
pytestmark: MarkDecorator = pytest.mark.asyncio
|
||||||
|
|
||||||
class TestPluginsClient(TestCase):
|
|
||||||
|
class TestPluginsClient:
|
||||||
async def test_plugins_client(self) -> None:
|
async def test_plugins_client(self) -> None:
|
||||||
with self.assertWarns(Warning) as w:
|
with warnings.catch_warnings(record=True) as w:
|
||||||
client = AsyncOpenSearch()
|
client = AsyncOpenSearch()
|
||||||
# testing double-init here
|
# testing double-init here
|
||||||
client.plugins.__init__(client) # type: ignore
|
client.plugins.__init__(client) # type: ignore
|
||||||
self.assertEqual(
|
assert (
|
||||||
str(w.warnings[0].message),
|
str(w[0].message)
|
||||||
"Cannot load `alerting` directly to AsyncOpenSearch as it already exists. Use `AsyncOpenSearch.plugin.alerting` instead.",
|
== "Cannot load `alerting` directly to AsyncOpenSearch as it already exists. Use `AsyncOpenSearch.plugin.alerting` instead."
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user