From 36a4d3f2c6b7ddb967d885ba36f850a668029d9e Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sun, 12 Sep 2021 20:59:43 -0400 Subject: Ported unit tests to use pytest. --- bs4/tests/test_html5lib.py | 51 ++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'bs4/tests/test_html5lib.py') diff --git a/bs4/tests/test_html5lib.py b/bs4/tests/test_html5lib.py index f8902ad..9ac6ccc 100644 --- a/bs4/tests/test_html5lib.py +++ b/bs4/tests/test_html5lib.py @@ -17,7 +17,7 @@ from bs4.testing import ( @skipIf( not HTML5LIB_PRESENT, "html5lib seems not to be present, not testing its tree builder.") -class HTML5LibBuilderSmokeTest(SoupTest, HTML5TreeBuilderSmokeTest): +class TestHTML5LibBuilder(SoupTest, HTML5TreeBuilderSmokeTest): """See ``HTML5TreeBuilderSmokeTest``.""" @property @@ -30,12 +30,9 @@ class HTML5LibBuilderSmokeTest(SoupTest, HTML5TreeBuilderSmokeTest): markup = "

A bold statement.

" with warnings.catch_warnings(record=True) as w: soup = self.soup(markup, parse_only=strainer) - self.assertEqual( - soup.decode(), self.document_for(markup)) + assert soup.decode() == self.document_for(markup) - self.assertTrue( - "the html5lib tree builder doesn't support parse_only" in - str(w[0].message)) + assert "the html5lib tree builder doesn't support parse_only" in str(w[0].message) def test_correctly_nested_tables(self): """html5lib inserts tags where other parsers don't.""" @@ -46,13 +43,13 @@ class HTML5LibBuilderSmokeTest(SoupTest, HTML5TreeBuilderSmokeTest): 'foo' '') - self.assertSoupEquals( + self.assert_soup( markup, '
Here\'s another table:' '
foo
' '
') - self.assertSoupEquals( + self.assert_soup( "" "" "
Foo
Bar
Baz
") @@ -69,20 +66,20 @@ class HTML5LibBuilderSmokeTest(SoupTest, HTML5TreeBuilderSmokeTest): ''' soup = self.soup(markup) # Verify that we can reach the

tag; this means the tree is connected. - self.assertEqual(b"

foo

", soup.p.encode()) + assert b"

foo

" == soup.p.encode() def test_reparented_markup(self): markup = '

foo

\n

bar

' soup = self.soup(markup) - self.assertEqual("

foo

\n

bar

", soup.body.decode()) - self.assertEqual(2, len(soup.find_all('p'))) + assert "

foo

\n

bar

" == soup.body.decode() + assert 2 == len(soup.find_all('p')) def test_reparented_markup_ends_with_whitespace(self): markup = '

foo

\n

bar

\n' soup = self.soup(markup) - self.assertEqual("

foo

\n

bar

\n", soup.body.decode()) - self.assertEqual(2, len(soup.find_all('p'))) + assert "

foo

\n

bar

\n" == soup.body.decode() + assert 2 == len(soup.find_all('p')) def test_reparented_markup_containing_identical_whitespace_nodes(self): """Verify that we keep the two whitespace nodes in this @@ -99,7 +96,7 @@ class HTML5LibBuilderSmokeTest(SoupTest, HTML5TreeBuilderSmokeTest): markup = '
aftermath

aftermath

' soup = self.soup(markup) noscript = soup.noscript - self.assertEqual("target", noscript.next_element) + assert "target" == noscript.next_element target = soup.find(string='target') # The 'aftermath' string was duplicated; we want the second one. @@ -108,8 +105,8 @@ class HTML5LibBuilderSmokeTest(SoupTest, HTML5TreeBuilderSmokeTest): # The