Merge lp:~jameinel/loggerhead/pygment-annotate-fail into lp:loggerhead

Proposed by John A Meinel
Status: Merged
Merged at revision: 427
Proposed branch: lp:~jameinel/loggerhead/pygment-annotate-fail
Merge into: lp:loggerhead
Diff against target: 51 lines (+19/-4)
1 file modified
loggerhead/tests/test_simple.py (+19/-4)
To merge this branch: bzr merge lp:~jameinel/loggerhead/pygment-annotate-fail
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Benji York (community) code* Approve
Review via email: mp+49312@code.launchpad.net

Commit message

Fix an "annotate" test that fails when pygments is installed.

Description of the change

I was running the test suite on another machine, and it seems having pygments installed causes on of the annotate tests to fail.

The point of the test was to assert that we properly escape the file content on the annotate page. It was doing so by making sure the text "with&lt;htmlspecialchars" was present. However, when pygments is installed, it highlights the "&lt;" with custom <span> entries.

So this changes it to just use a regex that can match either way. I've tested it on both machines, and the test still passes.

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

The "with.*&lt;.*htmlspecialchars" regex feels a bit too liberal. How
about something like this?

    # remove any pygments-inserted tags
    body = re.sub('<[^>]+>', '', res.body)
    self.assertContains(body, "with&lt;htmlspecialchars")

Also, I suspect judicious use of a clean Python and buildout would help
with this scenario, providing reproducible builds isolated from the
environment. If you're interested I'd be glad to help craft a buildout
for the project.

Regardless, the branch is certainly approvable as is, so I've done so.
Note that this is a mentored review so Brad will be reviewing my review
and giving the final approval.

review: Approve (code*)
Revision history for this message
Brad Crittenden (bac) wrote :

Hi John,

s/pigments/pygments/

Your comment at 37 is a bit misleading as it only happens if pygments is installed. Perhaps reword that statement to remove references to "now" since it isn't an on-going issue but only if pygments is installed.

I like Benji's suggestion to clean up the results rather than match something that is overly broad.

review: Approve (code)
Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2/11/2011 2:00 PM, Brad Crittenden wrote:
> Review: Approve code
> Hi John,
>
> s/pigments/pygments/
>
> Your comment at 37 is a bit misleading as it only happens if pygments is installed. Perhaps reword that statement to remove references to "now" since it isn't an on-going issue but only if pygments is installed.
>
> I like Benji's suggestion to clean up the results rather than match something that is overly broad.

Thanks. I went with just stripping all <span class="pyg-."> entries and
all </span> entries. Which gives the same basic results.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1Vt+cACgkQJdeBCYSNAANxEwCgu2nuYuQYgzTANHdQCN6MnbfK
r40AoMuWFmgQNBY/zVYG3WKlqKwIKUES
=5992
-----END PGP SIGNATURE-----

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2/11/2011 12:29 PM, Benji York wrote:
> Review: Approve code*
> The "with.*&lt;.*htmlspecialchars" regex feels a bit too liberal. How
> about something like this?
>
> # remove any pygments-inserted tags
> body = re.sub('<[^>]+>', '', res.body)
> self.assertContains(body, "with&lt;htmlspecialchars")
>
> Also, I suspect judicious use of a clean Python and buildout would help
> with this scenario, providing reproducible builds isolated from the
> environment. If you're interested I'd be glad to help craft a buildout
> for the project.

The thing is, we *want* pygments to be installed for Loggerhead, so that
it can highlight source code when you are looking at the View content pages.

It is just a soft dependency. If we had a PQM testing loggerhead trunk,
we would want it to be there.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1VuG4ACgkQJdeBCYSNAAPu4QCg07Wxew98U8Xgsm+xIaMZzpPQ
hUoAoL7jF1N5qTOUCdeyQWz/Y/3esJoN
=G10t
-----END PGP SIGNATURE-----

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loggerhead/tests/test_simple.py'
2--- loggerhead/tests/test_simple.py 2009-06-08 23:02:49 +0000
3+++ loggerhead/tests/test_simple.py 2011-02-10 22:20:26 +0000
4@@ -1,4 +1,4 @@
5-# Copyright (C) 2008, 2009 Canonical Ltd.
6+# Copyright (C) 2007-2011 Canonical Ltd.
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10@@ -61,7 +61,7 @@
11 'with<htmlspecialchars\n')
12 self.build_tree_contents(
13 [('myfilename', self.filecontents)])
14- self.tree.add('myfilename')
15+ self.tree.add('myfilename', 'myfile-id')
16 self.fileid = self.tree.path2id('myfilename')
17 self.msg = 'a very exciting commit message <'
18 self.revid = self.tree.commit(message=self.msg)
19@@ -71,6 +71,11 @@
20 res = app.get('/changes')
21 res.mustcontain(cgi.escape(self.msg))
22
23+ def test_changes_for_file(self):
24+ app = self.setUpLoggerhead()
25+ res = app.get('/changes?filter_file_id=myfile-id')
26+ res.mustcontain(cgi.escape(self.msg))
27+
28 def test_changes_branch_from(self):
29 app = self.setUpLoggerhead(served_url="lp:loggerhead")
30 res = app.get('/changes')
31@@ -88,8 +93,18 @@
32 def test_annotate(self):
33 app = self.setUpLoggerhead()
34 res = app.get('/annotate', params={'file_id': self.fileid})
35- for line in self.filecontents.splitlines():
36- res.mustcontain(cgi.escape(line))
37+ # This now fails because pigments is highlighting the lines.
38+ # Specifically, instead of getting:
39+ # 'with&lt;htmlspecialchars' we are now getting
40+ # '<span class='pyg-n'>with</span><span class='pyg-o'>&lt;</span>'
41+ # '<span class='pyg-n'>htmlspecialchars</span>
42+ # So pygments is breaking up the special characters with custom
43+ # highlighting. The alternative is to figure out how to disable
44+ # pygments for this test.
45+ ## for line in self.filecontents.splitlines():
46+ ## res.mustcontain(cgi.escape(line))
47+ self.assertContainsRe(res.body,
48+ "with.*&lt;.*htmlspecialchars")
49
50 def test_inventory(self):
51 app = self.setUpLoggerhead()

Subscribers

People subscribed via source and target branches