test_batch_get.test_batch_get_8()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
from yfrake.client.return_types.client_response import ClientResponse
2
from yfrake import client
3
import asyncio
4
import pytest
5
import sys
6
import time
7
8
9
if sys.platform == 'win32':
10
    asyncio.set_event_loop_policy(
11
        asyncio.WindowsSelectorEventLoopPolicy()
12
    )
13
14
queries = [
15
    dict(endpoint='quote_type', symbol='msft'),
16
    dict(endpoint='price_overview', symbol='aapl'),
17
    dict(endpoint='key_statistics', symbol='tsla')
18
]
19
20
21
def test_batch_get_1():
22
    @client.session
23
    def inner():
24
        results = client.batch_get(queries)
25
        results.wait()
26
        for resp in results:
27
            assert bool(resp.error) is False
28
            assert bool(resp.data) is True
29
    inner()
30
31
32
def test_batch_get_2():
33
    @client.session
34
    def inner():
35
        results = client.batch_get(queries)
36
        while results.pending():
37
            time.sleep(0.001)
38
        for resp in results:
39
            assert bool(resp.error) is False
40
            assert bool(resp.data) is True
41
    inner()
42
43
44
def test_batch_get_3():
45
    @client.session
46
    def inner():
47
        results = client.batch_get(queries)
48
        for resp in results.gather():
49
            assert bool(resp.error) is False
50
            assert bool(resp.data) is True
51
    inner()
52
53
54
def test_batch_get_4():
55
    @client.session
56
    def inner():
57
        results = client.batch_get(queries)
58
        for resp in results.as_completed():
59
            assert bool(resp.error) is False
60
            assert bool(resp.data) is True
61
    inner()
62
63
64
async def test_batch_get_5():
65
    @client.session
66
    async def inner():
67
        results = client.batch_get(queries)
68
        await results.wait()
69
        for resp in results:
70
            assert bool(resp.error) is False
71
            assert bool(resp.data) is True
72
    await inner()
73
74
75
async def test_batch_get_6():
76
    @client.session
77
    async def inner():
78
        results = client.batch_get(queries)
79
        while results.pending():
80
            await asyncio.sleep(0.001)
81
        for resp in results:
82
            assert bool(resp.error) is False
83
            assert bool(resp.data) is True
84
    await inner()
85
86
87
async def test_batch_get_7():
88
    @client.session
89
    async def inner():
90
        results = client.batch_get(queries)
91
        async for resp in results.gather():
92
            assert bool(resp.error) is False
93
            assert bool(resp.data) is True
94
    await inner()
95
96
97
async def test_batch_get_8():
98
    @client.session
99
    async def inner():
100
        results = client.batch_get(queries)
101
        async for resp in results.as_completed():
102
            assert bool(resp.error) is False
103
            assert bool(resp.data) is True
104
    await inner()
105
106
107
async def test_batch_get_9():
108
    @client.session
109
    async def inner():
110
        results = client.batch_get(queries)
111
        await results.wait()
112
113
        assert len(results) == len(queries)
114
        assert isinstance(results[0], ClientResponse)
115
        results[0] = str()
116
        assert isinstance(results[0], str)
117
        del results[0]
118
        assert len(results) < len(queries)
119
    await inner()
120
121
122
async def test_batch_get_10():
123
    @client.session
124
    async def inner():
125
        _queries = ['asdfg']
126
        with pytest.raises(TypeError):
127
            client.batch_get(_queries)
128
    await inner()
129