diff options
author | Leonard Richardson <leonardr@segfault.org> | 2014-12-07 09:31:30 -0500 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2014-12-07 09:31:30 -0500 |
commit | bf58c02abf418556927363cf79cc86bee58d0592 (patch) | |
tree | 747e9f5a6d6aa7fcce064ad44c9efb5e43fdca73 /bs4/tests/test_soup.py | |
parent | a7f63d509473e11a48ff3f9b2d8b37a19a7a25ef (diff) |
Issue a warning if the BeautifulSoup constructor arguments do not explicitly name a parser.
Diffstat (limited to 'bs4/tests/test_soup.py')
-rw-r--r-- | bs4/tests/test_soup.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/bs4/tests/test_soup.py b/bs4/tests/test_soup.py index 47ac245..b74a246 100644 --- a/bs4/tests/test_soup.py +++ b/bs4/tests/test_soup.py @@ -49,7 +49,28 @@ class TestConstructor(SoupTest): self.assertEqual(u"foo\0bar", soup.h1.string) -class TestDeprecatedConstructorArguments(SoupTest): +class TestWarnings(SoupTest): + + def _no_parser_specified(self, s, is_there=True): + v = s.startswith(BeautifulSoup.NO_PARSER_SPECIFIED_WARNING[:80]) + self.assertTrue(v) + + def test_warning_if_no_parser_specified(self): + with warnings.catch_warnings(record=True) as w: + soup = self.soup("<a><b></b></a>") + msg = str(w[0].message) + self._assert_no_parser_specified(msg) + + def test_warning_if_parser_specified_too_vague(self): + with warnings.catch_warnings(record=True) as w: + soup = self.soup("<a><b></b></a>", "html") + msg = str(w[0].message) + self._assert_no_parser_specified(msg) + + def test_no_warning_if_explicit_parser_specified(self): + with warnings.catch_warnings(record=True) as w: + soup = self.soup("<a><b></b></a>", "html.parser") + self.assertEquals([], w) def test_parseOnlyThese_renamed_to_parse_only(self): with warnings.catch_warnings(record=True) as w: |