mirror of
https://github.com/kennethreitz/requests-html.git
synced 2026-06-05 06:46:14 +00:00
Fix broken tests, add more cases, refactor tests to allow more cases.
This commit is contained in:
Generated
+978
-392
File diff suppressed because it is too large
Load Diff
+28
-29
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user