diff options
| author | mozbugbox <mozbugbox@yahoo.com.au> | 2015-06-06 00:04:19 +0800 |
|---|---|---|
| committer | mozbugbox <mozbugbox@yahoo.com.au> | 2015-06-06 00:04:19 +0800 |
| commit | 9d14dd83b95ffdba04f3ed62b34e5ce862c5cc6f (patch) | |
| tree | 2b865010131188a16bc0d8fa6fe26e763e4370a2 /src/lxml/html/tests | |
| parent | afa17103213b0fab66f381d7eae01e3433ac2d01 (diff) | |
| download | python-lxml-9d14dd83b95ffdba04f3ed62b34e5ce862c5cc6f.tar.gz | |
unittest check beautifulsoup/bs4 import properly
Diffstat (limited to 'src/lxml/html/tests')
| -rw-r--r-- | src/lxml/html/tests/test_elementsoup.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/lxml/html/tests/test_elementsoup.py b/src/lxml/html/tests/test_elementsoup.py index d16a702e..4eaed7ec 100644 --- a/src/lxml/html/tests/test_elementsoup.py +++ b/src/lxml/html/tests/test_elementsoup.py @@ -3,12 +3,9 @@ from lxml.tests.common_imports import make_doctest, HelperTestCase BS_INSTALLED = True try: - import BeautifulSoup + import lxml.html.soupparser except ImportError: - try: - import bs4 - except ImportError: - BS_INSTALLED = False + BS_INSTALLED = False from lxml.html import tostring @@ -93,12 +90,24 @@ b'''<!DOCTYPE html PUBLIC "-//IETF//DTD HTML//EN"> self.assertTrue(tree.docinfo.public_id is None) self.assertEqual(tostring(tree), html) +else: + class SoupNotInstalledTestCase(HelperTestCase): + + def test_beautifulsoup_not_installed(self): + # If BS_INSTALLED failed, beautifulsoup should not exist + with self.assertRaises(ImportError): + import bs4 + with self.assertRaises(ImportError): + import BeautifulSoup + def test_suite(): suite = unittest.TestSuite() if BS_INSTALLED: suite.addTests([unittest.makeSuite(SoupParserTestCase)]) if sys.version_info[0] < 3: suite.addTests([make_doctest('../../../../doc/elementsoup.txt')]) + else: + suite.addTests([unittest.makeSuite(SoupNotInstalledTestCase)]) return suite if __name__ == '__main__': |
