Commits

anatoly techtonik committed f2ba7d7

Add tests from replacement code of bugs.python.org

Comments (0)

Files changed (2)

tests/data_python_tracker.txt

+## test data for test_local_replace.py - odd lines are plain text, even lines are linkified
+## lines starting with '##' are ignored, but they have to be in an even number
+##
+## more generic tests first to make them reusable for other trackers
+##
+## URLs (no HTML escaping)
+http://svn.python.org/view/python/tags/r265
+<a href="http://svn.python.org/view/python/tags/r265">http://svn.python.org/view/python/tags/r265</a>
+http://svn.python.org/view/python/tags/r265/Lib/cgi.py
+<a href="http://svn.python.org/view/python/tags/r265/Lib/cgi.py">http://svn.python.org/view/python/tags/r265/Lib/cgi.py</a>
+http://svn.python.org/view/python/tags/r265/Lib/cgi.py?view=markup
+<a href="http://svn.python.org/view/python/tags/r265/Lib/cgi.py?view=markup">http://svn.python.org/view/python/tags/r265/Lib/cgi.py?view=markup</a>
+http://bugs.python.org/issue1000
+<a href="http://bugs.python.org/issue1000">http://bugs.python.org/issue1000</a>
+http://svn.python.org/view/python/branches/release26-maint/Lib/socket.py?r1=83624&r2=83623&pathrev=83624
+<a href="http://svn.python.org/view/python/branches/release26-maint/Lib/socket.py?r1=83624&r2=83623&pathrev=83624">http://svn.python.org/view/python/branches/release26-maint/Lib/socket.py?r1=83624&r2=83623&pathrev=83624</a>
+see http://www.python.org/dev/peps/pep-3127/#removal-of-old-octal-syntax
+see <a href="http://www.python.org/dev/peps/pep-3127/#removal-of-old-octal-syntax">http://www.python.org/dev/peps/pep-3127/#removal-of-old-octal-syntax</a>
+see http://docs.python.org/whatsnew/2.6.html#pep-371-the-multiprocessing-package
+see <a href="http://docs.python.org/whatsnew/2.6.html#pep-371-the-multiprocessing-package">http://docs.python.org/whatsnew/2.6.html#pep-371-the-multiprocessing-package</a>
+http://bugs.python.org/file24624/Proposed-fix-of-issue14099-second.patch
+<a href="http://bugs.python.org/file24624/Proposed-fix-of-issue14099-second.patch">http://bugs.python.org/file24624/Proposed-fix-of-issue14099-second.patch</a>
+http://www.microsoft.com/downloads/details.aspx?familyid=32BC1BEE-A3F9-4C13-9C99-220B62A191EE&displaylang=en
+<a href="http://www.microsoft.com/downloads/details.aspx?familyid=32BC1BEE-A3F9-4C13-9C99-220B62A191EE&displaylang=en">http://www.microsoft.com/downloads/details.aspx?familyid=32BC1BEE-A3F9-4C13-9C99-220B62A191EE&displaylang=en</a>
+http://hg.python.org/sandbox/morph-devguide/shortlog/a92d431ef749
+<a href="http://hg.python.org/sandbox/morph-devguide/shortlog/a92d431ef749">http://hg.python.org/sandbox/morph-devguide/shortlog/a92d431ef749</a>
+http://bazaar.launchpad.net/~ipython-dev/ipython/trunk/annotate/head%3A/IPython/testing/_paramtestpy3.py
+<a href="http://bazaar.launchpad.net/~ipython-dev/ipython/trunk/annotate/head%3A/IPython/testing/_paramtestpy3.py">http://bazaar.launchpad.net/~ipython-dev/ipython/trunk/annotate/head%3A/IPython/testing/_paramtestpy3.py</a>
+##
+## emails
+fixed@europython.eu
+<a href="mailto:fixed@europython.eu">fixed@europython.eu</a>
+##
+## revisions - r12345, r 12345, rev12345, rev 12345, revision12345, revision 12345
+r2222
+<a href="http://hg.python.org/lookup/r2222">r2222</a>
+ r2222
+ <a href="http://hg.python.org/lookup/r2222">r2222</a>
+ r 2222
+ <a href="http://hg.python.org/lookup/r2222">r 2222</a>
+ r. 2222
+ <a href="http://hg.python.org/lookup/r2222">r. 2222</a>
+ rev2222
+ <a href="http://hg.python.org/lookup/r2222">rev2222</a>
+ rev  2222
+ <a href="http://hg.python.org/lookup/r2222">rev  2222</a>
+ rev.  2222
+ <a href="http://hg.python.org/lookup/r2222">rev.  2222</a>
+ revision2222
+ <a href="http://hg.python.org/lookup/r2222">revision2222</a>
+ revision 2222
+ <a href="http://hg.python.org/lookup/r2222">revision 2222</a>
+deadbeeffeed
+<a href="http://hg.python.org/lookup/deadbeeffeed">deadbeeffeed</a>
+wordthatendswithr 2222
+wordthatendswithr 2222
+I uploaded http://pypi.python.org/pypi/ctypesgen/0.r125
+I uploaded <a href="http://pypi.python.org/pypi/ctypesgen/0.r125">http://pypi.python.org/pypi/ctypesgen/0.r125</a>
+##
+##
+see the devguide.
+see the <a href="http://docs.python.org/devguide">devguide</a>.
+see http://docs.python.org/devguide/.
+see <a href="http://docs.python.org/devguide/">http://docs.python.org/devguide/</a>.
+see devguide/triaging.
+see <a href="http://docs.python.org/devguide/triaging">devguide/triaging</a>.
+see devguide/triaging.html.
+see <a href="http://docs.python.org/devguide/triaging.html">devguide/triaging.html</a>.
+see http://docs.python.org/devguide/committing.html#using-several-working-copies
+see <a href="http://docs.python.org/devguide/committing.html#using-several-working-copies">http://docs.python.org/devguide/committing.html#using-several-working-copies</a>
+see devguide/committing.html#using-several-working-copies
+see <a href="http://docs.python.org/devguide/committing.html#using-several-working-copies">devguide/committing.html#using-several-working-copies</a>
+see devguide/committing#using-several-working-copies
+see <a href="http://docs.python.org/devguide/committing#using-several-working-copies">devguide/committing#using-several-working-copies</a>
+##
+## issues - the lowest issue id on bugs.python.org is #1000, the highest is #1779871
+ #1
+ #1
+ #10
+ #10
+ #999
+ #999
+ # 999
+ # 999
+ #1020
+ #1020
+ #2000000
+ #2000000
+ # 2000000
+ # 2000000
+ #1234567890123
+ #1234567890123
+pyissue1000
+pyissue1000
+http://mail.python.org/pipermail/python-ideas/2011-October/thread.html#12459
+<a href="http://mail.python.org/pipermail/python-ideas/2011-October/thread.html#12459">http://mail.python.org/pipermail/python-ideas/2011-October/thread.html#12459</a>
+##
+## only msgs and files are linkified
+see version1000.
+see version1000.
+see version 1000.
+see version 1000.

