Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix asyncio warnings/markers. #574

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage:
status:
project:
default:
threshold: 0.1%
5 changes: 2 additions & 3 deletions test_opensearchpy/test_async/test_http_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@

import mock
import pytest
from _pytest.mark.structures import MarkDecorator
from multidict import CIMultiDict

from opensearchpy._async._extra_imports import aiohttp # type: ignore
from opensearchpy._async.compat import get_running_loop
from opensearchpy.connection.http_async import AsyncHttpConnection

pytestmark: MarkDecorator = pytest.mark.asyncio


class TestAsyncHttpConnection:
def test_auth_as_tuple(self) -> None:
Expand All @@ -60,6 +57,7 @@ def auth_fn() -> None:
c = AsyncHttpConnection(http_auth=auth_fn)
assert callable(c._http_auth)

@pytest.mark.asyncio # type: ignore
@mock.patch("aiohttp.ClientSession.request", new_callable=mock.Mock)
async def test_basicauth_in_request_session(self, mock_request: Any) -> None:
async def do_request(*args: Any, **kwargs: Any) -> Any:
Expand Down Expand Up @@ -91,6 +89,7 @@ async def do_request(*args: Any, **kwargs: Any) -> Any:
fingerprint=None,
)

@pytest.mark.asyncio # type: ignore
@mock.patch("aiohttp.ClientSession.request", new_callable=mock.Mock)
async def test_callable_in_request_session(self, mock_request: Any) -> None:
def auth_fn(*args: Any, **kwargs: Any) -> Any:
Expand Down
18 changes: 12 additions & 6 deletions test_opensearchpy/test_async/test_plugins_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@
# Modifications Copyright OpenSearch Contributors. See
# GitHub history for details.

from unittest import TestCase

import warnings

import pytest
from _pytest.mark.structures import MarkDecorator

from opensearchpy._async.client import AsyncOpenSearch

pytestmark: MarkDecorator = pytest.mark.asyncio


class TestPluginsClient(TestCase):
class TestPluginsClient:
async def test_plugins_client(self) -> None:
with self.assertWarns(Warning) as w:
with warnings.catch_warnings(record=True) as w:
client = AsyncOpenSearch()
# testing double-init here
client.plugins.__init__(client) # type: ignore
self.assertEqual(
str(w.warnings[0].message),
"Cannot load `alerting` directly to AsyncOpenSearch as it already exists. Use `AsyncOpenSearch.plugin.alerting` instead.",
assert (
str(w[0].message)
== "Cannot load `alerting` directly to AsyncOpenSearch as it already exists. Use `AsyncOpenSearch.plugin.alerting` instead."
)
Loading