Mercurial > hgsubversion
annotate tests/test_svnwrap.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 | 192a3f65837a |
children | e9af7eba88db |
rev | line source |
---|---|
643
d2ef7220a079
tests: import test_util as the first module in all relevant tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
642
diff
changeset
|
1 import test_util |
d2ef7220a079
tests: import test_util as the first module in all relevant tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
642
diff
changeset
|
2 |
347
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
3 import imp |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
4 import os |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
5 import subprocess |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
6 import shutil |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
7 import tempfile |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
8 import unittest |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
9 |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
10 from hgsubversion import svnwrap |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
11 |
481
e5a9c824ffbf
Make tearDown() be able to delete read-only files to avoid an exception when removing 'testrepo/db/format'
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
480
diff
changeset
|
12 import os |
e5a9c824ffbf
Make tearDown() be able to delete read-only files to avoid an exception when removing 'testrepo/db/format'
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
480
diff
changeset
|
13 import stat |
e5a9c824ffbf
Make tearDown() be able to delete read-only files to avoid an exception when removing 'testrepo/db/format'
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
480
diff
changeset
|
14 def force_rm(path): |
642
c2d606a1dc6f
tests: get rid of DOS line endings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
482
diff
changeset
|
15 os.chmod( |
c2d606a1dc6f
tests: get rid of DOS line endings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
482
diff
changeset
|
16 path, |
c2d606a1dc6f
tests: get rid of DOS line endings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
482
diff
changeset
|
17 os.stat(path).st_mode | stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH |
c2d606a1dc6f
tests: get rid of DOS line endings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
482
diff
changeset
|
18 ) |
481
e5a9c824ffbf
Make tearDown() be able to delete read-only files to avoid an exception when removing 'testrepo/db/format'
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
480
diff
changeset
|
19 os.remove(path) |
e5a9c824ffbf
Make tearDown() be able to delete read-only files to avoid an exception when removing 'testrepo/db/format'
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
480
diff
changeset
|
20 |
347
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
21 class TestBasicRepoLayout(unittest.TestCase): |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
22 def setUp(self): |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
23 self.tmpdir = tempfile.mkdtemp('svnwrap_test') |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
24 self.repo_path = '%s/testrepo' % self.tmpdir |
478
37304494cd15
No os.spawnvp() in Windows, use subprocess.call() instead
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
347
diff
changeset
|
25 subprocess.call(['svnadmin', 'create', self.repo_path,]) |
347
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
26 inp = open(os.path.join(os.path.dirname(__file__), 'fixtures', |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
27 'project_root_at_repo_root.svndump')) |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
28 proc = subprocess.call(['svnadmin', 'load', self.repo_path,], |
479
83fcb1cf6d8f
Avoid 'ValueError: close_fds is not supported on Windows platforms' exception
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
478
diff
changeset
|
29 stdin=inp, |
83fcb1cf6d8f
Avoid 'ValueError: close_fds is not supported on Windows platforms' exception
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
478
diff
changeset
|
30 close_fds=test_util.canCloseFds, |
347
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
31 stdout=subprocess.PIPE, |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
32 stderr=subprocess.STDOUT) |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
33 assert proc == 0 |
480
7fa100ae1a11
Avoid 'Abort: Illegal repository URL' exception
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
479
diff
changeset
|
34 self.repo = svnwrap.SubversionRepo(test_util.fileurl(self.repo_path)) |
347
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
35 |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
36 def tearDown(self): |
482
a42fb4f1716a
Reclaim repository object to avoid tearDown() failing to remove the open file 'testrepo/db/rep-cache.db'
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
481
diff
changeset
|
37 del self.repo |
481
e5a9c824ffbf
Make tearDown() be able to delete read-only files to avoid an exception when removing 'testrepo/db/format'
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
480
diff
changeset
|
38 shutil.rmtree(self.tmpdir, onerror=lambda func, path, e: force_rm(path)) |
347
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
39 |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
40 |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
41 def test_num_revs(self): |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
42 revs = list(self.repo.revisions()) |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
43 self.assertEqual(len(revs), 7) |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
44 r = revs[1] |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
45 self.assertEqual(r.revnum, 2) |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
46 self.assertEqual(sorted(r.paths.keys()), |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
47 ['trunk/alpha', 'trunk/beta', 'trunk/delta']) |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
48 for r in revs: |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
49 for p in r.paths: |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
50 # make sure these paths are always non-absolute for sanity |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
51 if p: |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
52 assert p[0] != '/' |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
53 revs = list(self.repo.revisions(start=3)) |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
54 self.assertEqual(len(revs), 4) |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
55 |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
56 class TestRootAsSubdirOfRepo(TestBasicRepoLayout): |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
57 def setUp(self): |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
58 self.tmpdir = tempfile.mkdtemp('svnwrap_test') |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
59 self.repo_path = '%s/testrepo' % self.tmpdir |
478
37304494cd15
No os.spawnvp() in Windows, use subprocess.call() instead
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
347
diff
changeset
|
60 subprocess.call(['svnadmin', 'create', self.repo_path,]) |
347
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
61 inp = open(os.path.join(os.path.dirname(__file__), 'fixtures', |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
62 'project_root_not_repo_root.svndump')) |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
63 ret = subprocess.call(['svnadmin', 'load', self.repo_path,], |
479
83fcb1cf6d8f
Avoid 'ValueError: close_fds is not supported on Windows platforms' exception
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
478
diff
changeset
|
64 stdin=inp, |
83fcb1cf6d8f
Avoid 'ValueError: close_fds is not supported on Windows platforms' exception
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
478
diff
changeset
|
65 close_fds=test_util.canCloseFds, |
347
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
66 stdout=subprocess.PIPE, |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
67 stderr=subprocess.STDOUT) |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
68 assert ret == 0 |
480
7fa100ae1a11
Avoid 'Abort: Illegal repository URL' exception
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
479
diff
changeset
|
69 self.repo = svnwrap.SubversionRepo(test_util.fileurl( |
7fa100ae1a11
Avoid 'Abort: Illegal repository URL' exception
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
479
diff
changeset
|
70 self.repo_path + '/dummyproj' |
7fa100ae1a11
Avoid 'Abort: Illegal repository URL' exception
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
479
diff
changeset
|
71 )) |
7fa100ae1a11
Avoid 'Abort: Illegal repository URL' exception
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
479
diff
changeset
|
72 |
347
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
73 def suite(): |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
74 all = [unittest.TestLoader().loadTestsFromTestCase(TestBasicRepoLayout), |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
75 unittest.TestLoader().loadTestsFromTestCase(TestRootAsSubdirOfRepo)] |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
76 return unittest.TestSuite(all) |