Skip to content

Commit f822c83

Browse files
committed
elastic#5 adds syntax support for tests in 3.5
1 parent 688ae44 commit f822c83

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

test_elasticsearch_async/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ def sniff_data():
103103

104104

105105
@fixture
106-
async def es():
107-
es = AsyncElasticsearch()
108-
await es.indices.delete('test_*', ignore=404)
106+
def es(event_loop):
107+
es = AsyncElasticsearch(loop=event_loop)
108+
event_loop.run_until_complete(es.indices.delete('test_*', ignore=404))
109109
yield es
110-
await es.transport.close()
110+
event_loop.run_until_complete(es.transport.close())

test_elasticsearch_async/test_helpers/test_scan.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ async def es_data(es):
3535
async def test_basic(es, mocker):
3636
mocker.spy(es.transport, 'perform_request')
3737

38-
docs = [d async for d in scan(es, size=5)]
38+
docs = []
39+
async for d in scan(es, size=5):
40+
docs.append(d)
3941
assert len(docs) == 8
4042
assert {d['_id'] for d in docs} == set(map(str, range(1, 9)))
4143
assert {d['_source']['field'] for d in docs} == set('abcdefgh')
@@ -56,14 +58,17 @@ async def _active_scrolls(es):
5658
async def test_cleanup(es):
5759
assert await _active_scrolls(es) == 0
5860

59-
_ = [d async for d in scan(es, clear_scroll=True)]
61+
async for _ in scan(es, clear_scroll=True):
62+
pass
6063
assert await _active_scrolls(es) == 0
6164

62-
generator = scan(es, clear_scroll=False)
63-
_ = [d async for d in generator]
64-
assert await _active_scrolls(es) != 0
65-
66-
await es.clear_scroll(scroll_id=generator._scroll_id)
65+
scroller = scan(es, clear_scroll=False)
66+
try:
67+
async for _ in scroller:
68+
pass
69+
assert await _active_scrolls(es) != 0
70+
finally:
71+
await es.clear_scroll(scroll_id=scroller._scroll_id)
6772

6873

6974
async def test_scan_error(es, mocker):
@@ -76,7 +81,9 @@ async def wrapper(*args, **kwargs):
7681
return response
7782
return wrapper
7883

79-
res = [d async for d in scan(es)]
84+
res = []
85+
async for d in scan(es):
86+
res.append(d)
8087
assert len(res) == 8
8188

8289
warning_mock = mocker.patch('elasticsearch_async.helpers.logger.warning')
@@ -87,12 +94,15 @@ async def wrapper(*args, **kwargs):
8794
)
8895

8996
with pytest.raises(ScanError):
90-
_ = [d async for d in scan(es)]
97+
async for _ in scan(es):
98+
pass
9199
assert warning_mock.called
92100
assert await _active_scrolls(es) == 0
93101

94102
mocker.resetall()
95-
res = [d async for d in scan(es, raise_on_error=False)]
103+
res = []
104+
async for d in scan(es, raise_on_error=False):
105+
res.append(d)
96106
assert len(res) == 8
97107
assert warning_mock.called
98108
assert await _active_scrolls(es) == 0

0 commit comments

Comments
 (0)