Merge .pyi type stubs inline (#563)

* Merged types into .py code.

Signed-off-by: dblock <[email protected]>

* Fix: nox -rs generate.

Signed-off-by: dblock <[email protected]>

* Updated CHANGELOG.

Signed-off-by: dblock <[email protected]>

* Use lowest common python version for lint.

Signed-off-by: dblock <[email protected]>

* Fix: don't typeshed.

Signed-off-by: dblock <[email protected]>

* Removed unneeded comment.

Signed-off-by: dblock <[email protected]>

* Simplify OPENSEARCH_URL.

Signed-off-by: dblock <[email protected]>

* Fix: positional ignore_status used as chunk_size.

Signed-off-by: dblock <[email protected]>

* Fix: parse version string.

Signed-off-by: dblock <[email protected]>

* Remove future annotations for Python 3.6.

Signed-off-by: dblock <[email protected]>

* Fix: types in documentation.

Signed-off-by: dblock <[email protected]>

* Improve CHANGELOG text.

Signed-off-by: dblock <[email protected]>

* Re-added missing separator.

Signed-off-by: dblock <[email protected]>

* Remove duplicate licenses.

Signed-off-by: dblock <[email protected]>

* Get rid of Optional[Any].

Signed-off-by: dblock <[email protected]>

* Fix docs with AsyncOpenSearch.

Signed-off-by: dblock <[email protected]>

* Fix: undo comment.

Signed-off-by: dblock <[email protected]>

---------

Signed-off-by: dblock <[email protected]>
This commit is contained in:
Daniel (dB.) Doubrovkine
2023-11-06 10:08:19 -08:00
committed by GitHub
parent 0d8a23dd78
commit dcb79cc322
268 changed files with 6218 additions and 16378 deletions
@@ -35,13 +35,13 @@ from ...utils import wipe_cluster
class AsyncOpenSearchTestCase(IsolatedAsyncioTestCase):
async def asyncSetUp(self):
async def asyncSetUp(self) -> None:
self.client = await get_test_client(
verify_certs=False, http_auth=("admin", "admin")
)
await add_connection("default", self.client)
async def asyncTearDown(self):
async def asyncTearDown(self) -> None:
wipe_cluster(self.client)
if self.client:
await self.client.close()
@@ -29,13 +29,14 @@
import asyncio
import pytest
from _pytest.mark.structures import MarkDecorator
import opensearchpy
from opensearchpy.helpers.test import OPENSEARCH_URL
from ...utils import wipe_cluster
pytestmark = pytest.mark.asyncio
pytestmark: MarkDecorator = pytest.mark.asyncio
@pytest.fixture(scope="function")
@@ -29,24 +29,25 @@
from __future__ import unicode_literals
import pytest
from _pytest.mark.structures import MarkDecorator
pytestmark = pytest.mark.asyncio
pytestmark: MarkDecorator = pytest.mark.asyncio
class TestUnicode:
async def test_indices_analyze(self, async_client):
async def test_indices_analyze(self, async_client) -> None:
await async_client.indices.analyze(body='{"text": "привет"}')
class TestBulk:
async def test_bulk_works_with_string_body(self, async_client):
async def test_bulk_works_with_string_body(self, async_client) -> None:
docs = '{ "index" : { "_index" : "bulk_test_index", "_id" : "1" } }\n{"answer": 42}'
response = await async_client.bulk(body=docs)
assert response["errors"] is False
assert len(response["items"]) == 1
async def test_bulk_works_with_bytestring_body(self, async_client):
async def test_bulk_works_with_bytestring_body(self, async_client) -> None:
docs = b'{ "index" : { "_index" : "bulk_test_index", "_id" : "2" } }\n{"answer": 42}'
response = await async_client.bulk(body=docs)
@@ -57,7 +58,7 @@ class TestBulk:
class TestYarlMissing:
async def test_aiohttp_connection_works_without_yarl(
self, async_client, monkeypatch
):
) -> None:
# This is a defensive test case for if aiohttp suddenly stops using yarl.
from opensearchpy._async import http_aiohttp
@@ -96,7 +96,7 @@ async def pull_request(write_client):
@fixture
async def setup_ubq_tests(client):
async def setup_ubq_tests(client) -> str:
index = "test-git"
await create_git_index(client, index)
await async_bulk(client, TEST_GIT_DATA, raise_on_error=True, refresh=True)
@@ -27,6 +27,7 @@
import asyncio
from typing import Tuple
import pytest
from mock import MagicMock, patch
@@ -48,8 +49,11 @@ class AsyncMock(MagicMock):
class FailingBulkClient(object):
def __init__(
self, client, fail_at=(2,), fail_with=TransportError(599, "Error!", {})
):
self,
client,
fail_at: Tuple[int] = (2,),
fail_with=TransportError(599, "Error!", {}),
) -> None:
self.client = client
self._called = 0
self._fail_at = fail_at
@@ -64,7 +68,7 @@ class FailingBulkClient(object):
class TestStreamingBulk(object):
async def test_actions_remain_unchanged(self, async_client):
async def test_actions_remain_unchanged(self, async_client) -> None:
actions1 = [{"_id": 1}, {"_id": 2}]
async for ok, item in actions.async_streaming_bulk(
async_client, actions1, index="test-index"
@@ -72,7 +76,7 @@ class TestStreamingBulk(object):
assert ok
assert [{"_id": 1}, {"_id": 2}] == actions1
async def test_all_documents_get_inserted(self, async_client):
async def test_all_documents_get_inserted(self, async_client) -> None:
docs = [{"answer": x, "_id": x} for x in range(100)]
async for ok, item in actions.async_streaming_bulk(
async_client, docs, index="test-index", refresh=True
@@ -118,7 +122,9 @@ class TestStreamingBulk(object):
"_source"
]
async def test_all_errors_from_chunk_are_raised_on_failure(self, async_client):
async def test_all_errors_from_chunk_are_raised_on_failure(
self, async_client
) -> None:
await async_client.indices.create(
"i",
{
@@ -187,7 +193,7 @@ class TestStreamingBulk(object):
}
} == results[1][1]
async def test_rejected_documents_are_retried(self, async_client):
async def test_rejected_documents_are_retried(self, async_client) -> None:
failing_client = FailingBulkClient(
async_client, fail_with=TransportError(429, "Rejected!", {})
)
@@ -217,7 +223,7 @@ class TestStreamingBulk(object):
async def test_rejected_documents_are_retried_at_most_max_retries_times(
self, async_client
):
) -> None:
failing_client = FailingBulkClient(
async_client, fail_at=(1, 2), fail_with=TransportError(429, "Rejected!", {})
)
@@ -246,7 +252,9 @@ class TestStreamingBulk(object):
assert {"value": 2, "relation": "eq"} == res["hits"]["total"]
assert 4 == failing_client._called
async def test_transport_error_is_raised_with_max_retries(self, async_client):
async def test_transport_error_is_raised_with_max_retries(
self, async_client
) -> None:
failing_client = FailingBulkClient(
async_client,
fail_at=(1, 2, 3, 4),
@@ -272,7 +280,7 @@ class TestStreamingBulk(object):
class TestBulk(object):
async def test_bulk_works_with_single_item(self, async_client):
async def test_bulk_works_with_single_item(self, async_client) -> None:
docs = [{"answer": 42, "_id": 1}]
success, failed = await actions.async_bulk(
async_client, docs, index="test-index", refresh=True
@@ -285,7 +293,7 @@ class TestBulk(object):
"_source"
]
async def test_all_documents_get_inserted(self, async_client):
async def test_all_documents_get_inserted(self, async_client) -> None:
docs = [{"answer": x, "_id": x} for x in range(100)]
success, failed = await actions.async_bulk(
async_client, docs, index="test-index", refresh=True
@@ -298,7 +306,7 @@ class TestBulk(object):
"_source"
]
async def test_stats_only_reports_numbers(self, async_client):
async def test_stats_only_reports_numbers(self, async_client) -> None:
docs = [{"answer": x} for x in range(100)]
success, failed = await actions.async_bulk(
async_client, docs, index="test-index", refresh=True, stats_only=True
@@ -402,7 +410,7 @@ class TestBulk(object):
class MockScroll:
def __init__(self):
def __init__(self) -> None:
self.calls = []
async def __call__(self, *args, **kwargs):
@@ -424,7 +432,7 @@ class MockScroll:
class MockResponse:
def __init__(self, resp):
def __init__(self, resp) -> None:
self.resp = resp
async def __call__(self, *args, **kwargs):
@@ -564,7 +572,7 @@ class TestScan(object):
assert data == [{"search_data": 1}]
assert mock_scroll.calls == []
async def test_no_scroll_id_fast_route(self, async_client, scan_teardown):
async def test_no_scroll_id_fast_route(self, async_client, scan_teardown) -> None:
with patch.object(async_client, "search", MockResponse({"no": "_scroll_id"})):
with patch.object(async_client, "scroll") as scroll_mock:
with patch.object(async_client, "clear_scroll") as clear_mock:
@@ -776,7 +784,7 @@ async def reindex_setup(async_client):
class TestReindex(object):
async def test_reindex_passes_kwargs_to_scan_and_bulk(
self, async_client, reindex_setup
):
) -> None:
await actions.async_reindex(
async_client,
"test_index",
@@ -795,7 +803,7 @@ class TestReindex(object):
await async_client.get(index="prod_index", id=42)
)["_source"]
async def test_reindex_accepts_a_query(self, async_client, reindex_setup):
async def test_reindex_accepts_a_query(self, async_client, reindex_setup) -> None:
await actions.async_reindex(
async_client,
"test_index",
@@ -814,7 +822,7 @@ class TestReindex(object):
await async_client.get(index="prod_index", id=42)
)["_source"]
async def test_all_documents_get_moved(self, async_client, reindex_setup):
async def test_all_documents_get_moved(self, async_client, reindex_setup) -> None:
await actions.async_reindex(async_client, "test_index", "prod_index")
await async_client.indices.refresh()
@@ -10,6 +10,8 @@
from __future__ import unicode_literals
from typing import Any, Dict
async def create_flat_git_index(client, index):
# we will use user on several places
@@ -1076,7 +1078,7 @@ DATA = [
]
def flatten_doc(d):
def flatten_doc(d) -> Dict[str, Any]:
src = d["_source"].copy()
del src["commit_repo"]
return {"_index": "flat-git", "_id": d["_id"], "_source": src}
@@ -1085,7 +1087,7 @@ def flatten_doc(d):
FLAT_DATA = [flatten_doc(d) for d in DATA if "routing" in d]
def create_test_git_data(d):
def create_test_git_data(d) -> Dict[str, Any]:
src = d["_source"].copy()
return {
"_index": "test-git",
@@ -146,7 +146,7 @@ async def test_serialization(write_client):
}
async def test_nested_inner_hits_are_wrapped_properly(pull_request):
async def test_nested_inner_hits_are_wrapped_properly(pull_request) -> None:
history_query = Q(
"nested",
path="comments.history",
@@ -174,7 +174,7 @@ async def test_nested_inner_hits_are_wrapped_properly(pull_request):
assert "score" in history.meta
async def test_nested_inner_hits_are_deserialized_properly(pull_request):
async def test_nested_inner_hits_are_deserialized_properly(pull_request) -> None:
s = PullRequest.search().query(
"nested",
inner_hits={},
@@ -189,7 +189,7 @@ async def test_nested_inner_hits_are_deserialized_properly(pull_request):
assert isinstance(pr.comments[0].created_at, datetime)
async def test_nested_top_hits_are_wrapped_properly(pull_request):
async def test_nested_top_hits_are_wrapped_properly(pull_request) -> None:
s = PullRequest.search()
s.aggs.bucket("comments", "nested", path="comments").metric(
"hits", "top_hits", size=1
@@ -201,7 +201,7 @@ async def test_nested_top_hits_are_wrapped_properly(pull_request):
assert isinstance(r.aggregations.comments.hits.hits[0], Comment)
async def test_update_object_field(write_client):
async def test_update_object_field(write_client) -> None:
await Wiki.init()
w = Wiki(
owner=User(name="Honza Kral"),
@@ -221,7 +221,7 @@ async def test_update_object_field(write_client):
assert w.ranked == {"test1": 0.1, "topic2": 0.2}
async def test_update_script(write_client):
async def test_update_script(write_client) -> None:
await Wiki.init()
w = Wiki(owner=User(name="Honza Kral"), _id="opensearch-py", views=42)
await w.save()
@@ -231,7 +231,7 @@ async def test_update_script(write_client):
assert w.views == 47
async def test_update_retry_on_conflict(write_client):
async def test_update_retry_on_conflict(write_client) -> None:
await Wiki.init()
w = Wiki(owner=User(name="Honza Kral"), _id="opensearch-py", views=42)
await w.save()
@@ -250,7 +250,7 @@ async def test_update_retry_on_conflict(write_client):
@pytest.mark.parametrize("retry_on_conflict", [None, 0])
async def test_update_conflicting_version(write_client, retry_on_conflict):
async def test_update_conflicting_version(write_client, retry_on_conflict) -> None:
await Wiki.init()
w = Wiki(owner=User(name="Honza Kral"), _id="opensearch-py", views=42)
await w.save()
@@ -267,7 +267,7 @@ async def test_update_conflicting_version(write_client, retry_on_conflict):
)
async def test_save_and_update_return_doc_meta(write_client):
async def test_save_and_update_return_doc_meta(write_client) -> None:
await Wiki.init()
w = Wiki(owner=User(name="Honza Kral"), _id="opensearch-py", views=42)
resp = await w.save(return_doc_meta=True)
@@ -291,31 +291,33 @@ async def test_save_and_update_return_doc_meta(write_client):
assert resp.keys().__contains__("_version")
async def test_init(write_client):
async def test_init(write_client) -> None:
await Repository.init(index="test-git")
assert await write_client.indices.exists(index="test-git")
async def test_get_raises_404_on_index_missing(data_client):
async def test_get_raises_404_on_index_missing(data_client) -> None:
with raises(NotFoundError):
await Repository.get("opensearch-dsl-php", index="not-there")
async def test_get_raises_404_on_non_existent_id(data_client):
async def test_get_raises_404_on_non_existent_id(data_client) -> None:
with raises(NotFoundError):
await Repository.get("opensearch-dsl-php")
async def test_get_returns_none_if_404_ignored(data_client):
async def test_get_returns_none_if_404_ignored(data_client) -> None:
assert None is await Repository.get("opensearch-dsl-php", ignore=404)
async def test_get_returns_none_if_404_ignored_and_index_doesnt_exist(data_client):
async def test_get_returns_none_if_404_ignored_and_index_doesnt_exist(
data_client,
) -> None:
assert None is await Repository.get("42", index="not-there", ignore=404)
async def test_get(data_client):
async def test_get(data_client) -> None:
opensearch_repo = await Repository.get("opensearch-py")
assert isinstance(opensearch_repo, Repository)
@@ -323,15 +325,15 @@ async def test_get(data_client):
assert datetime(2014, 3, 3) == opensearch_repo.created_at
async def test_exists_return_true(data_client):
async def test_exists_return_true(data_client) -> None:
assert await Repository.exists("opensearch-py")
async def test_exists_false(data_client):
async def test_exists_false(data_client) -> None:
assert not await Repository.exists("opensearch-dsl-php")
async def test_get_with_tz_date(data_client):
async def test_get_with_tz_date(data_client) -> None:
first_commit = await Commit.get(
id="3ca6e1e73a071a705b4babd2f581c91a2a3e5037", routing="opensearch-py"
)
@@ -343,7 +345,7 @@ async def test_get_with_tz_date(data_client):
)
async def test_save_with_tz_date(data_client):
async def test_save_with_tz_date(data_client) -> None:
tzinfo = timezone("Europe/Prague")
first_commit = await Commit.get(
id="3ca6e1e73a071a705b4babd2f581c91a2a3e5037", routing="opensearch-py"
@@ -370,7 +372,7 @@ COMMIT_DOCS_WITH_MISSING = [
]
async def test_mget(data_client):
async def test_mget(data_client) -> None:
commits = await Commit.mget(COMMIT_DOCS_WITH_MISSING)
assert commits[0] is None
assert commits[1].meta.id == "3ca6e1e73a071a705b4babd2f581c91a2a3e5037"
@@ -378,23 +380,25 @@ async def test_mget(data_client):
assert commits[3].meta.id == "eb3e543323f189fd7b698e66295427204fff5755"
async def test_mget_raises_exception_when_missing_param_is_invalid(data_client):
async def test_mget_raises_exception_when_missing_param_is_invalid(data_client) -> None:
with raises(ValueError):
await Commit.mget(COMMIT_DOCS_WITH_MISSING, missing="raj")
async def test_mget_raises_404_when_missing_param_is_raise(data_client):
async def test_mget_raises_404_when_missing_param_is_raise(data_client) -> None:
with raises(NotFoundError):
await Commit.mget(COMMIT_DOCS_WITH_MISSING, missing="raise")
async def test_mget_ignores_missing_docs_when_missing_param_is_skip(data_client):
async def test_mget_ignores_missing_docs_when_missing_param_is_skip(
data_client,
) -> None:
commits = await Commit.mget(COMMIT_DOCS_WITH_MISSING, missing="skip")
assert commits[0].meta.id == "3ca6e1e73a071a705b4babd2f581c91a2a3e5037"
assert commits[1].meta.id == "eb3e543323f189fd7b698e66295427204fff5755"
async def test_update_works_from_search_response(data_client):
async def test_update_works_from_search_response(data_client) -> None:
opensearch_repo = (await Repository.search().execute())[0]
await opensearch_repo.update(owner={"other_name": "opensearchpy"})
@@ -405,7 +409,7 @@ async def test_update_works_from_search_response(data_client):
assert "opensearch" == new_version.owner.name
async def test_update(data_client):
async def test_update(data_client) -> None:
opensearch_repo = await Repository.get("opensearch-py")
v = opensearch_repo.meta.version
@@ -429,7 +433,7 @@ async def test_update(data_client):
assert "primary_term" in new_version.meta
async def test_save_updates_existing_doc(data_client):
async def test_save_updates_existing_doc(data_client) -> None:
opensearch_repo = await Repository.get("opensearch-py")
opensearch_repo.new_field = "testing-save"
@@ -442,7 +446,7 @@ async def test_save_updates_existing_doc(data_client):
assert new_repo["_seq_no"] == opensearch_repo.meta.seq_no
async def test_save_automatically_uses_seq_no_and_primary_term(data_client):
async def test_save_automatically_uses_seq_no_and_primary_term(data_client) -> None:
opensearch_repo = await Repository.get("opensearch-py")
opensearch_repo.meta.seq_no += 1
@@ -450,7 +454,7 @@ async def test_save_automatically_uses_seq_no_and_primary_term(data_client):
await opensearch_repo.save()
async def test_delete_automatically_uses_seq_no_and_primary_term(data_client):
async def test_delete_automatically_uses_seq_no_and_primary_term(data_client) -> None:
opensearch_repo = await Repository.get("opensearch-py")
opensearch_repo.meta.seq_no += 1
@@ -458,7 +462,7 @@ async def test_delete_automatically_uses_seq_no_and_primary_term(data_client):
await opensearch_repo.delete()
async def assert_doc_equals(expected, actual):
async def assert_doc_equals(expected, actual) -> None:
async for f in aiter(expected):
assert f in actual
assert actual[f] == expected[f]
@@ -479,7 +483,7 @@ async def test_can_save_to_different_index(write_client):
)
async def test_save_without_skip_empty_will_include_empty_fields(write_client):
async def test_save_without_skip_empty_will_include_empty_fields(write_client) -> None:
test_repo = Repository(field_1=[], field_2=None, field_3={}, meta={"id": 42})
assert await test_repo.save(index="test-document", skip_empty=False)
@@ -494,7 +498,7 @@ async def test_save_without_skip_empty_will_include_empty_fields(write_client):
)
async def test_delete(write_client):
async def test_delete(write_client) -> None:
await write_client.create(
index="test-document",
id="opensearch-py",
@@ -515,11 +519,11 @@ async def test_delete(write_client):
)
async def test_search(data_client):
async def test_search(data_client) -> None:
assert await Repository.search().count() == 1
async def test_search_returns_proper_doc_classes(data_client):
async def test_search_returns_proper_doc_classes(data_client) -> None:
result = await Repository.search().execute()
opensearch_repo = result.hits[0]
@@ -528,7 +532,7 @@ async def test_search_returns_proper_doc_classes(data_client):
assert opensearch_repo.owner.name == "opensearch"
async def test_refresh_mapping(data_client):
async def test_refresh_mapping(data_client) -> None:
class Commit(AsyncDocument):
class Index:
name = "git"
@@ -542,7 +546,7 @@ async def test_refresh_mapping(data_client):
assert isinstance(Commit._index._mapping["committed_date"], Date)
async def test_highlight_in_meta(data_client):
async def test_highlight_in_meta(data_client) -> None:
commit = (
await Commit.search()
.query("match", description="inverting")
@@ -11,6 +11,7 @@
from datetime import datetime
import pytest
from _pytest.mark.structures import MarkDecorator
from opensearchpy import A, Boolean, Date, Keyword
from opensearchpy._async.helpers.document import AsyncDocument
@@ -25,7 +26,7 @@ from test_opensearchpy.test_async.test_server.test_helpers.test_document import
PullRequest,
)
pytestmark = pytest.mark.asyncio
pytestmark: MarkDecorator = pytest.mark.asyncio
class Repos(AsyncDocument):
@@ -118,7 +119,7 @@ def pr_search_cls(opensearch_version):
return PRSearch
async def test_facet_with_custom_metric(data_client):
async def test_facet_with_custom_metric(data_client) -> None:
ms = MetricSearch()
r = await ms.execute()
@@ -127,7 +128,7 @@ async def test_facet_with_custom_metric(data_client):
assert dates[0] == 1399038439000
async def test_nested_facet(pull_request, pr_search_cls):
async def test_nested_facet(pull_request, pr_search_cls) -> None:
prs = pr_search_cls()
r = await prs.execute()
@@ -135,7 +136,7 @@ async def test_nested_facet(pull_request, pr_search_cls):
assert [(datetime(2018, 1, 1, 0, 0), 1, False)] == r.facets.comments
async def test_nested_facet_with_filter(pull_request, pr_search_cls):
async def test_nested_facet_with_filter(pull_request, pr_search_cls) -> None:
prs = pr_search_cls(filters={"comments": datetime(2018, 1, 1, 0, 0)})
r = await prs.execute()
@@ -147,7 +148,7 @@ async def test_nested_facet_with_filter(pull_request, pr_search_cls):
assert not r.hits
async def test_datehistogram_facet(data_client, repo_search_cls):
async def test_datehistogram_facet(data_client, repo_search_cls) -> None:
rs = repo_search_cls()
r = await rs.execute()
@@ -155,7 +156,7 @@ async def test_datehistogram_facet(data_client, repo_search_cls):
assert [(datetime(2014, 3, 1, 0, 0), 1, False)] == r.facets.created
async def test_boolean_facet(data_client, repo_search_cls):
async def test_boolean_facet(data_client, repo_search_cls) -> None:
rs = repo_search_cls()
r = await rs.execute()
@@ -167,7 +168,7 @@ async def test_boolean_facet(data_client, repo_search_cls):
async def test_empty_search_finds_everything(
data_client, opensearch_version, commit_search_cls
):
) -> None:
cs = commit_search_cls()
r = await cs.execute()
assert r.hits.total.value == 52
@@ -213,7 +214,7 @@ async def test_empty_search_finds_everything(
async def test_term_filters_are_shown_as_selected_and_data_is_filtered(
data_client, commit_search_cls
):
) -> None:
cs = commit_search_cls(filters={"files": "test_opensearchpy/test_dsl"})
r = await cs.execute()
@@ -259,7 +260,7 @@ async def test_term_filters_are_shown_as_selected_and_data_is_filtered(
async def test_range_filters_are_shown_as_selected_and_data_is_filtered(
data_client, commit_search_cls
):
) -> None:
cs = commit_search_cls(filters={"deletions": "better"})
r = await cs.execute()
@@ -267,7 +268,7 @@ async def test_range_filters_are_shown_as_selected_and_data_is_filtered(
assert 19 == r.hits.total.value
async def test_pagination(data_client, commit_search_cls):
async def test_pagination(data_client, commit_search_cls) -> None:
cs = commit_search_cls()
cs = cs[0:20]
@@ -9,13 +9,14 @@
# GitHub history for details.
import pytest
from _pytest.mark.structures import MarkDecorator
from opensearchpy import Date, Text
from opensearchpy._async.helpers.document import AsyncDocument
from opensearchpy._async.helpers.index import AsyncIndex, AsyncIndexTemplate
from opensearchpy.helpers import analysis
pytestmark = pytest.mark.asyncio
pytestmark: MarkDecorator = pytest.mark.asyncio
class Post(AsyncDocument):
@@ -23,7 +24,7 @@ class Post(AsyncDocument):
published_from = Date()
async def test_index_template_works(write_client):
async def test_index_template_works(write_client) -> None:
it = AsyncIndexTemplate("test-template", "test-*")
it.document(Post)
it.settings(number_of_replicas=0, number_of_shards=1)
@@ -44,7 +45,7 @@ async def test_index_template_works(write_client):
} == await write_client.indices.get_mapping(index="test-blog")
async def test_index_can_be_saved_even_with_settings(write_client):
async def test_index_can_be_saved_even_with_settings(write_client) -> None:
i = AsyncIndex("test-blog", using=write_client)
i.settings(number_of_shards=3, number_of_replicas=0)
await i.save()
@@ -59,12 +60,12 @@ async def test_index_can_be_saved_even_with_settings(write_client):
)
async def test_index_exists(data_client):
async def test_index_exists(data_client) -> None:
assert await AsyncIndex("git").exists()
assert not await AsyncIndex("not-there").exists()
async def test_index_can_be_created_with_settings_and_mappings(write_client):
async def test_index_can_be_created_with_settings_and_mappings(write_client) -> None:
i = AsyncIndex("test-blog", using=write_client)
i.document(Post)
i.settings(number_of_replicas=0, number_of_shards=1)
@@ -89,7 +90,7 @@ async def test_index_can_be_created_with_settings_and_mappings(write_client):
}
async def test_delete(write_client):
async def test_delete(write_client) -> None:
await write_client.indices.create(
index="test-index",
body={"settings": {"number_of_replicas": 0, "number_of_shards": 1}},
@@ -100,7 +101,7 @@ async def test_delete(write_client):
assert not await write_client.indices.exists(index="test-index")
async def test_multiple_indices_with_same_doc_type_work(write_client):
async def test_multiple_indices_with_same_doc_type_work(write_client) -> None:
i1 = AsyncIndex("test-index-1", using=write_client)
i2 = AsyncIndex("test-index-2", using=write_client)
@@ -9,16 +9,17 @@
# GitHub history for details.
import pytest
from _pytest.mark.structures import MarkDecorator
from pytest import raises
from opensearchpy import exceptions
from opensearchpy._async.helpers import mapping
from opensearchpy.helpers import analysis
pytestmark = pytest.mark.asyncio
pytestmark: MarkDecorator = pytest.mark.asyncio
async def test_mapping_saved_into_opensearch(write_client):
async def test_mapping_saved_into_opensearch(write_client) -> None:
m = mapping.AsyncMapping()
m.field(
"name", "text", analyzer=analysis.analyzer("my_analyzer", tokenizer="keyword")
@@ -40,7 +41,7 @@ async def test_mapping_saved_into_opensearch(write_client):
async def test_mapping_saved_into_opensearch_when_index_already_exists_closed(
write_client,
):
) -> None:
m = mapping.AsyncMapping()
m.field(
"name", "text", analyzer=analysis.analyzer("my_analyzer", tokenizer="keyword")
@@ -65,7 +66,7 @@ async def test_mapping_saved_into_opensearch_when_index_already_exists_closed(
async def test_mapping_saved_into_opensearch_when_index_already_exists_with_analysis(
write_client,
):
) -> None:
m = mapping.AsyncMapping()
analyzer = analysis.analyzer("my_analyzer", tokenizer="keyword")
m.field("name", "text", analyzer=analyzer)
@@ -11,6 +11,7 @@
from __future__ import unicode_literals
import pytest
from _pytest.mark.structures import MarkDecorator
from pytest import raises
from opensearchpy import Date, Keyword, Q, Text, TransportError
@@ -19,7 +20,7 @@ from opensearchpy._async.helpers.search import AsyncMultiSearch, AsyncSearch
from opensearchpy.helpers.response import aggs
from test_opensearchpy.test_async.test_server.test_helpers.test_data import FLAT_DATA
pytestmark = pytest.mark.asyncio
pytestmark: MarkDecorator = pytest.mark.asyncio
class Repository(AsyncDocument):
@@ -40,7 +41,7 @@ class Commit(AsyncDocument):
name = "flat-git"
async def test_filters_aggregation_buckets_are_accessible(data_client):
async def test_filters_aggregation_buckets_are_accessible(data_client) -> None:
has_tests_query = Q("term", files="test_opensearchpy/test_dsl")
s = Commit.search()[0:0]
s.aggs.bucket("top_authors", "terms", field="author.name.raw").bucket(
@@ -61,7 +62,7 @@ async def test_filters_aggregation_buckets_are_accessible(data_client):
)
async def test_top_hits_are_wrapped_in_response(data_client):
async def test_top_hits_are_wrapped_in_response(data_client) -> None:
s = Commit.search()[0:0]
s.aggs.bucket("top_authors", "terms", field="author.name.raw").metric(
"top_commits", "top_hits", size=5
@@ -77,7 +78,7 @@ async def test_top_hits_are_wrapped_in_response(data_client):
assert isinstance(hits[0], Commit)
async def test_inner_hits_are_wrapped_in_response(data_client):
async def test_inner_hits_are_wrapped_in_response(data_client) -> None:
s = AsyncSearch(index="git")[0:1].query(
"has_parent", parent_type="repo", inner_hits={}, query=Q("match_all")
)
@@ -88,7 +89,7 @@ async def test_inner_hits_are_wrapped_in_response(data_client):
assert repr(commit.meta.inner_hits.repo[0]).startswith("<Hit(git/opensearch-py): ")
async def test_scan_respects_doc_types(data_client):
async def test_scan_respects_doc_types(data_client) -> None:
result = Repository.search().scan()
repos = await get_result(result)
@@ -97,7 +98,7 @@ async def test_scan_respects_doc_types(data_client):
assert repos[0].organization == "opensearch"
async def test_scan_iterates_through_all_docs(data_client):
async def test_scan_iterates_through_all_docs(data_client) -> None:
s = AsyncSearch(index="flat-git")
result = s.scan()
commits = await get_result(result)
@@ -113,7 +114,7 @@ async def get_result(b):
return a
async def test_multi_search(data_client):
async def test_multi_search(data_client) -> None:
s1 = Repository.search()
s2 = AsyncSearch(index="flat-git")
@@ -130,7 +131,7 @@ async def test_multi_search(data_client):
assert r2._search is s2
async def test_multi_missing(data_client):
async def test_multi_missing(data_client) -> None:
s1 = Repository.search()
s2 = AsyncSearch(index="flat-git")
s3 = AsyncSearch(index="does_not_exist")
@@ -153,7 +154,7 @@ async def test_multi_missing(data_client):
assert r3 is None
async def test_raw_subfield_can_be_used_in_aggs(data_client):
async def test_raw_subfield_can_be_used_in_aggs(data_client) -> None:
s = AsyncSearch(index="git")[0:0]
s.aggs.bucket("authors", "terms", field="author.name.raw", size=1)
r = await s.execute()
@@ -9,14 +9,15 @@
# GitHub history for details.
import pytest
from _pytest.mark.structures import MarkDecorator
from opensearchpy._async.helpers.update_by_query import AsyncUpdateByQuery
from opensearchpy.helpers.search import Q
pytestmark = pytest.mark.asyncio
pytestmark: MarkDecorator = pytest.mark.asyncio
async def test_update_by_query_no_script(write_client, setup_ubq_tests):
async def test_update_by_query_no_script(write_client, setup_ubq_tests) -> None:
index = setup_ubq_tests
ubq = (
@@ -35,7 +36,7 @@ async def test_update_by_query_no_script(write_client, setup_ubq_tests):
assert response.success()
async def test_update_by_query_with_script(write_client, setup_ubq_tests):
async def test_update_by_query_with_script(write_client, setup_ubq_tests) -> None:
index = setup_ubq_tests
ubq = (
@@ -52,7 +53,7 @@ async def test_update_by_query_with_script(write_client, setup_ubq_tests):
assert response.version_conflicts == 0
async def test_delete_by_query_with_script(write_client, setup_ubq_tests):
async def test_delete_by_query_with_script(write_client, setup_ubq_tests) -> None:
index = setup_ubq_tests
ubq = (
@@ -14,12 +14,13 @@ from __future__ import unicode_literals
import unittest
import pytest
from _pytest.mark.structures import MarkDecorator
from opensearchpy.helpers.test import OPENSEARCH_VERSION
from .. import AsyncOpenSearchTestCase
pytestmark = pytest.mark.asyncio
pytestmark: MarkDecorator = pytest.mark.asyncio
class TestAlertingPlugin(AsyncOpenSearchTestCase):
@@ -43,7 +44,7 @@ class TestAlertingPlugin(AsyncOpenSearchTestCase):
(OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)),
"Plugin not supported for opensearch version",
)
async def test_get_destination(self):
async def test_get_destination(self) -> None:
# Create a dummy destination
await self.test_create_destination()
@@ -123,7 +124,7 @@ class TestAlertingPlugin(AsyncOpenSearchTestCase):
(OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)),
"Plugin not supported for opensearch version",
)
async def test_search_monitor(self):
async def test_search_monitor(self) -> None:
# Create a dummy monitor
await self.test_create_monitor()
@@ -141,7 +142,7 @@ class TestAlertingPlugin(AsyncOpenSearchTestCase):
(OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)),
"Plugin not supported for opensearch version",
)
async def test_get_monitor(self):
async def test_get_monitor(self) -> None:
# Create a dummy monitor
await self.test_create_monitor()
@@ -165,7 +166,7 @@ class TestAlertingPlugin(AsyncOpenSearchTestCase):
(OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)),
"Plugin not supported for opensearch version",
)
async def test_run_monitor(self):
async def test_run_monitor(self) -> None:
# Create a dummy monitor
await self.test_create_monitor()
@@ -12,12 +12,13 @@
from __future__ import unicode_literals
import pytest
from _pytest.mark.structures import MarkDecorator
from opensearchpy.exceptions import NotFoundError
from .. import AsyncOpenSearchTestCase
pytestmark = pytest.mark.asyncio
pytestmark: MarkDecorator = pytest.mark.asyncio
class TestIndexManagementPlugin(AsyncOpenSearchTestCase):
@@ -68,7 +69,7 @@ class TestIndexManagementPlugin(AsyncOpenSearchTestCase):
}
}
async def test_create_policy(self):
async def test_create_policy(self) -> None:
# Test to create policy
response = await self.client.index_management.put_policy(
policy=self.POLICY_NAME, body=self.POLICY_CONTENT
@@ -77,7 +78,7 @@ class TestIndexManagementPlugin(AsyncOpenSearchTestCase):
self.assertNotIn("errors", response)
self.assertIn("_id", response)
async def test_get_policy(self):
async def test_get_policy(self) -> None:
# Create a policy
await self.test_create_policy()
@@ -88,7 +89,7 @@ class TestIndexManagementPlugin(AsyncOpenSearchTestCase):
self.assertIn("_id", response)
self.assertEqual(response["_id"], self.POLICY_NAME)
async def test_update_policy(self):
async def test_update_policy(self) -> None:
# Create a policy
await self.test_create_policy()
@@ -110,7 +111,7 @@ class TestIndexManagementPlugin(AsyncOpenSearchTestCase):
self.assertNotIn("errors", response)
self.assertIn("_id", response)
async def test_delete_policy(self):
async def test_delete_policy(self) -> None:
# Create a policy
await self.test_create_policy()
@@ -35,6 +35,7 @@ import inspect
import warnings
import pytest
from _pytest.mark.structures import MarkDecorator
from opensearchpy import OpenSearchWarning
from opensearchpy.helpers.test import _get_version
@@ -47,7 +48,7 @@ from ...test_server.test_rest_api_spec import (
YamlRunner,
)
pytestmark = pytest.mark.asyncio
pytestmark: MarkDecorator = pytest.mark.asyncio
OPENSEARCH_VERSION = None
@@ -77,7 +78,7 @@ class AsyncYamlRunner(YamlRunner):
if self._setup_code:
await self.run_code(self._setup_code)
async def teardown(self):
async def teardown(self) -> None:
if self._teardown_code:
self.section("teardown")
await self.run_code(self._teardown_code)
@@ -92,10 +93,10 @@ class AsyncYamlRunner(YamlRunner):
OPENSEARCH_VERSION = tuple(int(v) if v.isdigit() else 999 for v in version)
return OPENSEARCH_VERSION
def section(self, name):
def section(self, name) -> None:
print(("=" * 10) + " " + name + " " + ("=" * 10))
async def run(self):
async def run(self) -> None:
try:
await self.setup()
self.section("test")
@@ -106,7 +107,7 @@ class AsyncYamlRunner(YamlRunner):
except Exception:
pass
async def run_code(self, test):
async def run_code(self, test) -> None:
"""Execute an instruction based on its type."""
for action in test:
assert len(action) == 1
@@ -118,7 +119,7 @@ class AsyncYamlRunner(YamlRunner):
else:
raise RuntimeError("Invalid action type %r" % (action_type,))
async def run_do(self, action):
async def run_do(self, action) -> None:
api = self.client
headers = action.pop("headers", None)
catch = action.pop("catch", None)
@@ -184,7 +185,7 @@ class AsyncYamlRunner(YamlRunner):
% (warn, caught_warnings)
)
async def run_skip(self, skip):
async def run_skip(self, skip) -> None:
if "features" in skip:
features = skip["features"]
if not isinstance(features, (tuple, list)):
@@ -204,7 +205,7 @@ class AsyncYamlRunner(YamlRunner):
if min_version <= (await self.opensearch_version()) <= max_version:
pytest.skip(reason)
async def _feature_enabled(self, name):
async def _feature_enabled(self, name) -> bool:
return False
@@ -216,7 +217,7 @@ def async_runner(async_client):
if RUN_ASYNC_REST_API_TESTS:
@pytest.mark.parametrize("test_spec", YAML_TEST_SPECS)
async def test_rest_api_spec(test_spec, async_runner):
async def test_rest_api_spec(test_spec, async_runner) -> None:
if test_spec.get("skip", False):
pytest.skip("Manually skipped in 'SKIP_TESTS'")
async_runner.use_spec(test_spec)