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:
Hugo van Kemenade
2024-07-20 16:19:20 -04:00
committed by GitHub
parent de96d28e45
commit 6e3f1a1194
95 changed files with 229 additions and 300 deletions
+1 -1
View File
@@ -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()