Edgewall Software
Modify

Opened 3 years ago

Closed 3 years ago

Last modified 2 years ago

#13229 closed defect (fixed)

Test failures with Pygments 2.5.2

Reported by: Jun Omae Owned by: Jun Omae
Priority: normal Milestone: 1.2.6
Component: wiki system Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Fixed test failures with Pygments 2.5.0 and later.

Description

https://travis-ci.org/edgewall/trac/jobs/619251349

Python: /home/travis/virtualenv/python2.7_with_system_site_packages/bin/python 

  Package        Version
  -------------------------------------------------------
  Python       : 2.7.12 (default, Nov 12 2018, 14:36:49) 
               : [GCC 5.4.0 20160609]
  Setuptools   : 42.0.2
  Pip          : 19.3.1
  Wheel        : 0.33.6
  Genshi       : 0.7.3 (with speedups)
  Babel        : 2.7.0
  sqlite3      : 2.6.0 (3.11.0)
  PySqlite     : not installed
  MySQLdb      : not installed
  Psycopg2     : not installed
  SVN bindings : 1.9.3 (r1718519)
  Mercurial    : 4.8
  Pygments     : 2.5.2
  Textile      : 3.0.4
  Pytz         : 2019.3
  Docutils     : 0.15.2
  Twill        : 0.9
  LXML         : 4.4.2
  coverage     : not installed
  figleaf      : not installed
