From 107469c6205df592fd3049c497a3489067833d15 Mon Sep 17 00:00:00 2001 From: Mark Cohen Date: Thu, 18 Jan 2024 20:56:31 +0000 Subject: [PATCH] updated TODOs as requested renamed test_opensearchpy.test_async.test_server.test_helpers.conftest.setup_ubq_tests to setup_update_by_query_tests added OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/stats/50_noop_update[0] to skip tests list run_tests.py catches a CalledProcessError when the git repo already exists and the command to add the origin fails in fetch_opensearch_repo() Signed-off-by: Mark Cohen --- opensearchpy/compat.py | 8 +++---- test_opensearchpy/run_tests.py | 21 +++++++++++++------ .../test_server/test_helpers/conftest.py | 4 ++-- .../test_server/test_helpers/test_actions.py | 2 +- .../test_helpers/test_faceted_search.py | 2 +- .../test_helpers/test_update_by_query.py | 12 +++++------ .../test_server/test_rest_api_spec.py | 21 ++++++++++--------- utils/generate_api.py | 2 +- 8 files changed, 41 insertions(+), 31 deletions(-) diff --git a/opensearchpy/compat.py b/opensearchpy/compat.py index 72355bb9..1bf6df94 100644 --- a/opensearchpy/compat.py +++ b/opensearchpy/compat.py @@ -36,10 +36,10 @@ def to_str(x: Union[str, bytes], encoding: str = "ascii") -> str: """ - - :param y: - :param encoding: - :return: + returns x as a string encoded in "encoding" if it is not already a string + :param x: the value to convert to a str + :param encoding: the encoding to convert to - see https://docs.python.org/3/library/codecs.html#standard-encodings + :return: an encoded str """ if not isinstance(x, str): return x.decode(encoding) diff --git a/test_opensearchpy/run_tests.py b/test_opensearchpy/run_tests.py index b54218a0..2aa94a76 100755 --- a/test_opensearchpy/run_tests.py +++ b/test_opensearchpy/run_tests.py @@ -37,6 +37,7 @@ import sys from os import environ from os.path import abspath, dirname, exists, join, pardir +from subprocess import CalledProcessError from typing import Any @@ -82,12 +83,20 @@ def fetch_opensearch_repo() -> None: # make a new blank repository in the test directory subprocess.check_call("cd %s && git init" % repo_path, shell=True) - # add a remote - subprocess.check_call( - "cd %s && git remote add origin https://github.com/opensearch-project/opensearch.git" - % repo_path, - shell=True, - ) # TODO this fails when the remote already exists; should clean up or ignore? + try: + # add a remote + subprocess.check_call( + "cd %s && git remote add origin https://github.com/opensearch-project/opensearch.git" + % repo_path, + shell=True, + ) + except CalledProcessError as e: + # if the run is interrupted from a previous run, it doesn't clean up, and the git add origin command + # errors out; this allows the test to continue + remote_origin_already_exists = 3 + print(e) + if e.returncode != remote_origin_already_exists: + sys.exit(1) # fetch the sha commit, version from info() print("Fetching opensearch repo...") diff --git a/test_opensearchpy/test_async/test_server/test_helpers/conftest.py b/test_opensearchpy/test_async/test_server/test_helpers/conftest.py index 172a6a39..983ae711 100644 --- a/test_opensearchpy/test_async/test_server/test_helpers/conftest.py +++ b/test_opensearchpy/test_async/test_server/test_helpers/conftest.py @@ -115,9 +115,9 @@ async def pull_request(write_client: Any) -> Any: @fixture # type: ignore -async def setup_ubq_tests(client: Any) -> str: +async def setup_update_by_query_tests(client: Any) -> str: """ - #todo what's a ubq test? this is ignored. should it be deleted? + sets up update by query tests :param client: :return: an index name """ diff --git a/test_opensearchpy/test_async/test_server/test_helpers/test_actions.py b/test_opensearchpy/test_async/test_server/test_helpers/test_actions.py index c1a5dc7a..29fbb5a3 100644 --- a/test_opensearchpy/test_async/test_server/test_helpers/test_actions.py +++ b/test_opensearchpy/test_async/test_server/test_helpers/test_actions.py @@ -61,7 +61,7 @@ def __init__( async def bulk(self, *args: Any, **kwargs: Any) -> Any: """ - increments number of times called and, when it equals fail_at, raises self.fail_with when + increments number of times called and, when it equals fail_at, raises self.fail_with """ self._called += 1 if self._called in self._fail_at: diff --git a/test_opensearchpy/test_async/test_server/test_helpers/test_faceted_search.py b/test_opensearchpy/test_async/test_server/test_helpers/test_faceted_search.py index 49685e32..90899d62 100644 --- a/test_opensearchpy/test_async/test_server/test_helpers/test_faceted_search.py +++ b/test_opensearchpy/test_async/test_server/test_helpers/test_faceted_search.py @@ -57,7 +57,7 @@ class MetricSearch(AsyncFacetedSearch): @pytest.fixture(scope="function") # type: ignore def commit_search_cls(opensearch_version: Any) -> Any: """ - :param opensearch_version: not used. #todo should be removed? + :param opensearch_version the semver version of OpenSearch :return: an AsyncFacetedSearch for git commits """ interval_kwargs = {"fixed_interval": "1d"} diff --git a/test_opensearchpy/test_async/test_server/test_helpers/test_update_by_query.py b/test_opensearchpy/test_async/test_server/test_helpers/test_update_by_query.py index a26d046e..9301e3e6 100644 --- a/test_opensearchpy/test_async/test_server/test_helpers/test_update_by_query.py +++ b/test_opensearchpy/test_async/test_server/test_helpers/test_update_by_query.py @@ -19,9 +19,9 @@ async def test_update_by_query_no_script( - write_client: Any, setup_ubq_tests: Any + write_client: Any, setup_update_by_query_tests: Any ) -> None: - index = setup_ubq_tests + index = setup_update_by_query_tests ubq = ( AsyncUpdateByQuery(using=write_client) @@ -40,9 +40,9 @@ async def test_update_by_query_no_script( async def test_update_by_query_with_script( - write_client: Any, setup_ubq_tests: Any + write_client: Any, setup_update_by_query_tests: Any ) -> None: - index = setup_ubq_tests + index = setup_update_by_query_tests ubq = ( AsyncUpdateByQuery(using=write_client) @@ -59,9 +59,9 @@ async def test_update_by_query_with_script( async def test_delete_by_query_with_script( - write_client: Any, setup_ubq_tests: Any + write_client: Any, setup_update_by_query_tests: Any ) -> None: - index = setup_ubq_tests + index = setup_update_by_query_tests ubq = ( AsyncUpdateByQuery(using=write_client) diff --git a/test_opensearchpy/test_server/test_rest_api_spec.py b/test_opensearchpy/test_server/test_rest_api_spec.py index cb03cb76..8f965501 100644 --- a/test_opensearchpy/test_server/test_rest_api_spec.py +++ b/test_opensearchpy/test_server/test_rest_api_spec.py @@ -74,21 +74,22 @@ # Warning about date_histogram.interval deprecation is raised randomly "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/search_pipeline/10_basic", "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/pit/10_basic", - "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/clone/40_wait_for_completion[0]", # pylint: disable=line-too-long - "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/forcemerge/20_wait_for_completion[0]", # pylint: disable=line-too-long - "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/open/30_wait_for_completion[0]", # pylint: disable=line-too-long - "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/shrink/50_wait_for_completion[0]", # pylint: disable=line-too-long - "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/split/40_wait_for_completion[0]", # pylint: disable=line-too-long + "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/clone/40_wait_for_completion[0]", + "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/forcemerge/20_wait_for_completion[0]", + "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/open/30_wait_for_completion[0]", + "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/shrink/50_wait_for_completion[0]", + "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/split/40_wait_for_completion[0]", "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cat/nodes/10_basic[1]", "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cat/nodeattrs/10_basic[1]", - "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cluster/put_settings/10_basic[2]", # pylint: disable=line-too-long - "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cluster/put_settings/10_basic[3]", # pylint: disable=line-too-long + "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cluster/put_settings/10_basic[2]", + "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cluster/put_settings/10_basic[3]", "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cat/indices/10_basic[2]", - "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cluster/health/10_basic[6]", # pylint: disable=line-too-long - "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cluster/health/20_request_timeout", # pylint: disable=line-too-long - "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/search/aggregation/20_terms[4]", # pylint: disable=line-too-long + "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cluster/health/10_basic[6]", + "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cluster/health/20_request_timeout", + "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/search/aggregation/20_terms[4]", "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/tasks/list/10_basic[0]", "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/index/90_unsigned_long[1]", + "OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/stats/50_noop_update[0]", "search/aggregation/250_moving_fn[1]", # body: null "indices/simulate_index_template/10_basic[2]", diff --git a/utils/generate_api.py b/utils/generate_api.py index 86868f65..b10a9056 100644 --- a/utils/generate_api.py +++ b/utils/generate_api.py @@ -418,7 +418,7 @@ def method(self) -> Any: """ To adhere to the HTTP RFC we shouldn't send bodies in GET requests. - :return: + :return: an updated HTTP method to use to communicate with the OpenSearch API """ default_method = self.path["methods"][0]