test_client   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 73
dl 0
loc 92
rs 10
c 0
b 0
f 0
wmc 15

8 Functions

Rating   Name   Duplication   Size   Complexity  
A test_async_object() 0 10 2
A test_invalid_endpoint() 0 7 2
A test_client_already_configured() 0 8 2
A test_invalid_symbol() 0 9 1
A test_invalid_datatype() 0 7 2
A test_singleton_instantiation() 0 11 2
A test_invalid_param() 0 7 2
A test_client_not_configured() 0 6 2
1
from yfrake import client, ClientSingleton
2
import asyncio
3
import pytest
4
import sys
5
6
7
if sys.platform == 'win32':
8
    asyncio.set_event_loop_policy(
9
        asyncio.WindowsSelectorEventLoopPolicy()
10
    )
11
12
13
def test_client_not_configured():
14
    def inner():
15
        args = dict()
16
        with pytest.raises(RuntimeError):
17
            client.get(**args)
18
    inner()
19
20
21
def test_client_already_configured():
22
    @client.session
23
    def inner():
24
        with pytest.raises(RuntimeError):
25
            @client.session
26
            def failure():
27
                pass
28
    inner()
29
30
31
def test_invalid_endpoint():
32
    @client.session
33
    def inner():
34
        args = dict(endpoint='THIS_IS_INVALID', symbol='msft')
35
        with pytest.raises(NameError):
36
            client.get(**args)
37
    inner()
38
39
40
def test_invalid_param():
41
    @client.session
42
    def inner():
43
        args = dict(endpoint='quote_type', INVALID_KEY='msft')
44
        with pytest.raises(KeyError):
45
            client.get(**args)
46
    inner()
47
48
49
def test_invalid_datatype():
50
    @client.session
51
    def inner():
52
        args = dict(endpoint='quote_type', symbol=1000)
53
        with pytest.raises(TypeError):
54
            client.get(**args)
55
    inner()
56
57
58
def test_invalid_symbol():
59
    @client.session
60
    def inner():
61
        args = dict(endpoint='quote_type', symbol='THIS_IS_INVALID')
62
        resp = client.get(**args)
63
        resp.wait()
64
        assert bool(resp.error) is True
65
        assert bool(resp.data) is False
66
    inner()
67
68
69
async def test_async_object():
70
    @client.session
71
    async def inner():
72
        args = dict(endpoint='quote_type', symbol='msft')
73
        resp = client.get(**args)
74
        while resp.pending():
75
            await asyncio.sleep(0.0001)
76
        assert bool(resp.error) is False
77
        assert bool(resp.data) is True
78
    await inner()
79
80
81
async def test_singleton_instantiation():
82
    @client.session
83
    async def inner():
84
        _client = ClientSingleton()
85
        args = dict(endpoint='quote_type', symbol='msft')
86
        resp = _client.get(**args)
87
        while resp.pending():
88
            await asyncio.sleep(0.0001)
89
        assert bool(resp.error) is False
90
        assert bool(resp.data) is True
91
    await inner()
92