======================================================================
FAIL: test_python_with_invalid_arguments (trac.mimeview.tests.pygments.PygmentsRendererTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/edgewall/trac/trac/mimeview/tests/pygments.py", line 160, in test_python_with_invalid_arguments
    self._test('python_with_invalid_arguments_1_pygments_2.1plus', result)
  File "/home/travis/build/edgewall/trac/trac/mimeview/tests/pygments.py", line 68, in _test
    self.assertEqual(exp, res)
AssertionError: u'<div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">\xa0</th></tr></thead><tbody><tr><th id="a-L1"><a href="#a-L1">1</a></th><td><span class="k">print</span>\xa0<span class="s1">\'this is a python sample\'</span></td></tr><tr><th id="a-L2"><a href="#a-L2">2</a></th><td>a <span class="o">=</span>\xa0b<span class="o">+</span><span class="mi">3</span></td></tr><tr><th id="a-L3"><a href="#a-L3">3</a></th><td>z <span class="o">=</span>\xa0<span class="s2">"this is a string"</span></td></tr><tr><th id="a-L4"><a href="#a-L4">4</a></th><td><span class="k">print</span>\xa0<span class="s1">\'this is the end of the python sample\'</span></td></tr></tbody></table></div>' != u'<div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">\xa0</th></tr></thead><tbody><tr><th id="a-L1"><a href="#a-L1">1</a></th><td><span class="nb">print</span>\xa0<span class="s1">\'this is a python sample\'</span></td></tr><tr><th id="a-L2"><a href="#a-L2">2</a></th><td>a <span class="o">=</span>\xa0b<span class="o">+</span><span class="mi">3</span></td></tr><tr><th id="a-L3"><a href="#a-L3">3</a></th><td>z <span class="o">=</span>\xa0<span class="s2">"this is a string"</span></td></tr><tr><th id="a-L4"><a href="#a-L4">4</a></th><td><span class="nb">print</span>\xa0<span class="s1">\'this is the end of the python sample\'</span></td></tr></tbody></table></div>'
Diff is 2671 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_python_with_lineno (trac.mimeview.tests.pygments.PygmentsRendererTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/edgewall/trac/trac/mimeview/tests/pygments.py", line 114, in test_python_with_lineno
    self._test('python_with_lineno_1_pygments_2.1plus', result)
  File "/home/travis/build/edgewall/trac/trac/mimeview/tests/pygments.py", line 68, in _test
    self.assertEqual(exp, res)
AssertionError: u'<div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">\xa0</th></tr></thead><tbody><tr><th id="a-L1"><a href="#a-L1">1</a></th><td><span class="k">print</span>\xa0<span class="s1">\'this is a python sample\'</span></td></tr><tr><th id="a-L2"><a href="#a-L2">2</a></th><td>a <span class="o">=</span>\xa0b<span class="o">+</span><span class="mi">3</span></td></tr><tr><th id="a-L3"><a href="#a-L3">3</a></th><td>z <span class="o">=</span>\xa0<span class="s2">"this is a string"</span></td></tr><tr><th id="a-L4"><a href="#a-L4">4</a></th><td><span class="k">print</span>\xa0<span class="s1">\'this is the end of the python sample\'</span></td></tr></tbody></table></div>' != u'<div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">\xa0</th></tr></thead><tbody><tr><th id="a-L1"><a href="#a-L1">1</a></th><td><span class="nb">print</span>\xa0<span class="s1">\'this is a python sample\'</span></td></tr><tr><th id="a-L2"><a href="#a-L2">2</a></th><td>a <span class="o">=</span>\xa0b<span class="o">+</span><span class="mi">3</span></td></tr><tr><th id="a-L3"><a href="#a-L3">3</a></th><td>z <span class="o">=</span>\xa0<span class="s2">"this is a string"</span></td></tr><tr><th id="a-L4"><a href="#a-L4">4</a></th><td><span class="nb">print</span>\xa0<span class="s1">\'this is the end of the python sample\'</span></td></tr></tbody></table></div>'
Diff is 2671 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_python_with_lineno_and_markups (trac.mimeview.tests.pygments.PygmentsRendererTestCase)
Python highlighting with Pygments and lineno annotator
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/edgewall/trac/trac/mimeview/tests/pygments.py", line 145, in test_python_with_lineno_and_markups
    self._test('python_with_lineno_and_markups_pygments_2.1plus', result)
  File "/home/travis/build/edgewall/trac/trac/mimeview/tests/pygments.py", line 68, in _test
    self.assertEqual(exp, res)
AssertionError: u'<div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">\xa0</th></tr></thead><tbody><tr><th id="b-L3"><a href="#b-L3">3</a></th><td><span class="k">print</span>\xa0<span class="s1">\'this is a python sample\'</span></td></tr><tr class="hilite"><th id="b-L4"><a href="#b-L4">4</a></th><td>a <span class="o">=</span>\xa0b<span class="o">+</span><span class="mi">3</span></td></tr><tr class="hilite"><th id="b-L5"><a href="#b-L5">5</a></th><td>z <span class="o">=</span>\xa0<span class="s2">"this is a string"</span></td></tr><tr><th id="b-L6"><a href="#b-L6">6</a></th><td><span class="k">print</span>\xa0<span class="s1">\'this is the end of the python sample\'</span></td></tr></tbody></table></div>' != u'<div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">\xa0</th></tr></thead><tbody><tr><th id="b-L3"><a href="#b-L3">3</a></th><td><span class="nb">print</span>\xa0<span class="s1">\'this is a python sample\'</span></td></tr><tr class="hilite"><th id="b-L4"><a href="#b-L4">4</a></th><td>a <span class="o">=</span>\xa0b<span class="o">+</span><span class="mi">3</span></td></tr><tr class="hilite"><th id="b-L5"><a href="#b-L5">5</a></th><td>z <span class="o">=</span>\xa0<span class="s2">"this is a string"</span></td></tr><tr><th id="b-L6"><a href="#b-L6">6</a></th><td><span class="nb">print</span>\xa0<span class="s1">\'this is the end of the python sample\'</span></td></tr></tbody></table></div>'
Diff is 2791 characters long. Set self.maxDiff to None to see it.

----------------------------------------------------------------------
Ran 2415 tests in 115.116s

FAILED (failures=3)
Makefile:449: recipe for target 'unit-test' failed
make: *** [unit-test] Error 1

Attachments (0)

Change History (4)

comment:1 by Jun Omae, 3 years ago

Owner: set to Jun Omae
Status: newassigned

Proposed changes in [083272488/jomae.git] (jomae.git@t13229).

Root cause is that PythonLexer class is an alias of Python3Lexer class since Pygmenets 2.5.0. See https://github.com/pygments/pygments/releases/tag/2.5.0.

Work around is to use text/x-python2 for Pygments 2.5.0+.

Another thing, it is difficult to search the differences in results of test failures. I think it might be nice to understand failures with html fragments rather than lines.

-        expected, result = expected.splitlines(), result.splitlines()
-        for exp, res in zip(expected, result):
-            self.assertEqual(exp, res)
-        self.assertEqual(len(expected), len(result))
+        self.assertEqual(re.split(r'(<[^>]*>)', expected),
+                         re.split(r'(<[^>]*>)', result))

Those changes are included in the proposed changes.

Example:

======================================================================
FAIL: test_python_with_invalid_arguments (trac.mimeview.tests.pygments.PygmentsRendererTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jun66j5/src/tracdev/git/trac/mimeview/tests/pygments.py", line 166, in test_python_with_invalid_arguments
    self._test('python_with_invalid_arguments_1_pygments_2.1plus', result)
  File "/home/jun66j5/src/tracdev/git/trac/mimeview/tests/pygments.py", line 75, in _test
    re.split(r'(<[^>]*>)', result))
AssertionError: Lists differ: [u'', u'<div class="wiki-code"... != [u'', u'<div class="wiki-code"...

First differing element 35:
u'<span class="k">'
u'<span class="nb">'

Diff is 1901 characters long. Set self.maxDiff to None to see it.

comment:2 by Ryan J Ollos, 3 years ago

Both changes look good!

comment:3 by Jun Omae, 3 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Thanks for the reviewing!

Committed in [17220] and merged in [17221-17222].

comment:4 by Ryan J Ollos, 2 years ago

Internal Changes: modified (diff)
Release Notes: modified (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.