| Total Complexity | 2 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from yfrake.cache.cache import CacheSingleton |
||
| 2 | from yfrake import client |
||
| 3 | from datetime import datetime |
||
| 4 | import asyncio |
||
| 5 | import sys |
||
| 6 | |||
| 7 | |||
| 8 | if sys.platform == 'win32': |
||
| 9 | asyncio.set_event_loop_policy( |
||
| 10 | asyncio.WindowsSelectorEventLoopPolicy() |
||
| 11 | ) |
||
| 12 | |||
| 13 | |||
| 14 | async def test_client_cache(): |
||
| 15 | cache = CacheSingleton() |
||
| 16 | while len(cache.cache) != 0: |
||
| 17 | cache.cache.popitem() |
||
| 18 | |||
| 19 | @client.session |
||
| 20 | async def inner(): |
||
| 21 | args = dict(endpoint='quote_type', symbol='msft') |
||
| 22 | start_1 = datetime.now() |
||
| 23 | resp_1 = client.get(**args) |
||
| 24 | await resp_1.wait() |
||
| 25 | end_1 = datetime.now() |
||
| 26 | diff_1 = end_1 - start_1 |
||
| 27 | |||
| 28 | start_2 = datetime.now() |
||
| 29 | resp_2 = client.get(**args) |
||
| 30 | await resp_2.wait() |
||
| 31 | end_2 = datetime.now() |
||
| 32 | diff_2 = end_2 - start_2 |
||
| 33 | |||
| 34 | assert resp_1.data == resp_2.data |
||
| 35 | assert diff_1 > diff_2 |
||
| 36 | |||
| 37 | await inner() |
||
| 38 |