Browse Source

Do not die miserably when you get `False` as the HTML input. Test it.

pull/874/head
Yajo 9 years ago
committed by Jairo Llopis
parent
commit
0e3713583c
  1. 2
      html_text/models/ir_fields_converter.py
  2. 6
      html_text/tests/test_extractor.py

2
html_text/models/ir_fields_converter.py

@ -41,7 +41,7 @@ class IrFieldsConverter(models.Model):
# Parse HTML # Parse HTML
try: try:
doc = html.fromstring(html_content) doc = html.fromstring(html_content)
except (etree.XMLSyntaxError, etree.ParserError):
except (TypeError, etree.XMLSyntaxError, etree.ParserError):
if fail: if fail:
raise raise
else: else:

6
html_text/tests/test_extractor.py

@ -46,6 +46,12 @@ class ExtractorCase(TransactionCase):
with self.assertRaises(etree.XMLSyntaxError): with self.assertRaises(etree.XMLSyntaxError):
self.text_from_html("", fail=True) self.text_from_html("", fail=True)
def test_false_html(self):
"""``False`` HTML handled correctly."""
self.assertEqual(self.text_from_html(False), "")
with self.assertRaises(TypeError):
self.text_from_html(False, fail=True)
def test_bad_html(self): def test_bad_html(self):
"""Bad HTML handled correctly.""" """Bad HTML handled correctly."""
self.assertEqual(self.text_from_html("<<bad>"), "") self.assertEqual(self.text_from_html("<<bad>"), "")

Loading…
Cancel
Save