Remove redundant mock backport dependency and upgrade syntax for Python 3.8+ (#785)
* Upgrade syntax with pyupgrade --py38-plus Signed-off-by: Hugo van Kemenade <[email protected]> * Convert to f-strings with flynt Signed-off-by: Hugo van Kemenade <[email protected]> * Format with Black Signed-off-by: Hugo van Kemenade <[email protected]> * Remove redundant mock backport dependency Signed-off-by: Hugo van Kemenade <[email protected]> * isort imports Signed-off-by: Hugo van Kemenade <[email protected]> * Add changelog entry Signed-off-by: Hugo van Kemenade <[email protected]> --------- Signed-off-by: Hugo van Kemenade <[email protected]>
This commit is contained in:
@@ -25,8 +25,6 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
|
||||
import asyncio
|
||||
from typing import Any, List
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from mock import MagicMock, patch
|
||||
|
||||
from opensearchpy import TransportError
|
||||
from opensearchpy._async.helpers import actions
|
||||
@@ -40,13 +40,13 @@ pytestmark = pytest.mark.asyncio
|
||||
|
||||
class AsyncMock(MagicMock):
|
||||
async def __call__(self, *args: Any, **kwargs: Any) -> Any:
|
||||
return super(AsyncMock, self).__call__(*args, **kwargs)
|
||||
return super().__call__(*args, **kwargs)
|
||||
|
||||
def __await__(self) -> Any:
|
||||
return self().__await__()
|
||||
|
||||
|
||||
class FailingBulkClient(object):
|
||||
class FailingBulkClient:
|
||||
def __init__(
|
||||
self,
|
||||
client: Any,
|
||||
@@ -69,7 +69,7 @@ class FailingBulkClient(object):
|
||||
return await self.client.bulk(*args, **kwargs)
|
||||
|
||||
|
||||
class TestStreamingBulk(object):
|
||||
class TestStreamingBulk:
|
||||
async def test_actions_remain_unchanged(self, async_client: Any) -> None:
|
||||
actions1 = [{"_id": 1}, {"_id": 2}]
|
||||
async for ok, _ in actions.async_streaming_bulk(
|
||||
@@ -281,7 +281,7 @@ class TestStreamingBulk(object):
|
||||
assert 4 == failing_client._called
|
||||
|
||||
|
||||
class TestBulk(object):
|
||||
class TestBulk:
|
||||
async def test_bulk_works_with_single_item(self, async_client: Any) -> None:
|
||||
docs = [{"answer": 42, "_id": 1}]
|
||||
success, failed = await actions.async_bulk(
|
||||
@@ -453,7 +453,7 @@ async def scan_teardown(async_client: Any) -> Any:
|
||||
await async_client.clear_scroll(scroll_id="_all")
|
||||
|
||||
|
||||
class TestScan(object):
|
||||
class TestScan:
|
||||
async def test_order_can_be_preserved(
|
||||
self, async_client: Any, scan_teardown: Any
|
||||
) -> None:
|
||||
@@ -492,8 +492,8 @@ class TestScan(object):
|
||||
]
|
||||
|
||||
assert 100 == len(docs)
|
||||
assert set(map(str, range(100))) == set(d["_id"] for d in docs)
|
||||
assert set(range(100)) == set(d["_source"]["answer"] for d in docs)
|
||||
assert set(map(str, range(100))) == {d["_id"] for d in docs}
|
||||
assert set(range(100)) == {d["_source"]["answer"] for d in docs}
|
||||
|
||||
async def test_scroll_error(self, async_client: Any, scan_teardown: Any) -> None:
|
||||
bulk: Any = []
|
||||
@@ -824,7 +824,7 @@ async def reindex_setup(async_client: Any) -> Any:
|
||||
yield
|
||||
|
||||
|
||||
class TestReindex(object):
|
||||
class TestReindex:
|
||||
async def test_reindex_passes_kwargs_to_scan_and_bulk(
|
||||
self, async_client: Any, reindex_setup: Any
|
||||
) -> None:
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ class Repository(AsyncDocument):
|
||||
|
||||
@classmethod
|
||||
def search(cls, using: Any = None, index: Optional[str] = None) -> Any:
|
||||
return super(Repository, cls).search().filter("term", commit_repo="repo")
|
||||
return super().search().filter("term", commit_repo="repo")
|
||||
|
||||
class Index:
|
||||
name = "git"
|
||||
|
||||
@@ -98,7 +98,7 @@ def repo_search_cls(opensearch_version: Any) -> Any:
|
||||
}
|
||||
|
||||
def search(self) -> Any:
|
||||
s = super(RepoSearch, self).search()
|
||||
s = super().search()
|
||||
return s.filter("term", commit_repo="repo")
|
||||
|
||||
return RepoSearch
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from typing import Any
|
||||
|
||||
@@ -31,7 +30,7 @@ class Repository(AsyncDocument):
|
||||
|
||||
@classmethod
|
||||
def search(cls, using: Any = None, index: Any = None) -> Any:
|
||||
return super(Repository, cls).search().filter("term", commit_repo="repo")
|
||||
return super().search().filter("term", commit_repo="repo")
|
||||
|
||||
class Index:
|
||||
name = "git"
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
# GitHub history for details.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
# GitHub history for details.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ class AsyncYamlRunner(YamlRunner):
|
||||
if hasattr(self, "run_" + action_type):
|
||||
await await_if_coro(getattr(self, "run_" + action_type)(action))
|
||||
else:
|
||||
raise RuntimeError("Invalid action type %r" % (action_type,))
|
||||
raise RuntimeError(f"Invalid action type {action_type!r}")
|
||||
|
||||
async def run_do(self, action: Any) -> Any:
|
||||
api = self.client
|
||||
@@ -170,7 +170,7 @@ class AsyncYamlRunner(YamlRunner):
|
||||
else:
|
||||
if catch:
|
||||
raise AssertionError(
|
||||
"Failed to catch %r in %r." % (catch, self.last_response)
|
||||
f"Failed to catch {catch!r} in {self.last_response!r}."
|
||||
)
|
||||
|
||||
# Filter out warnings raised by other components.
|
||||
@@ -197,7 +197,7 @@ class AsyncYamlRunner(YamlRunner):
|
||||
for feature in features:
|
||||
if feature in IMPLEMENTED_FEATURES:
|
||||
continue
|
||||
pytest.skip("feature '%s' is not supported" % feature)
|
||||
pytest.skip(f"feature '{feature}' is not supported")
|
||||
|
||||
if "version" in skip:
|
||||
version, reason = skip["version"], skip["reason"]
|
||||
|
||||
Reference in New Issue
Block a user