Skip to content

Commit

Permalink
1.2dev: Merge [14490] from 1.0-stable
Browse files Browse the repository at this point in the history
Fix test cases that were failing on trunk, but not present
on 1.0-stable branch.

Refs #12326.


git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@14491 af82e41b-90c4-0310-8c96-b1721e28e2e2
  • Loading branch information
rjollos committed Jan 21, 2016
1 parent 664cf06 commit 053406e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
13 changes: 13 additions & 0 deletions trac/mimeview/tests/pygments.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,29 @@ <h1>Pygments Renderer Test Cases</h1>
<div id="python_hello">
<span class="k">def</span> <span class="nf">hello</span><span class="p">():</span>
<span class="k">return</span> <span class="s">"Hello World!"</span>
</div>
<div id="python_hello_pygments_2.1plus">
<span class="k">def</span> <span class="nf">hello</span><span class="p">():</span>
<span class="k">return</span> <span class="s2">"Hello World!"</span>
</div>
<div id="python_hello_mimeview"><div class="code"><pre>
<span class="k">def</span> <span class="nf">hello</span><span class="p">():</span>
<span class="k">return</span> <span class="s">"Hello World!"</span>
</pre></div></div>
<div id="python_hello_mimeview_pygments_2.1plus"><div class="code"><pre>
<span class="k">def</span> <span class="nf">hello</span><span class="p">():</span>
<span class="k">return</span> <span class="s2">"Hello World!"</span>
</pre></div></div>
<div id="python_with_lineno_1"><div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">&nbsp;</th></tr></thead><tbody><tr><th id="a-L1"><a href="#a-L1">1</a></th><td><span class="k">print</span>&nbsp;<span class="s">'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>&nbsp;b<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>&nbsp;<span class="s">"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>&nbsp;<span class="s">'this is the end of the python sample'</span></td></tr></tbody></table></div></div>
<div id="python_with_lineno_1_pygments_2.1plus"><div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">&nbsp;</th></tr></thead><tbody><tr><th id="a-L1"><a href="#a-L1">1</a></th><td><span class="k">print</span>&nbsp;<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>&nbsp;b<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>&nbsp;<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>&nbsp;<span class="s1">'this is the end of the python sample'</span></td></tr></tbody></table></div></div>
<div id="python_with_lineno_2"><div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">&nbsp;</th></tr></thead><tbody><tr><th id="a-L3"><a href="#a-L3">3</a></th><td><span class="k">print</span>&nbsp;<span class="s">'this is a python sample'</span></td></tr><tr><th id="a-L4"><a href="#a-L4">4</a></th><td>a <span class="o">=</span>&nbsp;b<span class="o">+</span><span class="mi">3</span></td></tr><tr><th id="a-L5"><a href="#a-L5">5</a></th><td>z <span class="o">=</span>&nbsp;<span class="s">"this is a string"</span></td></tr><tr><th id="a-L6"><a href="#a-L6">6</a></th><td><span class="k">print</span>&nbsp;<span class="s">'this is the end of the python sample'</span></td></tr></tbody></table></div></div>
<div id="python_with_lineno_2_pygments_2.1plus"><div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">&nbsp;</th></tr></thead><tbody><tr><th id="a-L3"><a href="#a-L3">3</a></th><td><span class="k">print</span>&nbsp;<span class="s1">'this is a python sample'</span></td></tr><tr><th id="a-L4"><a href="#a-L4">4</a></th><td>a <span class="o">=</span>&nbsp;b<span class="o">+</span><span class="mi">3</span></td></tr><tr><th id="a-L5"><a href="#a-L5">5</a></th><td>z <span class="o">=</span>&nbsp;<span class="s2">"this is a string"</span></td></tr><tr><th id="a-L6"><a href="#a-L6">6</a></th><td><span class="k">print</span>&nbsp;<span class="s1">'this is the end of the python sample'</span></td></tr></tbody></table></div></div>
<div id="python_with_lineno_and_markups"><div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">&nbsp;</th></tr></thead><tbody><tr><th id="b-L3"><a href="#b-L3">3</a></th><td><span class="k">print</span>&nbsp;<span class="s">'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>&nbsp;b<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>&nbsp;<span class="s">"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>&nbsp;<span class="s">'this is the end of the python sample'</span></td></tr></tbody></table></div></div>
<div id="python_with_lineno_and_markups_pygments_2.1plus"><div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">&nbsp;</th></tr></thead><tbody><tr><th id="b-L3"><a href="#b-L3">3</a></th><td><span class="k">print</span>&nbsp;<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>&nbsp;b<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>&nbsp;<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>&nbsp;<span class="s1">'this is the end of the python sample'</span></td></tr></tbody></table></div></div>
<div id="python_with_invalid_arguments_1"><div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">&nbsp;</th></tr></thead><tbody><tr><th id="a-L1"><a href="#a-L1">1</a></th><td><span class="k">print</span>&nbsp;<span class="s">'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>&nbsp;b<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>&nbsp;<span class="s">"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>&nbsp;<span class="s">'this is the end of the python sample'</span></td></tr></tbody></table></div></div>
<div id="python_with_invalid_arguments_1_pygments_2.1plus"><div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">&nbsp;</th></tr></thead><tbody><tr><th id="a-L1"><a href="#a-L1">1</a></th><td><span class="k">print</span>&nbsp;<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>&nbsp;b<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>&nbsp;<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>&nbsp;<span class="s1">'this is the end of the python sample'</span></td></tr></tbody></table></div></div>
<div id="python_with_invalid_arguments_2"><div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">&nbsp;</th></tr></thead><tbody><tr><th id="d-L1"><a href="#d-L1">1</a></th><td><span class="k">print</span>&nbsp;<span class="s">'this is a python sample'</span></td></tr><tr><th id="d-L2"><a href="#d-L2">2</a></th><td>a <span class="o">=</span>&nbsp;b<span class="o">+</span><span class="mi">3</span></td></tr><tr><th id="d-L3"><a href="#d-L3">3</a></th><td>z <span class="o">=</span>&nbsp;<span class="s">"this is a string"</span></td></tr><tr><th id="d-L4"><a href="#d-L4">4</a></th><td><span class="k">print</span>&nbsp;<span class="s">'this is the end of the python sample'</span></td></tr></tbody></table></div></div>
<div id="python_with_invalid_arguments_2_pygments_2.1plus"><div class="wiki-code"><table class="code"><thead><tr><th class="lineno" title="Line numbers">Line</th><th class="content">&nbsp;</th></tr></thead><tbody><tr><th id="d-L1"><a href="#d-L1">1</a></th><td><span class="k">print</span>&nbsp;<span class="s1">'this is a python sample'</span></td></tr><tr><th id="d-L2"><a href="#d-L2">2</a></th><td>a <span class="o">=</span>&nbsp;b<span class="o">+</span><span class="mi">3</span></td></tr><tr><th id="d-L3"><a href="#d-L3">3</a></th><td>z <span class="o">=</span>&nbsp;<span class="s2">"this is a string"</span></td></tr><tr><th id="d-L4"><a href="#d-L4">4</a></th><td><span class="k">print</span>&nbsp;<span class="s1">'this is the end of the python sample'</span></td></tr></tbody></table></div></div>
<div id="pygments_lexer_options"><div class="wiki-code"><div class="code"><pre><span class="k">if</span> <span class="p">(</span><span class="nx">class_exists</span><span class="p">(</span><span class="s1">'MyClass'</span><span class="p">))</span> <span class="p">{</span>
<span class="nv">$myclass</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">MyClass</span><span class="p">();</span>
<span class="p">}</span>
Expand Down
51 changes: 40 additions & 11 deletions trac/mimeview/tests/pygments.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import os
import unittest
from pkg_resources import parse_version

