annotate tests/test_template_keywords.py @ 717:ae5968ffe6fe

svnwrap: fix handling of quotable URLs (fixes #197, refs #132) The way hgsubversion handles URLs that may or may not be quoted is somewhat fragile. As part of fixing issue 132 in 925ff8c5989c, the path component of URLs was always quoted. The URL has been attempted encoded since the initial check-in. The fix from 925ff8c5989c was incomplete; reverting it allows us to clone a URL with a '~' in it.[1] Encoding the URL as UTF-8 seldom works as expected, as the default string encoding is ASCII, causing Python to be unable to decode any URL containing an 8-bit character. The core problem here is that we don't know whether the URL specified by the user is quoted or not. Rather than trying to deal with this ourselves, we pass the problem on to Subversion. Then, we obtain the URL from the RA instance, where it is always quoted. (It's worth noting that the editor interface, on the other hand, always deals with unquoted paths...) Thus, the following invariants should apply to SubversionRepo attributes: - svn_url and root will always be quoted. - subdir will always be unquoted. Tests are added that verify that it won't affect the conversion whether a URL is specified in quoted or unquoted form. Furthermore, a test fixture for this is added *twice*, so that we can thoroughly test both quoted and unquoted URLs. I'm not adding a test dedicated to tildes in URLs; it doesn't seem necessary. [1] Such as <https://svn.kenai.com/svn/winsw~subversion>.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Mon, 04 Oct 2010 21:00:36 -0500
parents cb32d90f915e
children af817963897e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
684
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
1 import test_util
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
2
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
3 import unittest
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
4
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
5 from mercurial import commands
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
6 from mercurial import ui
687
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
7 try:
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
8 from mercurial import templatekw
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
9 templatekw.keywords
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
10 except ImportError:
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
11 templatekw = None
684
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
12
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
13
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
14 class CapturingUI(ui.ui):
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
15
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
16 def __init__(self, *args, **kwds):
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
17 super(CapturingUI, self).__init__(*args, **kwds)
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
18 self._output = ""
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
19
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
20 def write(self, msg, *args, **kwds):
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
21 self._output += msg
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
22
707
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 687
diff changeset
23 class TestLogKeywords(test_util.TestBase):
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 687
diff changeset
24 if templatekw:
687
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
25 def test_svn_keywords(self):
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
26 defaults = {'date': None, 'rev': None, 'user': None}
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
27 repo = self._load_fixture_and_fetch('two_revs.svndump')
707
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 687
diff changeset
28
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 687
diff changeset
29 # we want one commit that isn't from Subversion
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 687
diff changeset
30 self.commitchanges([('foo', 'foo', 'frobnicate\n')])
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 687
diff changeset
31
687
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
32 ui = CapturingUI()
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
33 commands.log(ui, repo, template='{rev}:{svnrev} ', **defaults)
707
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 687
diff changeset
34 self.assertEqual(ui._output, '0:2 1:3 2: ')
687
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
35 ui = CapturingUI()
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
36 commands.log(ui, repo, template='{rev}:{svnpath} ', **defaults)
707
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 687
diff changeset
37 self.assertEqual(ui._output, '0:/trunk 1:/trunk 2: ')
687
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
38 ui = CapturingUI()
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
39 commands.log(ui, repo, template='{rev}:{svnuuid} ', **defaults)
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
40 self.assertEqual(ui._output,
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
41 ('0:df2126f7-00ab-4d49-b42c-7e981dde0bcf '
707
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 687
diff changeset
42 '1:df2126f7-00ab-4d49-b42c-7e981dde0bcf '
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 687
diff changeset
43 '2: '))
687
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
44
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
45
707
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 687
diff changeset
46 def suite():
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 687
diff changeset
47 all = [unittest.TestLoader().loadTestsFromTestCase(TestLogKeywords),]
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 687
diff changeset
48 return unittest.TestSuite(all)