From df26dc64d868875d7cd8ca550f1a174d68dd7c67 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Fri, 20 Jan 2012 14:22:42 -0500 Subject: Replaced assertEquals with assertEqual to get rid of deprecation notice. --- bs4/tests/test_lxml.py | 106 ++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 53 deletions(-) (limited to 'bs4/tests/test_lxml.py') diff --git a/bs4/tests/test_lxml.py b/bs4/tests/test_lxml.py index 0eafab0..d1f4276 100644 --- a/bs4/tests/test_lxml.py +++ b/bs4/tests/test_lxml.py @@ -55,7 +55,7 @@ class TestLXMLBuilder(SoupTest): soup = self.soup(markup) comment = soup.find(text="foobar") - self.assertEquals(comment.__class__, Comment) + self.assertEqual(comment.__class__, Comment) def test_nested_inline_elements(self): # Inline tags can be nested indefinitely. @@ -138,28 +138,28 @@ class TestLXMLBuilder(SoupTest): # best to parse the contents of a ' soup = self.soup(text) - self.assertEquals(len(soup.textarea.contents), 2) - self.assertEquals(soup.textarea.contents[0], u"Junk like ") - self.assertEquals(soup.textarea.contents[1].name, 'b') - self.assertEquals(soup.textarea.b.string, u" tags and ") + self.assertEqual(len(soup.textarea.contents), 2) + self.assertEqual(soup.textarea.contents[0], u"Junk like ") + self.assertEqual(soup.textarea.contents[1].name, 'b') + self.assertEqual(soup.textarea.b.string, u" tags and ") def test_literal_in_script(self): # The contents of a ' % javascript) - self.assertEquals(soup.script.string, javascript) + self.assertEqual(soup.script.string, javascript) def test_naked_ampersands(self): # Ampersands are left alone. text = "

AT&T

" soup = self.soup(text) - self.assertEquals(soup.p.string, "AT&T") + self.assertEqual(soup.p.string, "AT&T") # Even if they're in attribute values. invalid_url = 'foo' soup = self.soup(invalid_url) - self.assertEquals(soup.a['href'], "http://example.org?a=1&b=2;3") + self.assertEqual(soup.a['href'], "http://example.org?a=1&b=2;3") def test_entities_in_strings_converted_during_parsing(self): # Both XML and HTML entities are converted to Unicode characters @@ -173,13 +173,13 @@ class TestLXMLBuilder(SoupTest): # parsing. quote = b"

\x91Foo\x92

" soup = self.soup(quote) - self.assertEquals( + self.assertEqual( soup.p.string, u"\N{LEFT SINGLE QUOTATION MARK}Foo\N{RIGHT SINGLE QUOTATION MARK}") def test_non_breaking_spaces_converted_on_the_way_in(self): soup = self.soup("  ") - self.assertEquals(soup.a.string, u"\N{NO-BREAK SPACE}" * 2) + self.assertEqual(soup.a.string, u"\N{NO-BREAK SPACE}" * 2) def test_cdata_where_its_ok(self): # lxml strips CDATA sections, no matter where they occur. @@ -192,13 +192,13 @@ class TestLXMLBuilder(SoupTest): markup = doctype_str + '

foo

' soup = self.soup(markup) doctype = soup.contents[0] - self.assertEquals(doctype.__class__, Doctype) - self.assertEquals(doctype, doctype_fragment) - self.assertEquals(str(soup)[:len(doctype_str)], doctype_str) + self.assertEqual(doctype.__class__, Doctype) + self.assertEqual(doctype, doctype_fragment) + self.assertEqual(str(soup)[:len(doctype_str)], doctype_str) # Make sure that the doctype was correctly associated with the # parse tree and that the rest of the document parsed. - self.assertEquals(soup.p.contents[0], 'foo') + self.assertEqual(soup.p.contents[0], 'foo') def test_doctype(self): # Test a normal HTML doctype you'll commonly see in a real document. @@ -238,7 +238,7 @@ class TestLXMLBuilder(SoupTest): expected = expected.encode("utf-8") # Ta-da! - self.assertEquals(result, expected) + self.assertEqual(result, expected) def test_real_shift_jis_document(self): # Smoke test to make sure the parser can handle a document in @@ -254,8 +254,8 @@ class TestLXMLBuilder(SoupTest): # Make sure the parse tree is correctly encoded to various # encodings. - self.assertEquals(soup.encode("utf-8"), unicode_html.encode("utf-8")) - self.assertEquals(soup.encode("euc_jp"), unicode_html.encode("euc_jp")) + self.assertEqual(soup.encode("utf-8"), unicode_html.encode("utf-8")) + self.assertEqual(soup.encode("euc_jp"), unicode_html.encode("euc_jp")) # Tests below this line need work. @@ -275,9 +275,9 @@ class TestLXMLBuilder(SoupTest): # Parse the document, and the charset is replaced with a # generic value. parsed_meta = soup.find('meta', {'http-equiv': 'Content-type'}) - self.assertEquals(parsed_meta['content'], + self.assertEqual(parsed_meta['content'], 'text/html; charset=%SOUP-ENCODING%') - self.assertEquals(parsed_meta.contains_substitutions, True) + self.assertEqual(parsed_meta.contains_substitutions, True) # For the rest of the story, see TestSubstitutions in # test_tree.py. @@ -287,25 +287,25 @@ class TestLXMLBuilder(SoupTest): expected = u"<<sacr\N{LATIN SMALL LETTER E WITH ACUTE} bleu!>>".encode("utf-8") soup = self.soup(text) str = soup.p.string - #self.assertEquals(str.encode("utf-8"), expected) + #self.assertEqual(str.encode("utf-8"), expected) def test_br_tag_is_empty_element(self): """A
tag is designated as an empty-element tag.""" soup = self.soup("

") self.assertTrue(soup.br.is_empty_element) - self.assertEquals(str(soup.br), "
") + self.assertEqual(str(soup.br), "
") def test_p_tag_is_not_empty_element(self): """A

