Skip to content

Commit

Permalink
tests: improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
adbar committed Jan 25, 2022
1 parent 5053c27 commit 8af37c7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ omit =
exclude_lines =
pragma: no cover
if __name__ == .__main__.:
except .*ImportError.*:
except .*UnicodeDecodeError.*:
except .*urllib3.exceptions.*:
17 changes: 13 additions & 4 deletions tests/downloads_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,34 @@ def test_fetch():
else:
assert fetch_url('1234') == ''
assert fetch_url('https://httpbin.org/status/404') is None
# empty request?
#assert _send_request('') is None
# test if the fonctions default to no_ssl
assert _send_request('https://expired.badssl.com/', False, DEFAULT_CONFIG) is not None
if pycurl is not None:
assert _send_pycurl_request('https://expired.badssl.com/', False, DEFAULT_CONFIG) is not None
# no SSL, no decoding
url = 'https://httpbin.org/status/200'
response = _send_request('https://httpbin.org/status/200', True, DEFAULT_CONFIG)
assert response.data == b''
if pycurl is not None:
response = _send_pycurl_request('https://httpbin.org/status/200', True, DEFAULT_CONFIG)
assert response.data == b''
response1 = _send_pycurl_request('https://httpbin.org/status/200', True, DEFAULT_CONFIG)
assert _handle_response(url, response1, False, DEFAULT_CONFIG) == _handle_response(url, response, False, DEFAULT_CONFIG)
assert _handle_response(url, response1, True, DEFAULT_CONFIG) == _handle_response(url, response, True, DEFAULT_CONFIG)
# response object
url = 'https://httpbin.org/encoding/utf8'
response = _send_request(url, False, DEFAULT_CONFIG)
myobject = _handle_response(url, response, False, DEFAULT_CONFIG)
assert myobject.data.startswith(b'<h1>Unicode Demo</h1>')
# too large response object
mock = Mock()
mock.data = (b' '*10000000)
assert _handle_response(url, mock, False, DEFAULT_CONFIG) is None
mock.status = 200
# too large
mock.data = (b'ABC'*10000000)
assert _handle_response(url, mock, False, DEFAULT_CONFIG) == ''
# too small
mock.data = (b'ABC')
assert _handle_response(url, mock, False, DEFAULT_CONFIG) == ''
# straight handling of response object
assert load_html(response) is not None
# nothing to see here
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def test_lrucache():
def test_formatting():
'''Test HTML formatting conversion and extraction'''
# trailing <lb>
my_document = html.fromstring('<html><body><p>This here is the text.</p><br/></body></html>')
my_document = html.fromstring('<html><body><p>This here is the text.<br/></p></body></html>')
my_result = extract(my_document, output_format='xml', config=ZERO_CONFIG)
assert 'lb' not in my_result

Expand Down

0 comments on commit 8af37c7

Please sign in to comment.