Add unit tests for UnicodeEncodeError handling
This commit is contained in:
parent
be08cee63c
commit
b9aa5df5ed
@ -263,3 +263,14 @@ class TestFileSchemeHandler:
|
||||
handler = filescheme.FileSchemeHandler(win_id=0)
|
||||
reply = handler.createRequest(None, req, None)
|
||||
assert reply is None
|
||||
|
||||
def test_unicode_encode_error(self, mocker):
|
||||
url = QUrl('file:///tmp/foo')
|
||||
req = QNetworkRequest(url)
|
||||
handler = filescheme.FileSchemeHandler(win_id=0)
|
||||
|
||||
err = UnicodeEncodeError('ascii', '', 0, 2, 'foo')
|
||||
mocker.patch('os.path.isdir', side_effect=err)
|
||||
|
||||
reply = handler.createRequest(None, req, None)
|
||||
assert reply is None
|
||||
|
@ -245,7 +245,7 @@ class TestFuzzyUrl:
|
||||
('/foo', False),
|
||||
('/bar', True),
|
||||
])
|
||||
def test_get_path_existing(self, path, check_exists, os_mock):
|
||||
def test_get_path_existing(self, path, check_exists, os_mock, caplog):
|
||||
"""Test with an absolute path."""
|
||||
os_mock.path.exists.return_value = False
|
||||
expected = None if check_exists else path
|
||||
@ -253,6 +253,18 @@ class TestFuzzyUrl:
|
||||
url = urlutils.get_path_if_valid(path, check_exists=check_exists)
|
||||
assert url == expected
|
||||
|
||||
def test_get_path_unicode_encode_error(self, os_mock, caplog):
|
||||
"""Make sure LC_ALL=C is handled correctly."""
|
||||
err = UnicodeEncodeError('ascii', '', 0, 2, 'foo')
|
||||
os_mock.path.exists.side_effect = err
|
||||
|
||||
url = urlutils.get_path_if_valid('/', check_exists=True)
|
||||
assert url is None
|
||||
|
||||
msg = ("URL contains characters which are not present in the current "
|
||||
"locale")
|
||||
assert caplog.records[-1].message == msg
|
||||
|
||||
|
||||
@pytest.mark.parametrize('url, special', [
|
||||
('file:///tmp/foo', True),
|
||||
|
Loading…
Reference in New Issue
Block a user