from genshi.core import Stream, TEXT
from genshi.input import HTMLParser
Expand All @@ -30,11 +31,16 @@
if have_pygments:
from trac.mimeview.pygments import PygmentsRenderer
from trac.test import EnvironmentStub, Mock
from trac.util import get_pkginfo
from trac.web.chrome import Chrome, web_context
from trac.web.href import Href
from trac.wiki.formatter import format_to_html


if have_pygments:
pygments_version = parse_version(get_pkginfo(pygments).get('version'))


class PygmentsRendererTestCase(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -73,7 +79,10 @@ def hello():
return "Hello World!"
""")
self.assertTrue(result)
self._test('python_hello', result)
if pygments_version < parse_version('2.1'):
self._test('python_hello', result)
else:
self._test('python_hello_pygments_2.1plus', result)

def test_python_hello_mimeview(self):
"""
Expand All @@ -84,7 +93,10 @@ def hello():
return "Hello World!"
""")
self.assertTrue(result)
self._test('python_hello_mimeview', result)
if pygments_version < parse_version('2.1'):
self._test('python_hello_mimeview', result)
else:
self._test('python_hello_mimeview_pygments_2.1plus', result)

def test_python_with_lineno(self):
result = format_to_html(self.env, self.context, """\
Expand All @@ -96,7 +108,10 @@ def test_python_with_lineno(self):
}}}
""")
self.assertTrue(result)
self._test('python_with_lineno_1', result)
if pygments_version < parse_version('2.1'):
self._test('python_with_lineno_1', result)
else:
self._test('python_with_lineno_1_pygments_2.1plus', result)

result = format_to_html(self.env, self.context, """\
{{{#!text/x-python lineno=3
Expand All @@ -107,7 +122,10 @@ def test_python_with_lineno(self):
}}}
""")
self.assertTrue(result)
self._test('python_with_lineno_2', result)
if pygments_version < parse_version('2.1'):
self._test('python_with_lineno_2', result)
else:
self._test('python_with_lineno_2_pygments_2.1plus', result)

def test_python_with_lineno_and_markups(self):
"""Python highlighting with Pygments and lineno annotator
Expand All @@ -121,7 +139,10 @@ def test_python_with_lineno_and_markups(self):
}}}
""")
self.assertTrue(result)
self._test('python_with_lineno_and_markups', result)
if pygments_version < parse_version('2.1'):
self._test('python_with_lineno_and_markups', result)
else:
self._test('python_with_lineno_and_markups_pygments_2.1plus', result)

def test_python_with_invalid_arguments(self):
result = format_to_html(self.env, self.context, """\
Expand All @@ -133,7 +154,10 @@ def test_python_with_invalid_arguments(self):
}}}
""")
self.assertTrue(result)
self._test('python_with_invalid_arguments_1', result)
if pygments_version < parse_version('2.1'):
self._test('python_with_invalid_arguments_1', result)
else:
self._test('python_with_invalid_arguments_1_pygments_2.1plus', result)

result = format_to_html(self.env, self.context, """\
{{{#!text/x-python lineno=a id=d marks=a-b
Expand All @@ -144,7 +168,10 @@ def test_python_with_invalid_arguments(self):
}}}
""")
self.assertTrue(result)
self._test('python_with_invalid_arguments_2', result)
if pygments_version < parse_version('2.1'):
self._test('python_with_invalid_arguments_2', result)
else:
self._test('python_with_invalid_arguments_2_pygments_2.1plus', result)

def test_pygments_lexer_options(self):
self.env.config.set('pygments-lexer',
Expand Down Expand Up @@ -222,10 +249,12 @@ def test_extra_mimetypes(self):
Pygments supports it.
"""
mimeview = Mimeview(self.env)
self.assertEqual('text/x-ini; charset=utf-8',
mimeview.get_mimetype('file.ini'))
self.assertEqual('text/x-ini; charset=utf-8',
mimeview.get_mimetype('file.cfg'))
self.assertIn(mimeview.get_mimetype('file.ini'),
('text/x-ini; charset=utf-8',
'text/inf; charset=utf-8')) # Pygment 2.1+
self.assertIn(mimeview.get_mimetype('file.cfg'),
('text/x-ini; charset=utf-8',
'text/inf; charset=utf-8')) # Pygment 2.1+
self.assertEqual('text/x-ini; charset=utf-8',
mimeview.get_mimetype('file.text/x-ini'))

Expand Down

0 comments on commit 053406e

Please sign in to comment.