Opened 13 years ago

Closed 13 years ago

#17641 closed Bug (fixed)

HTMLParser has no interesting_cdata attribute with a Python version > 2.7.2

Reported by: Ramiro Morales Owned by: nobody
Component: Testing framework Version: dev
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ramiro Morales)

Our recent enhancements to the HTML content checking assertions in our test utils subclass and customizes standard library HTMLParser. But in recent HTMLParser shipped with recent 2.7.x CPythons there is no more a interesting_cdata module-level RE variable.

This results in 15 errors in our test suite like this

======================================================================
ERROR: test_readonly_get (regressiontests.admin_views.tests.ReadonlyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/regressiontests/admin_views/tests.py", line 2861, in test_readonly_get
    self.assertContains(response, '<p class="help">Some help text for the title (with unicode ŠĐĆŽćžšđ)</p>', html=True)
  File "django/test/testcases.py", line 627, in assertContains
    u"Response's content is not valid HTML:")
  File "django/test/testcases.py", line 87, in assert_and_parse_html
    dom = parse_html(html)
  File "django/test/html.py", line 213, in parse_html
    parser.feed(html)
  File "/usr/lib/python2.7/HTMLParser.py", line 111, in feed
    self.goahead(0)
  File "/usr/lib/python2.7/HTMLParser.py", line 155, in goahead
    k = self.parse_starttag(i)
  File "django/utils/htmlparser.py", line 68, in parse_starttag
    self.set_cdata_mode(tag) # <--------------------------- Changed
  File "django/utils/htmlparser.py", line 14, in set_cdata_mode
    self.interesting = _HTMLParser.interesting_cdata
AttributeError: 'module' object has no attribute 'interesting_cdata'

See:

Our CI server is using an older 2.7.x Python.

Attachments (1)

17641-1.diff (649 bytes ) - added by Ramiro Morales 13 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by Ramiro Morales, 13 years ago

Description: modified (diff)
Has patch: set

by Ramiro Morales, 13 years ago

Attachment: 17641-1.diff added

comment:2 by Łukasz Rekucki, 13 years ago

I run the test mentioned in the report on Python 2.7.2 and latest trunk:

(django)lrekucki@blizzard:~/django/django_lqc/tests {master *}$ python --version
Python 2.7.2
(django)lrekucki@blizzard:~/django/django_lqc/tests {master *}$ PYTHONPATH=.. python runtests.py --settings=test_sqlite admin_views.ReadonlyTest
Creating test database for alias 'default'...
Creating test database for alias 'other'...
...
----------------------------------------------------------------------
Ran 3 tests in 1.035s

OK
Destroying test database for alias 'default'...
Destroying test database for alias 'other'...

Edit: so I guess this change in Python hasn't been released yet (or my distro suppresed it).

Last edited 13 years ago by Łukasz Rekucki (previous) (diff)

comment:3 by Ramiro Morales, 13 years ago

Ah I'm running the test on Debian unstable, and now I understand why it reports '2.7.2+' as its version. Most surely it includes fixes post 2.7.2

$ python -c 'import sys ; print("Python version: %s" % sys.version)'
Python version: 2.7.2+ (default, Jan 20 2012, 23:05:38) 
[GCC 4.6.2]
Last edited 13 years ago by Ramiro Morales (previous) (diff)

comment:4 by Ramiro Morales, 13 years ago

Summary: HTMLParser has no interesting_cdata attribute with a Python version > 2.7.1HTMLParser has no interesting_cdata attribute with a Python version > 2.7.2

comment:5 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: newclosed

In [17456]:

Fixed #17641 -- Work around an issue in Python distributions that remove the module attribute ('2.7.2+'). Many thanks to Ramiro Morales for finding it.

Note: See TracTickets for help on using tickets.
Back to Top