Skip to content

Commit

Permalink
Merge pull request psf#269 from tvytlx/master
Browse files Browse the repository at this point in the history
Fix: fstring formatted with bytes
  • Loading branch information
oldani committed Feb 22, 2019
2 parents 9038704 + 9d78a00 commit afa7eb5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions requests_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,9 @@ def __init__(self, *, session: Union['HTMLSession', 'AsyncHTMLSession'] = None,
if isinstance(html, str):
html = html.encode(DEFAULT_ENCODING)

pq = PyQuery(html)
super(HTML, self).__init__(
# Convert unicode HTML to bytes.
element=PyQuery(html)('html') or PyQuery(f'<html>{html}</html>')('html'),
element=pq('html') or pq.wrapAll('<html></html>')('html'),
html=html,
url=url,
default_encoding=default_encoding
Expand Down
9 changes: 9 additions & 0 deletions tests/test_requests_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ def test_absolute_links(url, link, expected):
assert html.absolute_links.pop() == expected


@pytest.mark.parser
def test_parser():
doc = """<a href='https://httpbin.org'>httpbin.org\n</a>"""
html = HTML(html=doc)

assert html.find('html')
assert html.element('a').text().strip() == 'httpbin.org'


@pytest.mark.render
def test_render():
r = get()
Expand Down

0 comments on commit afa7eb5

Please sign in to comment.