diff options
author | Leonard Richardson <leonardr@segfault.org> | 2021-02-13 10:39:15 -0500 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2021-02-13 10:39:15 -0500 |
commit | 0986e7bb25c46c2c9c1787e474e81de157ecfedf (patch) | |
tree | 939b1ff73887f66ff92ead5df6bb0810f3463d02 /bs4/tests/test_soup.py | |
parent | 316093c577193e5e604bb90a16d520e2f5c1b60b (diff) |
Improve the warning issued when a directory name (as opposed to
the name of a regular file) is passed as markup into the BeautifulSoup
constructor. [bug=1913628]
Diffstat (limited to 'bs4/tests/test_soup.py')
-rw-r--r-- | bs4/tests/test_soup.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/bs4/tests/test_soup.py b/bs4/tests/test_soup.py index f21edfa..0603ce7 100644 --- a/bs4/tests/test_soup.py +++ b/bs4/tests/test_soup.py @@ -3,6 +3,7 @@ from pdb import set_trace import logging +import os import unittest import sys import tempfile @@ -291,6 +292,21 @@ class TestWarnings(SoupTest): soup = self.soup(filename) self.assertEqual([], w) + def test_directory_warning(self): + try: + filename = tempfile.mkdtemp() + with warnings.catch_warnings(record=True) as w: + soup = self.soup(filename) + warning = self._assert_warning(w, MarkupResemblesLocatorWarning) + self.assertTrue("looks like a directory" in str(warning.message)) + finally: + os.rmdir(filename) + + # The directory no longer exists, so Beautiful Soup will no longer issue the warning. + with warnings.catch_warnings(record=True) as w: + soup = self.soup(filename) + self.assertEqual([], w) + def test_url_warning_with_bytes_url(self): with warnings.catch_warnings(record=True) as warning_list: soup = self.soup(b"http://www.crummybytes.com/") |