Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
- remove unused iter/aiter in unasync conversion table
- improve contributing documentation wrt _async subdirectories
- remove some code duplication in async test fixtures
  • Loading branch information
miguelgrinberg committed Mar 27, 2024
1 parent 8b5fa41 commit 5cfffac
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 37 deletions.
7 changes: 4 additions & 3 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ The process for contributing to any of the Elasticsearch repositories is similar

2. Many classes included in this library are offered in two versions, for
asynchronous and synchronous Python. When working with these classes, you only
need to make changes to the asynchronous code, located in the *_async*
subdirectory of the source tree. Once you've made your changes, run the
following command to automatically generate the corresponding synchronous code:
need to make changes to the asynchronous code, located in *_async*
subdirectories in the source and tests trees. Once you've made your changes,
run the following command to automatically generate the corresponding
synchronous code:

.. code:: bash
Expand Down
44 changes: 12 additions & 32 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,8 @@ def write_client(client):


@pytest_asyncio.fixture
async def async_write_client(async_client):
async def async_write_client(write_client, async_client):
yield async_client
for index_name in await async_client.indices.get(
index="test-*", expand_wildcards="all"
):
await async_client.indices.delete(index=index_name)
await async_client.options(ignore_status=404).indices.delete_template(
name="test-template"
)


@fixture
Expand Down Expand Up @@ -443,18 +436,16 @@ def aggs_data():
}


@fixture
def pull_request(write_client):
sync_document.PullRequest.init()
pr = sync_document.PullRequest(
def make_pr(pr_module):
return pr_module.PullRequest(
_id=42,
comments=[
sync_document.Comment(
pr_module.Comment(
content="Hello World!",
author=sync_document.User(name="honzakral"),
author=pr_module.User(name="honzakral"),
created_at=datetime(2018, 1, 9, 10, 17, 3, 21184),
history=[
sync_document.History(
pr_module.History(
timestamp=datetime(2012, 1, 1),
diff="-Ahoj Svete!\n+Hello World!",
)
Expand All @@ -463,30 +454,19 @@ def pull_request(write_client):
],
created_at=datetime(2018, 1, 9, 9, 17, 3, 21184),
)

@fixture
def pull_request(write_client):
sync_document.PullRequest.init()
pr = make_pr(sync_document)
pr.save(refresh=True)
return pr


@pytest_asyncio.fixture
async def async_pull_request(async_write_client):
await async_document.PullRequest.init()
pr = async_document.PullRequest(
_id=42,
comments=[
async_document.Comment(
content="Hello World!",
author=async_document.User(name="honzakral"),
created_at=datetime(2018, 1, 9, 10, 17, 3, 21184),
history=[
async_document.History(
timestamp=datetime(2012, 1, 1),
diff="-Ahoj Svete!\n+Hello World!",
)
],
),
],
created_at=datetime(2018, 1, 9, 9, 17, 3, 21184),
)
pr = make_pr(async_document)
await pr.save(refresh=True)
return pr

Expand Down
2 changes: 0 additions & 2 deletions utils/run-unasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ def main(check=False):
# Unasync all the generated async code
additional_replacements = {
"_async": "_sync",
"aiter": "iter",
"anext": "next",
"AsyncElasticsearch": "Elasticsearch",
"AsyncSearch": "Search",
"AsyncMultiSearch": "MultiSearch",
Expand Down

0 comments on commit 5cfffac

Please sign in to comment.