tests/test_python_tracker.py

+import sys
+import unittest
+import os.path
+import re
+
+testdir = os.path.dirname(os.path.abspath(__file__))
+# add the dir where wikify.py is (i.e. one level up)
+sys.path.append(os.path.dirname(testdir))
+
+import wikify
+
+# --- configure rules
+substitutions = [
+    # URLs (adapted from Roundup)
+    # replacement does not escape HTML chars
+    (r'''(?x)\b
+         (
+          (ht|f)tp(s?)://                   # protocol
+          ([\w]+(:\w+)?@)?                  # username/password
+          ([\w\-]+)                         # hostname
+          ((\.[\w-]+)+)?                    # .domain.etc
+         |                                  # ... or ...
+          ([\w]+(:\w+)?@)?                  # username/password
+          www\.                             # "www."
+          ([\w\-]+\.)+                      # hostname
+          [\w]{2,5}                         # TLD
+         )
+         (:[\d]{1,5})?                      # port
+         (                                  # path etc.
+          /(
+            [\w\-$+*()@&=?/~\\#%.,;:!]*
+            [\w\-$+*()@&=?/~\\#%]             # end of URL
+           )
+         )?
+     ''', r'<a href="\0">\0</a>'),
+
+    # email
+    (r'\b[-+=%/\w\.]+@[\w\.\-]+', r'<a href="mailto:\0">\0</a>'),
+
+    # deadbeeffeed  (hashes with exactly twelve or forty chars)
+    (r'\b[a-fA-F0-9]{40}\b',
+     r'<a href="http://hg.python.org/lookup/\0">\0</a>'),
+    (r'\b(?P<revision>[a-fA-F0-9]{12})\b',
+     r'<a href="http://hg.python.org/lookup/\0">\0</a>'),
+
+    # r12345, r 12345, rev12345, rev. 12345, revision12345, revision 12345
+    (r'\b(?P<revstr>r\.?(ev\.?(ision)?)?\s*)(?P<revision>\d{4,})',
+     r'<a href="http://hg.python.org/lookup/r\4">\1\4</a>'),
+
+    # devguide
+    (r'\bdevguide(/\w+(\.html)?(#[\w-]+)?)?',
+     r'<a href="http://docs.python.org/\0">\0</a>'),
+]
+
+
+rules = [wikify.create_regexp_rule(a,b) for a,b in substitutions]
+
+class TestBugsPythonOrgData(unittest.TestCase):
+    def test_replacement(self):
+        self.maxDiff = None
+        # the test file contains the text on odd lines and the expected
+        # result on even ones, with comments starting with '##'
+        f = open(os.path.join(testdir, 'data_python_tracker.txt'))
+        for text, expected_result in zip(f, f):
+            if text.startswith('##') and expected_result.startswith('##'):
+                continue  # skip the comments
+            p = wikify.wikify(text, rules)
+            # decode the str -- Unicode strings have a better diff
+            self.assertEqual(p.decode(), expected_result.decode())
+
+# run the tests
+unittest.main()