mirror of
https://github.com/kennethreitz/requests-html.git
synced 2026-06-05 06:46:14 +00:00
Minor refactoring, typo fixes.
This commit is contained in:
+15
-19
@@ -13,14 +13,14 @@ session.mount('file://', FileAdapter())
|
|||||||
|
|
||||||
def get():
|
def get():
|
||||||
path = os.path.sep.join((os.path.dirname(os.path.abspath(__file__)), 'python.html'))
|
path = os.path.sep.join((os.path.dirname(os.path.abspath(__file__)), 'python.html'))
|
||||||
url = 'file://{}'.format(path)
|
url = f'file://{path}'
|
||||||
|
|
||||||
return session.get(url)
|
return session.get(url)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def async_get(event_loop):
|
def async_get(event_loop):
|
||||||
""" AsyncSession cannot be created global since it will create
|
"""AsyncSession cannot be created global since it will create
|
||||||
a different loop from pytest-asyncio. """
|
a different loop from pytest-asyncio. """
|
||||||
async_session = AsyncHTMLSession()
|
async_session = AsyncHTMLSession()
|
||||||
async_session.mount('file://', FileAdapter())
|
async_session.mount('file://', FileAdapter())
|
||||||
@@ -54,8 +54,8 @@ def test_css_selector():
|
|||||||
about = r.html.find('#about', first=True)
|
about = r.html.find('#about', first=True)
|
||||||
|
|
||||||
for menu_item in (
|
for menu_item in (
|
||||||
'About', 'Applications', 'Quotes', 'Getting Started', 'Help',
|
'About', 'Applications', 'Quotes', 'Getting Started', 'Help',
|
||||||
'Python Brochure'
|
'Python Brochure'
|
||||||
):
|
):
|
||||||
assert menu_item in about.text.split('\n')
|
assert menu_item in about.text.split('\n')
|
||||||
assert menu_item in about.full_text.split('\n')
|
assert menu_item in about.full_text.split('\n')
|
||||||
@@ -290,16 +290,24 @@ async def test_bare_js_async_eval():
|
|||||||
|
|
||||||
|
|
||||||
def test_browser_session():
|
def test_browser_session():
|
||||||
""" Test browser instaces is created and properly close when session is closed.
|
""" Test browser instances is created and properly close when session is closed.
|
||||||
Note: session.close method need to be tested together with browser creation,
|
Note: session.close method need to be tested together with browser creation,
|
||||||
since no doing that will left the browser running. """
|
since not doing that will leave the browser running. """
|
||||||
session = HTMLSession()
|
session = HTMLSession()
|
||||||
assert isinstance(session.browser, Browser)
|
assert isinstance(session.browser, Browser)
|
||||||
assert hasattr(session, "loop") == True
|
assert hasattr(session, "loop")
|
||||||
session.close()
|
session.close()
|
||||||
# assert count_chromium_process() == 0
|
# assert count_chromium_process() == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_browser_process():
|
||||||
|
for _ in range(3):
|
||||||
|
r = get()
|
||||||
|
r.html.render()
|
||||||
|
|
||||||
|
assert r.html.page is None
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_browser_session_fail():
|
async def test_browser_session_fail():
|
||||||
""" HTMLSession.browser should not be call within an existing event loop> """
|
""" HTMLSession.browser should not be call within an existing event loop> """
|
||||||
@@ -308,21 +316,9 @@ async def test_browser_session_fail():
|
|||||||
session.browser
|
session.browser
|
||||||
|
|
||||||
|
|
||||||
def test_browser_process():
|
|
||||||
for _ in range(3):
|
|
||||||
r = get()
|
|
||||||
r.html.render()
|
|
||||||
|
|
||||||
assert r.html.page == None
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_async_browser_session():
|
async def test_async_browser_session():
|
||||||
session = AsyncHTMLSession()
|
session = AsyncHTMLSession()
|
||||||
browser = await session.browser
|
browser = await session.browser
|
||||||
assert isinstance(browser, Browser)
|
assert isinstance(browser, Browser)
|
||||||
await session.close()
|
await session.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_containing()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user