Skip to content

Commit

Permalink
updated TODOs as requested
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
macohen committed Jan 19, 2024
1 parent ffa80b3 commit 107469c
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 31 deletions.
8 changes: 4 additions & 4 deletions opensearchpy/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 15 additions & 6 deletions test_opensearchpy/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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...")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
21 changes: 11 additions & 10 deletions test_opensearchpy/test_server/test_rest_api_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand Down
2 changes: 1 addition & 1 deletion utils/generate_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 107469c

Please sign in to comment.