Code

Opened 2 years ago

Closed 2 years ago

#17641 closed Bug (fixed)

HTMLParser has no interesting_cdata attribute with a Python version > 2.7.2

Reported by: ramiro Owned by: nobody
Component: Testing framework Version: master
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)

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 2 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 2 years ago by ramiro

  • Description modified (diff)
  • Has patch set

Changed 2 years ago by ramiro

comment:2 Changed 2 years ago by lrekucki

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 2 years ago by lrekucki (previous) (diff)

comment:3 Changed 2 years ago by ramiro

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]
Version 0, edited 2 years ago by ramiro (next)

comment:4 Changed 2 years ago by ramiro

  • Summary changed from HTMLParser has no interesting_cdata attribute with a Python version > 2.7.1 to HTMLParser has no interesting_cdata attribute with a Python version > 2.7.2

comment:5 Changed 2 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.