diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2013-06-03 07:34:30 -0400 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2013-06-03 07:34:30 -0400 |
commit | 9949d66d18f14623adf57fb4cef41b0282bb8672 (patch) | |
tree | d2cfb8eb5fbe52b06b93d15e4645f8b607ccea35 /bs4/tests | |
parent | 4a9444ac0b74fbf84cf86b9fcf6055c85e65f62a (diff) |
Beautiful Soup will issue a warning if instead of markup you pass it
a URL or the name of a file on disk (a common beginner mistake).
Diffstat (limited to 'bs4/tests')
-rw-r--r-- | bs4/tests/test_soup.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/bs4/tests/test_soup.py b/bs4/tests/test_soup.py index 0b69318..860b17b 100644 --- a/bs4/tests/test_soup.py +++ b/bs4/tests/test_soup.py @@ -4,6 +4,8 @@ import logging import unittest import sys +import tempfile + from bs4 import ( BeautifulSoup, BeautifulStoneSoup, @@ -64,7 +66,31 @@ class TestDeprecatedConstructorArguments(SoupTest): with warnings.catch_warnings(record=True) as w: soup = BeautifulStoneSoup("<markup>") self.assertTrue(isinstance(soup, BeautifulSoup)) - self.assertTrue("BeautifulStoneSoup class is deprecated") + self.assertTrue("BeautifulStoneSoup class is deprecated" in str(w[0].message)) + +class TestWarnings(SoupTest): + + def test_disk_file_warning(self): + filehandle = tempfile.NamedTemporaryFile() + filename = filehandle.name + try: + with warnings.catch_warnings(record=True) as w: + soup = self.soup(filename) + msg = str(w[0].message) + self.assertTrue("looks like a filename" in msg) + finally: + filehandle.close() + + def test_url_warning(self): + with warnings.catch_warnings(record=True) as w: + soup = self.soup("http://www.crummy.com/") + msg = str(w[0].message) + self.assertTrue("looks like a URL" in msg) + + with warnings.catch_warnings(record=True) as w: + soup = self.soup("http://www.crummy.com/ is great") + self.assertEqual(0, len(w)) + class TestSelectiveParsing(SoupTest): |