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:
@@ -31,8 +31,6 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
from os import environ
|
||||
@@ -78,10 +76,10 @@ def fetch_opensearch_repo() -> None:
|
||||
|
||||
# no test directory
|
||||
if not exists(repo_path):
|
||||
subprocess.check_call("mkdir %s" % repo_path, shell=True)
|
||||
subprocess.check_call(f"mkdir {repo_path}", shell=True)
|
||||
|
||||
# make a new blank repository in the test directory
|
||||
subprocess.check_call("cd %s && git init" % repo_path, shell=True)
|
||||
subprocess.check_call(f"cd {repo_path} && git init", shell=True)
|
||||
|
||||
try:
|
||||
# add a remote
|
||||
@@ -104,7 +102,7 @@ def fetch_opensearch_repo() -> None:
|
||||
|
||||
# fetch the sha commit, version from info()
|
||||
print("Fetching opensearch repo...")
|
||||
subprocess.check_call("cd %s && git fetch origin %s" % (repo_path, sha), shell=True)
|
||||
subprocess.check_call(f"cd {repo_path} && git fetch origin {sha}", shell=True)
|
||||
|
||||
|
||||
def run_all(argv: Any = None) -> None:
|
||||
@@ -136,18 +134,18 @@ def run_all(argv: Any = None) -> None:
|
||||
argv = [
|
||||
"pytest",
|
||||
"--cov=opensearchpy",
|
||||
"--junitxml=%s" % junit_xml,
|
||||
f"--junitxml={junit_xml}",
|
||||
"--log-level=DEBUG",
|
||||
"--cache-clear",
|
||||
"-vv",
|
||||
"--cov-report=xml:%s" % codecov_xml,
|
||||
f"--cov-report=xml:{codecov_xml}",
|
||||
]
|
||||
if (
|
||||
"OPENSEARCHPY_GEN_HTML_COV" in environ
|
||||
and environ.get("OPENSEARCHPY_GEN_HTML_COV") == "true"
|
||||
):
|
||||
codecov_html = join(abspath(dirname(dirname(__file__))), "junit", "html")
|
||||
argv.append("--cov-report=html:%s" % codecov_html)
|
||||
argv.append(f"--cov-report=html:{codecov_html}")
|
||||
|
||||
secured = False
|
||||
if environ.get("OPENSEARCH_URL", "").startswith("https://"):
|
||||
@@ -156,7 +154,7 @@ def run_all(argv: Any = None) -> None:
|
||||
# check TEST_PATTERN env var for specific test to run
|
||||
test_pattern = environ.get("TEST_PATTERN")
|
||||
if test_pattern:
|
||||
argv.append("-k %s" % test_pattern)
|
||||
argv.append(f"-k {test_pattern}")
|
||||
else:
|
||||
ignores = [
|
||||
"test_opensearchpy/test_server/",
|
||||
@@ -196,7 +194,7 @@ def run_all(argv: Any = None) -> None:
|
||||
)
|
||||
|
||||
if ignores:
|
||||
argv.extend(["--ignore=%s" % ignore for ignore in ignores])
|
||||
argv.extend([f"--ignore={ignore}" for ignore in ignores])
|
||||
|
||||
# Not in CI, run all tests specified.
|
||||
else:
|
||||
|
||||
@@ -32,11 +32,11 @@ import ssl
|
||||
import warnings
|
||||
from platform import python_version
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import aiohttp
|
||||
import pytest
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
from mock import MagicMock, patch
|
||||
from multidict import CIMultiDict
|
||||
from pytest import raises
|
||||
|
||||
@@ -154,7 +154,7 @@ class TestAIOHttpConnection:
|
||||
|
||||
async def test_default_user_agent(self) -> None:
|
||||
con = AIOHttpConnection()
|
||||
assert con._get_default_user_agent() == "opensearch-py/%s (Python %s)" % (
|
||||
assert con._get_default_user_agent() == "opensearch-py/{} (Python {})".format(
|
||||
__versionstr__,
|
||||
python_version(),
|
||||
)
|
||||
@@ -342,7 +342,7 @@ class TestAIOHttpConnection:
|
||||
buf = b"\xe4\xbd\xa0\xe5\xa5\xbd\xed\xa9\xaa"
|
||||
con = await self._get_mock_connection(response_body=buf)
|
||||
_, _, data = await con.perform_request("GET", "/")
|
||||
assert u"你好\uda6a" == data # fmt: skip
|
||||
assert "你好\uda6a" == data # fmt: skip
|
||||
|
||||
@pytest.mark.parametrize("exception_cls", reraise_exceptions) # type: ignore
|
||||
async def test_recursion_error_reraised(self, exception_cls: Any) -> None:
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
|
||||
from typing import Any
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
from mock import Mock
|
||||
from pytest import fixture
|
||||
|
||||
from opensearchpy.connection.async_connections import add_connection, async_connections
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import codecs
|
||||
import ipaddress
|
||||
|
||||
@@ -73,7 +73,7 @@ async def test_cloned_index_has_analysis_attribute() -> None:
|
||||
client = object()
|
||||
i = AsyncIndex("my-index", using=client)
|
||||
|
||||
random_analyzer_name = "".join((choice(string.ascii_letters) for _ in range(100)))
|
||||
random_analyzer_name = "".join(choice(string.ascii_letters) for _ in range(100))
|
||||
random_analyzer = analyzer(
|
||||
random_analyzer_name, tokenizer="standard", filter="standard"
|
||||
)
|
||||
@@ -117,7 +117,7 @@ async def test_registered_doc_type_included_in_search() -> None:
|
||||
|
||||
|
||||
async def test_aliases_add_to_object() -> None:
|
||||
random_alias = "".join((choice(string.ascii_letters) for _ in range(100)))
|
||||
random_alias = "".join(choice(string.ascii_letters) for _ in range(100))
|
||||
alias_dict: Any = {random_alias: {}}
|
||||
|
||||
index = AsyncIndex("i", using="alias")
|
||||
@@ -127,7 +127,7 @@ async def test_aliases_add_to_object() -> None:
|
||||
|
||||
|
||||
async def test_aliases_returned_from_to_dict() -> None:
|
||||
random_alias = "".join((choice(string.ascii_letters) for _ in range(100)))
|
||||
random_alias = "".join(choice(string.ascii_letters) for _ in range(100))
|
||||
alias_dict: Any = {random_alias: {}}
|
||||
|
||||
index = AsyncIndex("i", using="alias")
|
||||
@@ -137,7 +137,7 @@ async def test_aliases_returned_from_to_dict() -> None:
|
||||
|
||||
|
||||
async def test_analyzers_added_to_object() -> None:
|
||||
random_analyzer_name = "".join((choice(string.ascii_letters) for _ in range(100)))
|
||||
random_analyzer_name = "".join(choice(string.ascii_letters) for _ in range(100))
|
||||
random_analyzer = analyzer(
|
||||
random_analyzer_name, tokenizer="standard", filter="standard"
|
||||
)
|
||||
@@ -153,7 +153,7 @@ async def test_analyzers_added_to_object() -> None:
|
||||
|
||||
|
||||
async def test_analyzers_returned_from_to_dict() -> None:
|
||||
random_analyzer_name = "".join((choice(string.ascii_letters) for _ in range(100)))
|
||||
random_analyzer_name = "".join(choice(string.ascii_letters) for _ in range(100))
|
||||
random_analyzer = analyzer(
|
||||
random_analyzer_name, tokenizer="standard", filter="standard"
|
||||
)
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
|
||||
|
||||
from typing import Any
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from multidict import CIMultiDict
|
||||
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
# GitHub history for details.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
from unittest import IsolatedAsyncioTestCase
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
# GitHub history for details.
|
||||
|
||||
import uuid
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
from mock import Mock
|
||||
|
||||
pytestmark: MarkDecorator = pytest.mark.asyncio
|
||||
|
||||
|
||||
@@ -25,15 +25,13 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
from mock import patch
|
||||
|
||||
from opensearchpy import AIOHttpConnection, AsyncTransport
|
||||
from opensearchpy.connection import Connection
|
||||
@@ -51,7 +49,7 @@ class DummyConnection(Connection):
|
||||
self.delay = kwargs.pop("delay", 0)
|
||||
self.calls: Any = []
|
||||
self.closed = False
|
||||
super(DummyConnection, self).__init__(**kwargs)
|
||||
super().__init__(**kwargs)
|
||||
|
||||
async def perform_request(self, *args: Any, **kwargs: Any) -> Any:
|
||||
if self.closed:
|
||||
@@ -253,7 +251,7 @@ class TestTransport:
|
||||
assert dt is t.connection_pool.dead_timeout
|
||||
|
||||
async def test_custom_connection_class(self) -> None:
|
||||
class MyConnection(object):
|
||||
class MyConnection:
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
self.kwargs = kwargs
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ from unittest import SkipTest, TestCase
|
||||
from opensearchpy import OpenSearch
|
||||
|
||||
|
||||
class DummyTransport(object):
|
||||
class DummyTransport:
|
||||
def __init__(
|
||||
self, hosts: Sequence[str], responses: Any = None, **kwargs: Any
|
||||
) -> None:
|
||||
@@ -59,7 +59,7 @@ class DummyTransport(object):
|
||||
|
||||
class OpenSearchTestCase(TestCase):
|
||||
def setUp(self) -> None:
|
||||
super(OpenSearchTestCase, self).setUp()
|
||||
super().setUp()
|
||||
self.client: Any = OpenSearch(transport_class=DummyTransport) # type: ignore
|
||||
|
||||
def assert_call_count_equals(self, count: int) -> None:
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import warnings
|
||||
|
||||
from opensearchpy.client import OpenSearch
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from typing import Any
|
||||
|
||||
from opensearchpy.client.utils import _bulk_body, _escape, _make_path, query_params
|
||||
|
||||
@@ -30,9 +30,9 @@ import re
|
||||
import uuid
|
||||
import warnings
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
from mock import MagicMock, Mock, patch
|
||||
from requests.auth import AuthBase
|
||||
|
||||
from opensearchpy.connection import Connection, RequestsHttpConnection
|
||||
@@ -258,7 +258,7 @@ class TestRequestsHttpConnection(TestCase):
|
||||
"GET",
|
||||
"/",
|
||||
{"param": 42},
|
||||
"{}".encode("utf-8"),
|
||||
b"{}",
|
||||
)
|
||||
|
||||
# trace request
|
||||
@@ -282,7 +282,7 @@ class TestRequestsHttpConnection(TestCase):
|
||||
"GET",
|
||||
"/",
|
||||
{"param": 42},
|
||||
"""{"question": "what's that?"}""".encode("utf-8"),
|
||||
b"""{"question": "what's that?"}""",
|
||||
)
|
||||
|
||||
# trace request
|
||||
@@ -397,7 +397,7 @@ class TestRequestsHttpConnection(TestCase):
|
||||
|
||||
self.assertEqual("http://localhost:9200/", request.url)
|
||||
self.assertEqual("GET", request.method)
|
||||
self.assertEqual('{"answer": 42}'.encode("utf-8"), request.body)
|
||||
self.assertEqual(b'{"answer": 42}', request.body)
|
||||
|
||||
def test_http_auth_attached(self) -> None:
|
||||
con = self._get_mock_connection({"http_auth": "username:secret"})
|
||||
@@ -414,7 +414,7 @@ class TestRequestsHttpConnection(TestCase):
|
||||
|
||||
self.assertEqual("http://localhost:9200/some-prefix/_search", request.url)
|
||||
self.assertEqual("GET", request.method)
|
||||
self.assertEqual('{"answer": 42}'.encode("utf-8"), request.body)
|
||||
self.assertEqual(b'{"answer": 42}', request.body)
|
||||
|
||||
# trace request
|
||||
trace_curl_cmd = (
|
||||
@@ -431,7 +431,7 @@ class TestRequestsHttpConnection(TestCase):
|
||||
buf = b"\xe4\xbd\xa0\xe5\xa5\xbd\xed\xa9\xaa"
|
||||
con = self._get_mock_connection(response_body=buf)
|
||||
_, _, data = con.perform_request("GET", "/")
|
||||
self.assertEqual(u"你好\uda6a", data) # fmt: skip
|
||||
self.assertEqual("你好\uda6a", data) # fmt: skip
|
||||
|
||||
def test_recursion_error_reraised(self) -> None:
|
||||
conn = RequestsHttpConnection()
|
||||
|
||||
@@ -32,10 +32,10 @@ from gzip import GzipFile
|
||||
from io import BytesIO
|
||||
from platform import python_version
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
import urllib3
|
||||
from mock import MagicMock, Mock, patch
|
||||
from urllib3._collections import HTTPHeaderDict
|
||||
|
||||
from opensearchpy import __versionstr__
|
||||
@@ -130,7 +130,7 @@ class TestUrllib3HttpConnection(TestCase):
|
||||
con = Urllib3HttpConnection()
|
||||
self.assertEqual(
|
||||
con._get_default_user_agent(),
|
||||
"opensearch-py/%s (Python %s)" % (__versionstr__, python_version()),
|
||||
f"opensearch-py/{__versionstr__} (Python {python_version()})",
|
||||
)
|
||||
|
||||
def test_timeout_set(self) -> None:
|
||||
@@ -385,7 +385,7 @@ class TestUrllib3HttpConnection(TestCase):
|
||||
buf = b"\xe4\xbd\xa0\xe5\xa5\xbd\xed\xa9\xaa"
|
||||
con = self._get_mock_connection(response_body=buf)
|
||||
_, _, data = con.perform_request("GET", "/")
|
||||
self.assertEqual(u"你好\uda6a", data) # fmt: skip
|
||||
self.assertEqual("你好\uda6a", data) # fmt: skip
|
||||
|
||||
def test_recursion_error_reraised(self) -> None:
|
||||
conn = Urllib3HttpConnection()
|
||||
|
||||
@@ -68,9 +68,7 @@ class TestConnectionPool(TestCase):
|
||||
def test_selectors_have_access_to_connection_opts(self) -> None:
|
||||
class MySelector(RoundRobinSelector):
|
||||
def select(self, connections: Any) -> Any:
|
||||
return self.connection_opts[
|
||||
super(MySelector, self).select(connections)
|
||||
]["actual"]
|
||||
return self.connection_opts[super().select(connections)]["actual"]
|
||||
|
||||
pool = ConnectionPool(
|
||||
[(x, {"actual": x * x}) for x in range(100)],
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
|
||||
|
||||
from typing import Any
|
||||
from unittest.mock import Mock
|
||||
|
||||
from mock import Mock
|
||||
from pytest import fixture
|
||||
|
||||
from opensearchpy.connection.connections import add_connection, connections
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
import threading
|
||||
import time
|
||||
from typing import Any
|
||||
from unittest import mock
|
||||
from unittest.mock import Mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from opensearchpy import OpenSearch, helpers
|
||||
@@ -131,7 +131,7 @@ class TestParallelBulk(TestCase):
|
||||
results = list(
|
||||
helpers.parallel_bulk(OpenSearch(), actions, thread_count=10, chunk_size=2)
|
||||
)
|
||||
self.assertTrue(len(set([r[1] for r in results])) > 1)
|
||||
self.assertTrue(len({r[1] for r in results}) > 1)
|
||||
|
||||
|
||||
class TestChunkActions(TestCase):
|
||||
@@ -266,7 +266,7 @@ class TestChunkActions(TestCase):
|
||||
)
|
||||
self.assertEqual(25, len(chunks))
|
||||
for _, chunk_actions in chunks:
|
||||
chunk = u"".join(chunk_actions) # fmt: skip
|
||||
chunk = "".join(chunk_actions) # fmt: skip
|
||||
chunk = chunk if isinstance(chunk, str) else chunk.encode("utf-8")
|
||||
self.assertLessEqual(len(chunk), max_byte_size)
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import codecs
|
||||
import ipaddress
|
||||
|
||||
@@ -84,7 +84,7 @@ def test_cloned_index_has_analysis_attribute() -> None:
|
||||
client = object()
|
||||
i: Any = Index("my-index", using=client)
|
||||
|
||||
random_analyzer_name = "".join((choice(string.ascii_letters) for _ in range(100)))
|
||||
random_analyzer_name = "".join(choice(string.ascii_letters) for _ in range(100))
|
||||
random_analyzer = analyzer(
|
||||
random_analyzer_name, tokenizer="standard", filter="standard"
|
||||
)
|
||||
@@ -128,7 +128,7 @@ def test_registered_doc_type_included_in_search() -> None:
|
||||
|
||||
|
||||
def test_aliases_add_to_object() -> None:
|
||||
random_alias = "".join((choice(string.ascii_letters) for _ in range(100)))
|
||||
random_alias = "".join(choice(string.ascii_letters) for _ in range(100))
|
||||
alias_dict: Any = {random_alias: {}}
|
||||
|
||||
index: Any = Index("i", using="alias")
|
||||
@@ -138,7 +138,7 @@ def test_aliases_add_to_object() -> None:
|
||||
|
||||
|
||||
def test_aliases_returned_from_to_dict() -> None:
|
||||
random_alias = "".join((choice(string.ascii_letters) for _ in range(100)))
|
||||
random_alias = "".join(choice(string.ascii_letters) for _ in range(100))
|
||||
alias_dict: Any = {random_alias: {}}
|
||||
|
||||
index: Any = Index("i", using="alias")
|
||||
@@ -148,7 +148,7 @@ def test_aliases_returned_from_to_dict() -> None:
|
||||
|
||||
|
||||
def test_analyzers_added_to_object() -> None:
|
||||
random_analyzer_name = "".join((choice(string.ascii_letters) for _ in range(100)))
|
||||
random_analyzer_name = "".join(choice(string.ascii_letters) for _ in range(100))
|
||||
random_analyzer = analyzer(
|
||||
random_analyzer_name, tokenizer="standard", filter="standard"
|
||||
)
|
||||
@@ -164,7 +164,7 @@ def test_analyzers_added_to_object() -> None:
|
||||
|
||||
|
||||
def test_analyzers_returned_from_to_dict() -> None:
|
||||
random_analyzer_name = "".join((choice(string.ascii_letters) for _ in range(100)))
|
||||
random_analyzer_name = "".join(choice(string.ascii_letters) for _ in range(100))
|
||||
random_analyzer = analyzer(
|
||||
random_analyzer_name, tokenizer="standard", filter="standard"
|
||||
)
|
||||
|
||||
@@ -95,7 +95,7 @@ def test_interactive_helpers(dummy_response: Any) -> None:
|
||||
)
|
||||
|
||||
assert res
|
||||
assert "<Response: %s>" % rhits == repr(res)
|
||||
assert f"<Response: {rhits}>" == repr(res)
|
||||
assert rhits == repr(hits)
|
||||
assert {"meta", "city", "name"} == set(dir(h))
|
||||
assert "<Hit(test-index/opensearch): %r>" % dummy_response["hits"]["hits"][0][
|
||||
|
||||
@@ -99,7 +99,7 @@ def test_serializer_deals_with_attr_versions() -> None:
|
||||
|
||||
|
||||
def test_serializer_deals_with_objects_with_to_dict() -> None:
|
||||
class MyClass(object):
|
||||
class MyClass:
|
||||
def to_dict(self) -> int:
|
||||
return 42
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class AutoNowDate(Date):
|
||||
def clean(self, data: Any) -> Any:
|
||||
if data is None:
|
||||
data = datetime.now()
|
||||
return super(AutoNowDate, self).clean(data)
|
||||
return super().clean(data)
|
||||
|
||||
|
||||
class Log(Document):
|
||||
|
||||
@@ -74,7 +74,7 @@ def sync_client_factory() -> Any:
|
||||
except ConnectionError:
|
||||
time.sleep(0.1)
|
||||
else:
|
||||
pytest.skip("OpenSearch wasn't running at %r" % (OPENSEARCH_URL,))
|
||||
pytest.skip(f"OpenSearch wasn't running at {OPENSEARCH_URL!r}")
|
||||
|
||||
wipe_cluster(client)
|
||||
yield client
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from . import OpenSearchTestCase
|
||||
|
||||
|
||||
|
||||
@@ -26,8 +26,7 @@
|
||||
|
||||
|
||||
from typing import Any
|
||||
|
||||
from mock import patch
|
||||
from unittest.mock import patch
|
||||
|
||||
from opensearchpy import TransportError, helpers
|
||||
from opensearchpy.helpers import ScanError
|
||||
@@ -36,7 +35,7 @@ from ...test_cases import SkipTest
|
||||
from .. import OpenSearchTestCase
|
||||
|
||||
|
||||
class FailingBulkClient(object):
|
||||
class FailingBulkClient:
|
||||
def __init__(
|
||||
self,
|
||||
client: Any,
|
||||
@@ -383,7 +382,7 @@ class TestScan(OpenSearchTestCase):
|
||||
|
||||
def teardown_method(self, m: Any) -> None:
|
||||
self.client.transport.perform_request("DELETE", "/_search/scroll/_all")
|
||||
super(TestScan, self).teardown_method(m)
|
||||
super().teardown_method(m)
|
||||
|
||||
def test_order_can_be_preserved(self) -> None:
|
||||
bulk: Any = []
|
||||
@@ -415,8 +414,8 @@ class TestScan(OpenSearchTestCase):
|
||||
docs = list(helpers.scan(self.client, index="test_index", size=2))
|
||||
|
||||
self.assertEqual(100, len(docs))
|
||||
self.assertEqual(set(map(str, range(100))), set(d["_id"] for d in docs))
|
||||
self.assertEqual(set(range(100)), set(d["_source"]["answer"] for d in docs))
|
||||
self.assertEqual(set(map(str, range(100))), {d["_id"] for d in docs})
|
||||
self.assertEqual(set(range(100)), {d["_source"]["answer"] for d in docs})
|
||||
|
||||
def test_scroll_error(self) -> None:
|
||||
bulk: Any = []
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ class Repository(Document):
|
||||
|
||||
@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"
|
||||
|
||||
@@ -106,7 +106,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
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from typing import Any
|
||||
|
||||
@@ -52,7 +51,7 @@ class Repository(Document):
|
||||
|
||||
@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"
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import time
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
# GitHub history for details.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import unittest
|
||||
|
||||
from opensearchpy.helpers.test import OPENSEARCH_VERSION
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
# GitHub history for details.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from opensearchpy.exceptions import NotFoundError
|
||||
|
||||
from .. import OpenSearchTestCase
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
# GitHub history for details.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import unittest
|
||||
from typing import Any, Dict
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ class YamlRunner:
|
||||
if hasattr(self, "run_" + action_type):
|
||||
getattr(self, "run_" + action_type)(action)
|
||||
else:
|
||||
raise RuntimeError("Invalid action type %r" % (action_type,))
|
||||
raise RuntimeError(f"Invalid action type {action_type!r}")
|
||||
|
||||
def run_do(self, action: Any) -> Any:
|
||||
api = self.client
|
||||
@@ -218,7 +218,7 @@ class 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.
|
||||
@@ -248,7 +248,7 @@ class YamlRunner:
|
||||
elif catch[0] == "/" and catch[-1] == "/":
|
||||
assert (
|
||||
re.search(catch[1:-1], exception.error + " " + repr(exception.info)),
|
||||
"%s not in %r" % (catch, exception.info),
|
||||
f"{catch} not in {exception.info!r}",
|
||||
) is not None
|
||||
self.last_response = exception.info
|
||||
|
||||
@@ -262,7 +262,7 @@ class 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"]
|
||||
@@ -328,10 +328,7 @@ class YamlRunner:
|
||||
and expected.strip().endswith("/")
|
||||
):
|
||||
expected = re.compile(expected.strip()[1:-1], re.VERBOSE | re.MULTILINE)
|
||||
assert expected.search(value), "%r does not match %r" % (
|
||||
value,
|
||||
expected,
|
||||
)
|
||||
assert expected.search(value), f"{value!r} does not match {expected!r}"
|
||||
else:
|
||||
self._assert_match_equals(value, expected)
|
||||
|
||||
@@ -341,7 +338,7 @@ class YamlRunner:
|
||||
expected = self._resolve(expected) # dict[str, str]
|
||||
|
||||
if expected not in value:
|
||||
raise AssertionError("%s is not contained by %s" % (expected, value))
|
||||
raise AssertionError(f"{expected} is not contained by {value}")
|
||||
|
||||
def run_transform_and_set(self, action: Any) -> None:
|
||||
for key, value in action.items():
|
||||
@@ -371,7 +368,7 @@ class YamlRunner:
|
||||
break
|
||||
|
||||
if isinstance(value, dict):
|
||||
value = dict((k, self._resolve(v)) for (k, v) in value.items())
|
||||
value = {k: self._resolve(v) for (k, v) in value.items()}
|
||||
elif isinstance(value, list):
|
||||
value = list(map(self._resolve, value))
|
||||
return value
|
||||
@@ -412,7 +409,7 @@ class YamlRunner:
|
||||
if isinstance(b, string_types) and isinstance(a, float) and "e" in repr(a):
|
||||
a = repr(a).replace("e+", "E")
|
||||
|
||||
assert a == b, "%r does not match %r" % (a, b)
|
||||
assert a == b, f"{a!r} does not match {b!r}"
|
||||
|
||||
|
||||
@pytest.fixture(scope="function") # type: ignore
|
||||
@@ -473,7 +470,7 @@ def load_rest_api_tests() -> None:
|
||||
for prefix in ("rest-api-spec/", "test/", "oss/"):
|
||||
if pytest_test_name.startswith(prefix):
|
||||
pytest_test_name = pytest_test_name[len(prefix) :]
|
||||
pytest_param_id = "%s[%d]" % (pytest_test_name, test_number)
|
||||
pytest_param_id = f"{pytest_test_name}[{test_number}]"
|
||||
|
||||
pytest_param = {
|
||||
"setup": setup_steps,
|
||||
@@ -487,7 +484,7 @@ def load_rest_api_tests() -> None:
|
||||
YAML_TEST_SPECS.append(pytest.param(pytest_param, id=pytest_param_id))
|
||||
|
||||
except Exception as e:
|
||||
warnings.warn("Could not load REST API tests: %s" % (str(e),))
|
||||
warnings.warn(f"Could not load REST API tests: {str(e)}")
|
||||
|
||||
|
||||
load_rest_api_tests()
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
# GitHub history for details.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
from unittest import TestCase
|
||||
|
||||
|
||||
@@ -25,13 +25,10 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
from mock import patch
|
||||
from unittest.mock import patch
|
||||
|
||||
from opensearchpy.connection import Connection
|
||||
from opensearchpy.connection_pool import DummyConnectionPool
|
||||
@@ -47,7 +44,7 @@ class DummyConnection(Connection):
|
||||
self.status, self.data = kwargs.pop("status", 200), kwargs.pop("data", "{}")
|
||||
self.headers = kwargs.pop("headers", {})
|
||||
self.calls: Any = []
|
||||
super(DummyConnection, self).__init__(**kwargs)
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def perform_request(self, *args: Any, **kwargs: Any) -> Any:
|
||||
self.calls.append((args, kwargs))
|
||||
|
||||
Reference in New Issue
Block a user