Fix broken tests, add more cases, refactor tests to allow more cases.

This commit is contained in:
surister
2023-02-26 13:23:05 +01:00
parent 026c4e5217
commit 1786eb65fd
2 changed files with 1006 additions and 421 deletions
+28 -29
View File
@@ -1,48 +1,47 @@
import pytest
from requests_html import HTMLSession, AsyncHTMLSession, HTMLResponse
session = HTMLSession()
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():
pages = (
'https://xkcd.com/1957/',
'https://smile.amazon.com/',
'https://theverge.com/archives'
)
def test_pagination(url: str):
session = HTMLSession()
r = session.get(url)
assert next(r.html)
for page in pages:
r = session.get(page)
assert next(r.html)
@pytest.mark.parametrize('url', urls)
@pytest.mark.internet
@pytest.mark.asyncio
async def test_async_pagination(event_loop):
async def test_async_pagination(event_loop, url):
asession = AsyncHTMLSession()
pages = (
'https://xkcd.com/1957/',
'https://smile.amazon.com/',
'https://theverge.com/archives'
)
for page in pages:
r = await asession.get(page)
assert await r.html.__anext__()
r = await asession.get(url)
assert await r.html.__anext__()
@pytest.mark.internet
def test_async_run():
asession = AsyncHTMLSession()
async def test1():
return await asession.get('https://xkcd.com/1957/')
async_list = []
for url in urls:
async def _test():
return await asession.get(url)
async_list.append(_test)
async def test2():
return await asession.get('https://reddit.com/')
r = asession.run(*async_list)
async def test3():
return await asession.get('https://smile.amazon.com/')
r = asession.run(test1, test2, test3)
assert len(r) == 3
assert len(r) == len(urls)
assert isinstance(r[0], HTMLResponse)