Work around bs4 DeprecationWarning
See https://bugs.launchpad.net/beautifulsoup/+bug/1847592
This commit is contained in:
parent
bec5372473
commit
26aae66de5
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue