Skip to content

Commit 565cd49

Browse files
committed
bare render tests
Signed-off-by: Kenneth Reitz <me@kennethreitz.org>
1 parent e9c162f commit 565cd49

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

tests/test_requests_html.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def test_links():
4444
r = get()
4545
about = r.html.find('#about', first=True)
4646

47-
len(about.links) == 6
48-
len(about.absolute_links) == 6
47+
assert len(about.links) == 6
48+
assert len(about.absolute_links) == 6
4949

5050

5151
def test_search():
@@ -79,5 +79,44 @@ def test_anchor_links():
7979
assert '#site-map' in r.html.links
8080

8181

82+
def test_render():
83+
r = get()
84+
script = """
85+
() => {
86+
return {
87+
width: document.documentElement.clientWidth,
88+
height: document.documentElement.clientHeight,
89+
deviceScaleFactor: window.devicePixelRatio,
90+
}
91+
}
92+
"""
93+
val = r.html.render(script=script)
94+
for value in ('width', 'height', 'deviceScaleFactor'):
95+
assert value in val
96+
97+
about = r.html.find('#about', first=True)
98+
assert len(about.links) == 6
99+
100+
101+
def test_bare_render():
102+
doc = """<a href='https://httpbin.org'>"""
103+
html = HTML(html=doc)
104+
script = """
105+
() => {
106+
return {
107+
width: document.documentElement.clientWidth,
108+
height: document.documentElement.clientHeight,
109+
deviceScaleFactor: window.devicePixelRatio,
110+
}
111+
}
112+
"""
113+
val = html.render(script=script, reload=False)
114+
for value in ('width', 'height', 'deviceScaleFactor'):
115+
assert value in val
116+
117+
assert html.find('html')
118+
assert 'https://httpbin.org' in html.links
119+
120+
82121
if __name__ == '__main__':
83122
test_xpath()

0 commit comments

Comments
 (0)