Code

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#18027 closed Bug (fixed)

regressiontests.test_utils.tests.HTMLEqualTests.test_parsing_errors() fails with Python >=2.7.3

Reported by: Arfrever Owned by: nobody
Component: Testing framework Version: 1.4
Severity: Normal Keywords:
Cc: hertzog@…, charette.s@…, anssi.kaariainen@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

regressiontests.test_utils.tests.HTMLEqualTests.test_parsing_errors() fails with Python >=2.7.3, which contains improved HTMLParser.HTMLParser.

$ PYTHONPATH="." python2.7 tests/runtests.py --settings=test_sqlite -v2 test_utils.HTMLEqualTests.test_parsing_errors
Importing application test_utils
Creating test database for alias 'default' (':memory:')...
Creating tables ...
Creating table django_content_type
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_site
Creating table django_flatpage_sites
Creating table django_flatpage
Creating table django_redirect
Creating table django_session
Creating table django_comments
Creating table django_comment_flags
Creating table django_admin_log
Creating table test_utils_person
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
Creating test database for alias 'other' (':memory:')...
Creating tables ...
Creating table django_content_type
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_site
Creating table django_flatpage_sites
Creating table django_flatpage
Creating table django_redirect
Creating table django_session
Creating table django_comments
Creating table django_comment_flags
Creating table django_admin_log
Creating table test_utils_person
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
test_parsing_errors (regressiontests.test_utils.tests.HTMLEqualTests) ... FAIL

======================================================================
FAIL: test_parsing_errors (regressiontests.test_utils.tests.HTMLEqualTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/Django-1.4/tests/regressiontests/test_utils/tests.py", line 426, in test_parsing_errors
    parse_html('<!--')
AssertionError: HTMLParseError not raised

----------------------------------------------------------------------
Ran 1 test in 0.002s

FAILED (failures=1)
Destroying test database for alias 'default' (':memory:')...
Destroying test database for alias 'other' (':memory:')...
$ python2.6 -c 'import HTMLParser; parser = HTMLParser.HTMLParser(); parser.feed("<!--"); parser.close(); print(parser)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python2.6/HTMLParser.py", line 112, in close
    self.goahead(1)
  File "/usr/lib64/python2.6/HTMLParser.py", line 164, in goahead
    self.error("EOF in middle of construct")
  File "/usr/lib64/python2.6/HTMLParser.py", line 115, in error
    raise HTMLParseError(message, self.getpos())
HTMLParser.HTMLParseError: EOF in middle of construct, at line 1, column 1
$ python2.7 -c 'import HTMLParser; parser = HTMLParser.HTMLParser(); parser.feed("<!--"); parser.close(); print(parser)'
<HTMLParser.HTMLParser instance at 0x7fe49def5878>
$ python2.7 -c 'import sys; print(sys.version_info)'
sys.version_info(major=2, minor=7, micro=3, releaselevel='candidate', serial=2)

Attachments (1)

ticket_18027.diff (564 bytes) - added by akaariai 2 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 2 years ago by Raphaël Hertzog <hertzog@…>

  • Cc hertzog@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I have been bitten by this as well here on Debian Unstable while trying to update the python-django package.

comment:2 Changed 2 years ago by charettes

  • Cc charette.s@… added

Soon to be released Ubuntu Precise Pangolin 12.04 LTS which ships with python 2.7.3rc2 also trigger this issue when running the test suite.

comment:3 Changed 2 years ago by akaariai

  • Cc anssi.kaariainen@… added
  • Has patch set
  • Triage Stage changed from Unreviewed to Accepted

The Python commit that causes this failure in Django's test suite is this one: http://hg.python.org/cpython/rev/333e3acf2008/. The patch leads to this part of HTML5 standard: http://www.w3.org/TR/html5/tokenization.html#bogus-comment-state

Apparently if there is no closing tag, then the comment is still valid. Thus, I don't know if there is anything more to do than just remove the assertRaises for parse_html('<!--'). We could test conditionally on Python version but I don't see the point of that. What regression are we exactly testing against there? In any case we are mostly testing what HTMLParser does, not what our code does.

A patch for removing the test is attached. The patch should be back-patched.

Changed 2 years ago by akaariai

comment:4 Changed 2 years ago by charettes

  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 2 years ago by claudep

+1, this was my reasoning also.

comment:6 Changed 2 years ago by claudep

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

In [17900]:

Fixed #18027 -- Removed an HTMLParser test that doesn't raise any more in recent Python versions. Thanks Arfever and Anssi Kaariainen for the report and the patch.

comment:7 Changed 2 years ago by claudep

In [17901]:

(The changeset message doesn't reference this ticket)

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.