summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÁrni Dagur <arni@dagur.eu>2020-12-18 19:48:53 +0000
committerÁrni Dagur <arni@dagur.eu>2020-12-19 20:30:24 +0000
commitf655ec4717f1fd73c12233c249084fb5c11463ad (patch)
treed8778a6b1128af15d4a88e79a175446dba8a3670
parent6e65e55f3ff8189c0dba29b98fca12d76a34a68e (diff)
downloadqutebrowser-f655ec4717f1fd73c12233c249084fb5c11463ad.tar.gz
qutebrowser-f655ec4717f1fd73c12233c249084fb5c11463ad.zip
Fix unraisable exception pytest failures in adblock
-rw-r--r--qutebrowser/components/braveadblock.py5
-rw-r--r--tests/unit/components/test_blockutils.py7
2 files changed, 6 insertions, 6 deletions
diff --git a/qutebrowser/components/braveadblock.py b/qutebrowser/components/braveadblock.py
index 4f7afee7c..3e244d832 100644
--- a/qutebrowser/components/braveadblock.py
+++ b/qutebrowser/components/braveadblock.py
@@ -253,9 +253,8 @@ class BraveAdBlocker:
"""
try:
fileobj.seek(0)
- text = io.TextIOWrapper(fileobj, encoding="utf-8")
- filter_set.add_filter_list(text.read())
- text.close()
+ with io.TextIOWrapper(fileobj, encoding="utf-8") as text_io:
+ filter_set.add_filter_list(text_io.read())
except UnicodeDecodeError:
message.info("braveadblock: Block list is not valid utf-8")
diff --git a/tests/unit/components/test_blockutils.py b/tests/unit/components/test_blockutils.py
index a5514e214..480a6f9eb 100644
--- a/tests/unit/components/test_blockutils.py
+++ b/tests/unit/components/test_blockutils.py
@@ -65,9 +65,10 @@ def test_blocklist_dl(qtbot, pretend_blocklists):
num_single_dl_called += 1
num_lines = 0
- for line in io.TextIOWrapper(download, encoding="utf-8"):
- assert line.split(".")[-1].strip() in ("com", "net", "is")
- num_lines += 1
+ with io.TextIOWrapper(download, encoding="utf-8") as dl_io:
+ for line in dl_io:
+ assert line.split(".")[-1].strip() in ("com", "net", "is")
+ num_lines += 1
assert num_lines >= 1
list_qurls = [QUrl(blocklist) for blocklist in pretend_blocklists[0]]