rennat / pynliner

Python CSS-to-inline-styles conversion tool for HTML using BeautifulSoup and cssutils
http://pythonhosted.org/pynliner/
180 stars 93 forks source link

Pass existing tests, add 16 additional tests & add the majority of CSS2 #15

Closed philipkimmey closed 11 years ago

philipkimmey commented 12 years ago

Hi there,

We wanted to use Pynliner over at Rover.com, but it didn't quite handle all of the CSS selectors we wanted.

Pynliner itself is sufficient, but soupselect.py really didn't work very well.

We've improved it and added several test cases for our needs.

Let us know if there're any changes that need to be made from a style perspective.

We've added support for:

rennat commented 12 years ago

Nice work! I haven't had a chance to look at it thoroughly yet but I do plan to merge these changes in. Thanks guys!

philipkimmey commented 12 years ago

Awesome - take your time, we're pretty content with where it is, though Thomas contributed a few more (failing) tests with more advanced/other selectors.

rennat commented 11 years ago

This really is nice work and I would like to merge this in but I'm still seeing the double comment test failure when run on my machine:

======================================================================
FAIL: test_double_comment (__main__.BeautifulSoupBugs)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests.py", line 210, in test_double_comment
    self.assertNotIn("<!--<!--", output)
AssertionError: '<!--<!--' unexpectedly found in u'<!--<!-- comment -->-->'

======================================================================
FAIL: test_double_doctype (__main__.BeautifulSoupBugs)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests.py", line 205, in test_double_doctype
    self.assertNotIn("<!<!", output)
AssertionError: '<!<!' unexpectedly found in u'<!<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">>'

My testing environment:

$ python --version
Python 2.7.2
$ pip freeze
BeautifulSoup==3.2.0
Jinja2==2.6
Pygments==1.4
Sphinx==1.0.7
cssutils==0.9.8a3
docutils==0.8
wsgiref==0.1.2
rennat commented 11 years ago

After creating a clean virtualenv and installing your version of pynliner these package versions changed and all but one test pass.

$ pip freeze
BeautifulSoup==3.2.1
cssutils==0.9.10b1

$ python tests.py 
.............................................F....
======================================================================
FAIL: test_unknown_pseudo_selector (__main__.ComplexSelectors)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests.py", line 275, in test_unknown_pseudo_selector
    self.assertEqual(output, expected)
AssertionError: u'<h1><span style="color: red">Hello World!</span><p>foo</p><div class="barclass [truncated]... != u'<h1><span>Hello World!</span><p>foo</p><div class="barclass"><span>baz</span>b [truncated]...
- <h1><span style="color: red">Hello World!</span><p>foo</p><div class="barclass"><span>baz</span>bar</div></h1>
?          -------------------
+ <h1><span>Hello World!</span><p>foo</p><div class="barclass"><span>baz</span>bar</div></h1>

----------------------------------------------------------------------
Ran 50 tests in 0.142s

FAILED (failures=1)

If you resolve the version requirements to BeautifulSoup >=3.2.1, <4.0 I will merge this in and trigger a build.