Opened 8 years ago
Last modified 8 years ago
#12326 closed defect
Test failures with Pygments 2.1 — at Version 6
Reported by: | Ryan J Ollos | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Milestone: | 1.0.10 |
Component: | rendering | Version: | |
Severity: | normal | Keywords: | pygments |
Cc: | Branch: | ||
Release Notes: |
Fixed failing test cases with Pygments 2.1. |
||
API Changes: | |||
Internal Changes: |
Description
The automated tests that ran when committing the fix for #12325 revealed some test case failures. Pygments 2.1 was released on 2016-01-17. Test failures were not seen with Pygments 2.0.2.
====================================================================== FAIL: test_extra_mimetypes (trac.mimeview.tests.pygments.PygmentsRendererTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/mimeview/tests/pygments.py", line 123, in test_extra_mimetypes mimeview.get_mimetype('file.ini')) AssertionError: 'text/x-ini; charset=utf-8' != u'text/inf; charset=utf-8' ====================================================================== FAIL: test_python_hello (trac.mimeview.tests.pygments.PygmentsRendererTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/mimeview/tests/pygments.py", line 74, in test_python_hello self._test('python_hello', result) File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/mimeview/tests/pygments.py", line 62, in _test self.assertEqual(exp, res) AssertionError: ' <span class="k">return</span> <span class="s">"Hello World!"</span>' != ' <span class="k">return</span> <span class="s2">"Hello World!"</span>' ====================================================================== FAIL: test_python_hello_mimeview (trac.mimeview.tests.pygments.PygmentsRendererTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/mimeview/tests/pygments.py", line 85, in test_python_hello_mimeview self._test('python_hello_mimeview', result) File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/mimeview/tests/pygments.py", line 62, in _test self.assertEqual(exp, res) AssertionError: ' <span class="k">return</span> <span class="s">"Hello World!"</span>' != ' <span class="k">return</span> <span class="s2">"Hello World!"</span>' ---------------------------------------------------------------------- Ran 1795 tests in 108.513s FAILED (failures=3) make: *** [unit-test] Error 1
Change History (6)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
Now I remember looking at this some time ago. When there are multiple mimetypes for a given Short name (also referred to as aliases and keywords), the last mimetype overwrites the previously stored mimetype: tags/trac-1.0.9/trac/mimeview/api.py@:932-933#L922.
So I imagine we can fix this similar to how we fix the Babel tests when the CLDR data is updated:
-
trac/mimeview/tests/pygments.py
diff --git a/trac/mimeview/tests/pygments.py b/trac/mimeview/tests/pygments.py index 9bf92fc..d6ffd41 100644
a b def hello(): 119 119 Pygments supports it. 120 120 """ 121 121 mimeview = Mimeview(self.env) 122 self.assertEqual('text/x-ini; charset=utf-8', 123 mimeview.get_mimetype('file.ini')) 124 self.assertEqual('text/x-ini; charset=utf-8', 125 mimeview.get_mimetype('file.cfg')) 122 self.assertIn(mimeview.get_mimetype('file.ini'), 123 ('text/x-ini; charset=utf-8', 124 'text/inf; charset=utf-8')) # Pygment 2.1+ 125 self.assertIn(mimeview.get_mimetype('file.cfg'), 126 ('text/x-ini; charset=utf-8', 127 'text/inf; charset=utf-8')) # Pygment 2.1+ 126 128 self.assertEqual('text/x-ini; charset=utf-8', 127 129 mimeview.get_mimetype('file.text/x-ini'))
comment:3 by , 8 years ago
Regarding second and third errors, in Pygments 2.1 strings are being assigned Token.Literal.String.Double
rather than Token.Literal.String
.
Pygments 2.1:
>>> from pygments.lexers import PythonLexer >>> pl = PythonLexer() >>> s = """ ... def hello(): ... return "Hello World!" ... """ >>> tokens = pl.get_tokens(s) >>> for t in tokens: ... print t ... (Token.Keyword, u'def') (Token.Text, u' ') (Token.Name.Function, u'hello') (Token.Punctuation, u'(') (Token.Punctuation, u')') (Token.Punctuation, u':') (Token.Text, u'\n') (Token.Text, u' ') (Token.Keyword, u'return') (Token.Text, u' ') (Token.Literal.String.Double, u'"') (Token.Literal.String.Double, u'Hello World!') (Token.Literal.String.Double, u'"') (Token.Text, u'\n')
Pygments 2.0.2:
>>> from pygments.lexers import get_lexer_by_name >>> lexer = get_lexer_by_name('ini') >>> lexer.mimetypes ['text/x-ini'] >>> from pygments.lexers import PythonLexer >>> pl = PythonLexer() >>> s = """ ... def hello(): ... return "Hello World!" ... """ >>> tokens = pl.get_tokens(s) >>> for t in tokens: ... print t ... (Token.Keyword, u'def') (Token.Text, u' ') (Token.Name.Function, u'hello') (Token.Punctuation, u'(') (Token.Punctuation, u')') (Token.Punctuation, u':') (Token.Text, u'\n') (Token.Text, u' ') (Token.Keyword, u'return') (Token.Text, u' ') (Token.Literal.String, u'"') (Token.Literal.String, u'Hello World!') (Token.Literal.String, u'"') (Token.Text, u'\n')
comment:5 by , 8 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
Proposed changes in log:rjollos.git:t12326_pygments_2.1.
comment:6 by , 8 years ago
Release Notes: | modified (diff) |
---|
First issue seems to be due to addition of a mimetype for
ini
.Pygments 2.1:
Pygments 2.0.2: