Work around bs4 DeprecationWarning

See https://bugs.launchpad.net/beautifulsoup/+bug/1847592
This commit is contained in:
Florian Bruhin 2019-10-10 13:34:52 +02:00
parent bec5372473
commit 26aae66de5
3 changed files with 35 additions and 6 deletions

View File

@ -27,7 +27,9 @@ import pytest
import bs4
from PyQt5.QtCore import QUrl
from qutebrowser.utils import urlutils
from helpers import utils as testutils
pytestmark = pytest.mark.qtwebengine_skip("Title is empty when parsing for "
@ -127,7 +129,10 @@ def parse(quteproc):
"""
html = quteproc.get_content(plain=False)
soup = bs4.BeautifulSoup(html, 'html.parser')
print(soup.prettify())
with testutils.ignore_bs4_warning():
print(soup.prettify())
title_prefix = 'Browse directory: '
# Strip off the title prefix to obtain the path of the folder that
# we're browsing

View File

@ -27,7 +27,7 @@ import contextlib
import pytest
from qutebrowser.utils import qtutils
from qutebrowser.utils import qtutils, log
qt58 = pytest.mark.skipif(
@ -180,3 +180,14 @@ def abs_datapath():
@contextlib.contextmanager
def nop_contextmanager():
yield
@contextlib.contextmanager
def ignore_bs4_warning():
"""WORKAROUND for https://bugs.launchpad.net/beautifulsoup/+bug/1847592."""
with log.ignore_py_warnings(
category=DeprecationWarning,
message="Using or importing the ABCs from 'collections' instead "
"of from 'collections.abc' is deprecated, and in 3.8 it will stop "
"working", module='bs4.element'):
yield

View File

@ -19,6 +19,7 @@
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
import os
import contextlib
import attr
import pytest
@ -28,6 +29,7 @@ from PyQt5.QtNetwork import QNetworkRequest
from qutebrowser.browser.webkit.network import filescheme
from qutebrowser.utils import urlutils, utils
from helpers import utils as testutils
@pytest.mark.parametrize('create_file, create_dir, filterfunc, expected', [
@ -129,7 +131,10 @@ class TestDirbrowserHtml:
def parse(path):
html = filescheme.dirbrowser_html(path).decode('utf-8')
soup = bs4.BeautifulSoup(html, 'html.parser')
print(soup.prettify())
with testutils.ignore_bs4_warning():
print(soup.prettify())
container = soup('div', id='dirbrowserContainer')[0]
parent_elem = container('ul', class_='parent')
@ -156,7 +161,10 @@ class TestDirbrowserHtml:
def test_basic(self):
html = filescheme.dirbrowser_html(os.getcwd()).decode('utf-8')
soup = bs4.BeautifulSoup(html, 'html.parser')
print(soup.prettify())
with testutils.ignore_bs4_warning():
print(soup.prettify())
container = soup.div
assert container['id'] == 'dirbrowserContainer'
title_elem = container('div', id='dirbrowserTitle')[0]
@ -170,7 +178,9 @@ class TestDirbrowserHtml:
html = filescheme.dirbrowser_html(os.getcwd()).decode('utf-8')
soup = bs4.BeautifulSoup(html, 'html.parser')
print(soup.prettify())
with testutils.ignore_bs4_warning():
print(soup.prettify())
css = soup.html.head.style.string
assert "background-image: url('file:///test%20path/foo.svg');" in css
@ -239,7 +249,10 @@ class TestDirbrowserHtml:
m.side_effect = OSError('Error message')
html = filescheme.dirbrowser_html('').decode('utf-8')
soup = bs4.BeautifulSoup(html, 'html.parser')
print(soup.prettify())
with testutils.ignore_bs4_warning():
print(soup.prettify())
error_msg = soup('p', id='error-message-text')[0].string
assert error_msg == 'Error message'