Skip to content

Commit 7386dd5

Browse files
restore sync examples unasynced by mistake
1 parent 38cd862 commit 7386dd5

28 files changed

+24
-73
lines changed

Diff for: examples/alias_migration.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
will have index set to the concrete index whereas the class refers to the
3636
alias.
3737
"""
38-
import asyncio
38+
import os
3939
from datetime import datetime
4040
from fnmatch import fnmatch
4141

@@ -125,9 +125,9 @@ def migrate(move_data=True, update_alias=True):
125125
)
126126

127127

128-
def main():
128+
if __name__ == "__main__":
129129
# initiate the default connection to elasticsearch
130-
connections.create_connection(hosts=["http://localhost:9200"])
130+
connections.create_connection(hosts=[os.environ["ELASTICSEARCH_URL"]])
131131

132132
# create the empty index
133133
setup()
@@ -143,10 +143,3 @@ def main():
143143

144144
# create new index
145145
migrate()
146-
147-
# close the connection
148-
connections.get_connection().close()
149-
150-
151-
if __name__ == "__main__":
152-
asyncio.run(main())

Diff for: examples/completion.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
that does ascii folding.
2727
"""
2828

29-
import asyncio
3029
import os
3130
from itertools import permutations
3231

@@ -73,7 +72,7 @@ class Index:
7372
settings = {"number_of_shards": 1, "number_of_replicas": 0}
7473

7574

76-
def main():
75+
if __name__ == "__main__":
7776
# initiate the default connection to elasticsearch
7877
connections.create_connection(hosts=[os.environ["ELASTICSEARCH_URL"]])
7978

@@ -98,10 +97,3 @@ def main():
9897
# print out all the options we got
9998
for option in response.suggest.auto_complete[0].options:
10099
print("%10s: %25s (%d)" % (text, option._source.name, option._score))
101-
102-
# close the connection
103-
connections.get_connection().close()
104-
105-
106-
if __name__ == "__main__":
107-
asyncio.run(main())

Diff for: examples/composite_agg.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
import asyncio
1918
import os
2019

2120
from elasticsearch_dsl import A, Search, connections
@@ -37,16 +36,15 @@ def run_search(**kwargs):
3736

3837
response = run_search()
3938
while response.aggregations.comp.buckets:
40-
for b in response.aggregations.comp.buckets:
41-
yield b
39+
yield from response.aggregations.comp.buckets
4240
if "after_key" in response.aggregations.comp:
4341
after = response.aggregations.comp.after_key
4442
else:
4543
after = response.aggregations.comp.buckets[-1].key
4644
response = run_search(after=after)
4745

4846

49-
def main():
47+
if __name__ == "__main__":
5048
# initiate the default connection to elasticsearch
5149
connections.create_connection(hosts=[os.environ["ELASTICSEARCH_URL"]])
5250

@@ -59,10 +57,3 @@ def main():
5957
"File %s has been modified %d times, first seen at %s."
6058
% (b.key.files, b.doc_count, b.first_seen.value_as_string)
6159
)
62-
63-
# close the connection
64-
connections.get_connection().close()
65-
66-
67-
if __name__ == "__main__":
68-
asyncio.run(main())

Diff for: examples/parent_child.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
particular parent
4040
4141
"""
42-
import asyncio
4342
import os
4443
from datetime import datetime
4544

@@ -166,7 +165,7 @@ def get_answers(self):
166165
"""
167166
if "inner_hits" in self.meta and "answer" in self.meta.inner_hits:
168167
return self.meta.inner_hits.answer.hits
169-
return [a for a in self.search_answers()]
168+
return list(self.search_answers())
170169

171170
def save(self, **kwargs):
172171
self.question_answer = "question"
@@ -209,7 +208,7 @@ def setup():
209208
index_template.save()
210209

211210

212-
def main():
211+
if __name__ == "__main__":
213212
# initiate the default connection to elasticsearch
214213
connections.create_connection(hosts=[os.environ["ELASTICSEARCH_URL"]])
215214

@@ -244,12 +243,3 @@ def main():
244243
)
245244
question.save()
246245
answer = question.add_answer(honza, "Just use `elasticsearch-py`!")
247-
248-
# close the connection
249-
connections.get_connection().close()
250-
251-
return answer
252-
253-
254-
if __name__ == "__main__":
255-
asyncio.run(main())

Diff for: examples/percolate.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
import asyncio
1918
import os
2019

2120
from elasticsearch_dsl import (
@@ -92,15 +91,8 @@ def setup():
9291
).save(refresh=True)
9392

9493

95-
def main():
94+
if __name__ == "__main__":
9695
# initiate the default connection to elasticsearch
9796
connections.create_connection(hosts=[os.environ["ELASTICSEARCH_URL"]])
9897

