jseutter/ofxparse — pull request #65 by danc86 (2014-01-07 00:43:23+00:00)
Title: Test failures when lxml is not installed, due to parsing differences in BeautifulSoup

When the ofxparse test suite is run without lxml installed, there are two failures:

```
======================================================================
FAIL: testEmptyFile (tests.test_parse.TestParse)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/builddir/build/BUILD/ofxparse-0.14/tests/test_parse.py", line 212, in testEmptyFile
self.assertRaises(OfxParserException, OfxParser.parse, fh)
AssertionError: OfxParserException not raised
======================================================================
FAIL: testThatParseFailsIfNothingToParse (tests.test_parse.TestParse)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/builddir/build/BUILD/ofxparse-0.14/tests/test_parse.py", line 218, in testThatParseFailsIfNothingToParse
self.assertRaises(TypeError, OfxParser.parse, None)
AssertionError: TypeError not raised
----------------------------------------------------------------------
```

The reason for the failures is that BeautifulSoup has some slightly different behaviour for certain pathological inputs, depending on whether it's using lxml or has fallen back to... whatever other parser it uses (HTMLParser from the standard library?). The problem is only noticeable on Python 2.6 as well, which probably means that the standard library's behaviour changed across releases.

Without lxml installed:

```
[root@galangal /]# python -c 'from bs4 import BeautifulSoup; print BeautifulSoup(None)'

None

```

With lxml installed:

```
[root@galangal /]# python -c 'from bs4 import BeautifulSoup; print BeautifulSoup(None)'
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.6/site-packages/bs4/__init__.py", line 169, in __init__
self.builder.prepare_markup(markup, from_encoding))
File "/usr/lib/python2.6/site-packages/bs4/builder/_lxml.py", line 68, in prepare_markup
dammit = UnicodeDammit(markup, try_encodings, is_html=True)
File "/usr/lib/python2.6/site-packages/bs4/dammit.py", line 203, in __init__
self._detectEncoding(markup, is_html)
File "/usr/lib/python2.6/site-packages/bs4/dammit.py", line 373, in _detectEncoding
xml_encoding_match = xml_encoding_re.match(xml_data)
TypeError: expected string or buffer
```

Similarly, without lxml installed:

```
>>> BeautifulSoup(six.BytesIO('')).contents
[

]
```

With lxml installed:

```
>>> BeautifulSoup(six.BytesIO('')).contents
[]
```