forked from psf/requests-html
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathtest_internet.py
47 lines (35 loc) · 1.08 KB
/
test_internet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import pytest
from requests_html import HTMLSession, AsyncHTMLSession, HTMLResponse
urls = [
'https://xkcd.com/1957/',
'https://www.reddit.com/',
'https://github.com/psf/requests-html/issues',
'https://discord.com/category/engineering',
'https://stackoverflow.com/',
'https://www.frontiersin.org/',
'https://azure.microsoft.com/en-us'
]
@pytest.mark.parametrize('url', urls)
@pytest.mark.internet
def test_pagination(url: str):
session = HTMLSession()
r = session.get(url)
assert next(r.html)
@pytest.mark.parametrize('url', urls)
@pytest.mark.internet
@pytest.mark.asyncio
async def test_async_pagination(event_loop, url):
asession = AsyncHTMLSession()
r = await asession.get(url)
assert await r.html.__anext__()
@pytest.mark.internet
def test_async_run():
asession = AsyncHTMLSession()
async_list = []
for url in urls:
async def _test():
return await asession.get(url)
async_list.append(_test)
r = asession.run(*async_list)
assert len(r) == len(urls)
assert isinstance(r[0], HTMLResponse)