tag is not designated as an empty-element tag.""" soup = self.soup("

") self.assertFalse(soup.p.is_empty_element) - self.assertEquals(str(soup.p), "

") + self.assertEqual(str(soup.p), "

") def test_soupstrainer(self): strainer = SoupStrainer("b") soup = self.soup("A bold statement", parse_only=strainer) - self.assertEquals(soup.decode(), "bold") + self.assertEqual(soup.decode(), "bold") class TestLXMLBuilderInvalidMarkup(SoupTest): @@ -348,7 +348,7 @@ class TestLXMLBuilderInvalidMarkup(SoupTest): def test_boolean_attribute_with_no_value_gets_empty_value(self): soup = self.soup("
foo
") - self.assertEquals(soup.table.td['nowrap'], '') + self.assertEqual(soup.table.td['nowrap'], '') def test_incorrectly_nested_tables(self): self.assertSoupEquals( @@ -359,7 +359,7 @@ class TestLXMLBuilderInvalidMarkup(SoupTest): markup = self.soup("

this is the definition:" "

first case
") # The

tag is closed before the

tag begins. - self.assertEquals(markup.p.contents, ["this is the definition:"]) + self.assertEqual(markup.p.contents, ["this is the definition:"]) def test_empty_element_tag_with_contents(self): self.assertSoupEquals("
foo
", "
foo") @@ -391,7 +391,7 @@ class TestLXMLBuilderInvalidMarkup(SoupTest): def test_attribute_value_never_got_closed(self): markup = ' and blah and blah") def test_attribute_value_was_closed_by_subsequent_tag(self): @@ -399,28 +399,28 @@ class TestLXMLBuilderInvalidMarkup(SoupTest): soup = self.soup(markup) # The string between the first and second quotes was interpreted # as the value of the 'href' attribute. - self.assertEquals(soup.a['href'], 'foo, , ') - self.assertEquals(soup.a['style'], '{height:21px;}') + self.assertEqual(soup.a['style'], '{height:21px;}') def test_attribute_value_with_embedded_brackets(self): soup = self.soup('') - self.assertEquals(soup.a['b'], '') + self.assertEqual(soup.a['b'], '') def test_nonexistent_entity(self): soup = self.soup("

foo&#bar;baz

") - self.assertEquals(soup.p.string, "foobar;baz") + self.assertEqual(soup.p.string, "foobar;baz") # Compare a real entity. soup = self.soup("

foodbaz

") - self.assertEquals(soup.p.string, "foodbaz") + self.assertEqual(soup.p.string, "foodbaz") # Also compare html5lib, which preserves the &# before the # entity name. @@ -428,27 +428,27 @@ class TestLXMLBuilderInvalidMarkup(SoupTest): def test_entity_out_of_range(self): # An entity that's out of range will be ignored. soup = self.soup("

") - self.assertEquals(soup.p.string, None) + self.assertEqual(soup.p.string, None) soup = self.soup("

") - self.assertEquals(soup.p.string, None) + self.assertEqual(soup.p.string, None) def test_entity_was_not_finished(self): soup = self.soup("

<Hello>") # Compare html5lib, which completes the entity. - self.assertEquals(soup.p.string, "a

a

') # The declaration is ignored altogether. - self.assertEquals(soup.encode(), b"

a

") + self.assertEqual(soup.encode(), b"

a

") def test_tag_name_contains_unicode(self): # Unicode characters in tag names are stripped. @@ -475,28 +475,28 @@ class TestLXMLBuilderEncodingConversion(SoupTest): soup_from_ascii = self.soup(ascii) unicode_output = soup_from_ascii.decode() self.assertTrue(isinstance(unicode_output, unicode)) - self.assertEquals(unicode_output, self.document_for(ascii.decode())) - self.assertEquals(soup_from_ascii.original_encoding, "ascii") + self.assertEqual(unicode_output, self.document_for(ascii.decode())) + self.assertEqual(soup_from_ascii.original_encoding, "ascii") def test_unicode_in_unicode_out(self): # Unicode input is left alone. The original_encoding attribute # is not set. soup_from_unicode = self.soup(self.unicode_data) - self.assertEquals(soup_from_unicode.decode(), self.unicode_data) - self.assertEquals(soup_from_unicode.foo.string, u'Sacr\xe9 bleu!') - self.assertEquals(soup_from_unicode.original_encoding, None) + self.assertEqual(soup_from_unicode.decode(), self.unicode_data) + self.assertEqual(soup_from_unicode.foo.string, u'Sacr\xe9 bleu!') + self.assertEqual(soup_from_unicode.original_encoding, None) def test_utf8_in_unicode_out(self): # UTF-8 input is converted to Unicode. The original_encoding # attribute is set. soup_from_utf8 = self.soup(self.utf8_data) - self.assertEquals(soup_from_utf8.decode(), self.unicode_data) - self.assertEquals(soup_from_utf8.foo.string, u'Sacr\xe9 bleu!') + self.assertEqual(soup_from_utf8.decode(), self.unicode_data) + self.assertEqual(soup_from_utf8.foo.string, u'Sacr\xe9 bleu!') def test_utf8_out(self): # The internal data structures can be encoded as UTF-8. soup_from_unicode = self.soup(self.unicode_data) - self.assertEquals(soup_from_unicode.encode('utf-8'), self.utf8_data) + self.assertEqual(soup_from_unicode.encode('utf-8'), self.utf8_data) HEBREW_DOCUMENT = b'Hebrew (ISO 8859-8) in Visual Directionality

Hebrew (ISO 8859-8) in Visual Directionality

\xed\xe5\xec\xf9' @@ -505,8 +505,8 @@ class TestLXMLBuilderEncodingConversion(SoupTest): # Hebrew encoding) to UTF-8. soup = self.soup(self.HEBREW_DOCUMENT, from_encoding="iso-8859-8") - self.assertEquals(soup.original_encoding, 'iso-8859-8') - self.assertEquals( + self.assertEqual(soup.original_encoding, 'iso-8859-8') + self.assertEqual( soup.encode('utf-8'), self.HEBREW_DOCUMENT.decode("iso-8859-8").encode("utf-8")) @@ -539,7 +539,7 @@ class TestLXMLXMLBuilder(SoupTest): markup = "" soup = self.soup(markup) cdata = soup.foo.contents[0] - self.assertEquals(cdata.__class__.__name__, 'NavigableString') + self.assertEqual(cdata.__class__.__name__, 'NavigableString') def test_can_handle_invalid_xml(self): @@ -562,20 +562,20 @@ class TestLXMLXMLBuilder(SoupTest): self.assertTrue(soup.bar.is_empty_element) soup.bar.insert(1, "Contents") self.assertFalse(soup.bar.is_empty_element) - self.assertEquals(str(soup), self.document_for("Contents")) + self.assertEqual(str(soup), self.document_for("Contents")) def test_designated_empty_element_tag_has_no_closing_tag(self): builder = LXMLTreeBuilderForXML(empty_element_tags=['bar']) soup = BeautifulSoup(builder=builder, markup="") self.assertTrue(soup.bar.is_empty_element) - self.assertEquals(str(soup), self.document_for("")) + self.assertEqual(str(soup), self.document_for("")) def test_empty_tag_not_in_empty_element_tag_list_has_closing_tag(self): builder = LXMLTreeBuilderForXML(empty_element_tags=['bar']) soup = BeautifulSoup(builder=builder, markup="") self.assertFalse(soup.foo.is_empty_element) - self.assertEquals(str(soup), self.document_for("")) + self.assertEqual(str(soup), self.document_for("")) def test_designated_empty_element_tag_does_not_change_parser_behavior(self): # The designated list of empty-element tags only affects how @@ -583,4 +583,4 @@ class TestLXMLXMLBuilder(SoupTest): # parsed--that's the parser's job. builder = LXMLTreeBuilderForXML(empty_element_tags=['bar']) soup = BeautifulSoup(builder=builder, markup="contents") - self.assertEquals(str(soup), self.document_for("contents")) + self.assertEqual(str(soup), self.document_for("contents")) -- cgit v1.2.3