9998
setup()
100-
101-
# close the connection
102-
connections.get_connection().close()
103-
104-
105-
if __name__ == "__main__":
106-
asyncio.run(main())

Diff for: tests/test_integration/test_examples/_async/alias_migration.py

-1
This file was deleted.

Diff for: tests/test_integration/test_examples/_async/completion.py

-1
This file was deleted.

Diff for: tests/test_integration/test_examples/_async/composite_agg.py

-1
This file was deleted.

Diff for: tests/test_integration/test_examples/_async/parent_child.py

-1
This file was deleted.

Diff for: tests/test_integration/test_examples/_async/percolate.py

-1
This file was deleted.

Diff for: tests/test_integration/test_examples/_async/test_alias_migration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from . import alias_migration
19-
from .alias_migration import ALIAS, PATTERN, BlogPost, migrate
18+
from ..async_examples import alias_migration
19+
from ..async_examples.alias_migration import ALIAS, PATTERN, BlogPost, migrate
2020

2121

2222
async def test_alias_migration(async_write_client):

Diff for: tests/test_integration/test_examples/_async/test_completion.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# under the License.
1717

1818

19-
from .completion import Person
19+
from ..async_examples.completion import Person
2020

2121

2222
async def test_person_suggests_on_all_variants_of_name(async_write_client):

Diff for: tests/test_integration/test_examples/_async/test_composite_aggs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from elasticsearch_dsl import A, AsyncSearch
1919

20-
from .composite_agg import scan_aggs
20+
from ..async_examples.composite_agg import scan_aggs
2121

2222

2323
async def test_scan_aggs_exhausts_all_files(async_data_client):

Diff for: tests/test_integration/test_examples/_async/test_parent_child.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from elasticsearch_dsl import Q
2323

24-
from .parent_child import Answer, Comment, Question, User, setup
24+
from ..async_examples.parent_child import Answer, Comment, Question, User, setup
2525

2626
honza = User(
2727
id=42,

Diff for: tests/test_integration/test_examples/_async/test_percolate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from .percolate import BlogPost, setup
18+
from ..async_examples.percolate import BlogPost, setup
1919

2020

2121
async def test_post_gets_tagged_automatically(async_write_client):

Diff for: tests/test_integration/test_examples/_sync/alias_migration.py

-1
This file was deleted.

Diff for: tests/test_integration/test_examples/_sync/completion.py

-1
This file was deleted.

Diff for: tests/test_integration/test_examples/_sync/composite_agg.py

-1
This file was deleted.

Diff for: tests/test_integration/test_examples/_sync/parent_child.py

-1
This file was deleted.

Diff for: tests/test_integration/test_examples/_sync/percolate.py

-1
This file was deleted.

Diff for: tests/test_integration/test_examples/_sync/test_alias_migration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from . import alias_migration
19-
from .alias_migration import ALIAS, PATTERN, BlogPost, migrate
18+
from ..examples import alias_migration
19+
from ..examples.alias_migration import ALIAS, PATTERN, BlogPost, migrate
2020

2121

2222
def test_alias_migration(write_client):

Diff for: tests/test_integration/test_examples/_sync/test_completion.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# under the License.
1717

1818

19-
from .completion import Person
19+
from ..examples.completion import Person
2020

2121

2222
def test_person_suggests_on_all_variants_of_name(write_client):

Diff for: tests/test_integration/test_examples/_sync/test_composite_aggs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from elasticsearch_dsl import A, Search
1919

20-
from .composite_agg import scan_aggs
20+
from ..examples.composite_agg import scan_aggs
2121

2222

2323
def test_scan_aggs_exhausts_all_files(data_client):

Diff for: tests/test_integration/test_examples/_sync/test_parent_child.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from elasticsearch_dsl import Q
2323

24-
from .parent_child import Answer, Comment, Question, User, setup
24+
from ..examples.parent_child import Answer, Comment, Question, User, setup
2525

2626
honza = User(
2727
id=42,

Diff for: tests/test_integration/test_examples/_sync/test_percolate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from .percolate import BlogPost, setup
18+
from ..examples.percolate import BlogPost, setup
1919

2020

2121
def test_post_gets_tagged_automatically(write_client):

Diff for: tests/test_integration/test_examples/async_examples

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../examples/async

Diff for: tests/test_integration/test_examples/examples

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../examples

Diff for: utils/run-unasync.py

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def main(check=False):
5555
"async_data_client": "data_client",
5656
"async_write_client": "write_client",
5757
"async_pull_request": "pull_request",
58+
"async_examples": "examples",
5859
"assert_awaited_once_with": "assert_called_once_with",
5960
}
6061
rules = [

0 commit comments

Comments
 (0)