Mercurial > hgsubversion
annotate tests/test_fetch_renames.py @ 90:4c419603d41b
fetch_command: create branch temporary directory when we need it
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Fri, 14 Nov 2008 16:18:24 -0600 |
parents | 072010a271c6 |
children | 7d10165cf3d9 |
rev | line source |
---|---|
67
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
1 import os |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
2 import shutil |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
3 import sys |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
4 import tempfile |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
5 import unittest |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
6 |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
7 from mercurial import hg |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
8 from mercurial import ui |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
9 from mercurial import node |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
10 |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
11 import fetch_command |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
12 import test_util |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
13 |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
14 |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
15 class TestFetchRenames(unittest.TestCase): |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
16 def setUp(self): |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
17 self.oldwd = os.getcwd() |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
18 self.tmpdir = tempfile.mkdtemp('svnwrap_test') |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
19 self.repo_path = '%s/testrepo' % self.tmpdir |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
20 self.wc_path = '%s/testrepo_wc' % self.tmpdir |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
21 |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
22 def tearDown(self): |
78
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
73
diff
changeset
|
23 test_util.rmtree(self.tmpdir) |
67
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
24 os.chdir(self.oldwd) |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
25 |
73
9c1b53abefcb
fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents:
69
diff
changeset
|
26 def _load_fixture_and_fetch(self, fixture_name, stupid): |
67
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
27 return test_util.load_fixture_and_fetch(fixture_name, self.repo_path, |
73
9c1b53abefcb
fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents:
69
diff
changeset
|
28 self.wc_path, stupid=stupid) |
67
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
29 |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
30 def _debug_print_copies(self, repo): |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
31 w = sys.stderr.write |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
32 for rev in repo: |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
33 ctx = repo[rev] |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
34 w('%d - %s\n' % (ctx.rev(), ctx.branch())) |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
35 for f in ctx: |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
36 fctx = ctx[f] |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
37 w('%s: %r %r\n' % (f, fctx.data(), fctx.renamed())) |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
38 |
73
9c1b53abefcb
fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents:
69
diff
changeset
|
39 def _test_rename(self, stupid): |
9c1b53abefcb
fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents:
69
diff
changeset
|
40 repo = self._load_fixture_and_fetch('renames.svndump', stupid) |
67
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
41 # self._debug_print_copies(repo) |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
42 |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
43 # Map revnum to mappings of dest name to (source name, dest content) |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
44 copies = { |
68
e0c86ebe05e3
test_fetch_renames: test copy of deleted stuff from the past
Patrick Mezard <pmezard@gmail.com>
parents:
67
diff
changeset
|
45 4: { |
67
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
46 'a1': ('a', 'a\n'), |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
47 'a2': ('a', 'a\n'), |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
48 'b1': ('b', 'b\nc\n'), |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
49 'da1/daf': ('da/daf', 'c\n'), |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
50 'da1/db/dbf': ('da/db/dbf', 'd\n'), |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
51 'da2/daf': ('da/daf', 'c\n'), |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
52 'da2/db/dbf': ('da/db/dbf', 'd\n'), |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
53 }, |
68
e0c86ebe05e3
test_fetch_renames: test copy of deleted stuff from the past
Patrick Mezard <pmezard@gmail.com>
parents:
67
diff
changeset
|
54 5: { |
67
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
55 'c1': ('c', 'c\nc\n'), |
69
63ece4ea25c9
hg_delta_editor: register copies only if files are unchanged between source and dest
Patrick Mezard <pmezard@gmail.com>
parents:
68
diff
changeset
|
56 }, |
63ece4ea25c9
hg_delta_editor: register copies only if files are unchanged between source and dest
Patrick Mezard <pmezard@gmail.com>
parents:
68
diff
changeset
|
57 9: { |
63ece4ea25c9
hg_delta_editor: register copies only if files are unchanged between source and dest
Patrick Mezard <pmezard@gmail.com>
parents:
68
diff
changeset
|
58 'unchanged2': ('unchanged', 'unchanged\n'), |
63ece4ea25c9
hg_delta_editor: register copies only if files are unchanged between source and dest
Patrick Mezard <pmezard@gmail.com>
parents:
68
diff
changeset
|
59 'unchangeddir2/f': ('unchangeddir/f', 'unchanged2\n'), |
67
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
60 } |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
61 } |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
62 for rev in repo: |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
63 ctx = repo[rev] |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
64 copymap = copies.get(rev, {}) |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
65 for f in ctx.manifest(): |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
66 cp = ctx[f].renamed() |
69
63ece4ea25c9
hg_delta_editor: register copies only if files are unchanged between source and dest
Patrick Mezard <pmezard@gmail.com>
parents:
68
diff
changeset
|
67 self.assertEqual(bool(cp), bool(copymap.get(f)), |
63ece4ea25c9
hg_delta_editor: register copies only if files are unchanged between source and dest
Patrick Mezard <pmezard@gmail.com>
parents:
68
diff
changeset
|
68 'copy records differ for %s in %d' % (f, rev)) |
67
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
69 if not cp: |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
70 continue |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
71 self.assertEqual(cp[0], copymap[f][0]) |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
72 self.assertEqual(ctx[f].data(), copymap[f][1]) |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
73 |
73
9c1b53abefcb
fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents:
69
diff
changeset
|
74 def test_rename(self): |
9c1b53abefcb
fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents:
69
diff
changeset
|
75 self._test_rename(False) |
9c1b53abefcb
fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents:
69
diff
changeset
|
76 |
9c1b53abefcb
fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents:
69
diff
changeset
|
77 def test_rename_stupid(self): |
9c1b53abefcb
fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents:
69
diff
changeset
|
78 self._test_rename(True) |
9c1b53abefcb
fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents:
69
diff
changeset
|
79 |
67
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
80 def suite(): |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
81 all = [unittest.TestLoader().loadTestsFromTestCase(TestFetchRenames), |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
82 ] |
e319c9168910
hg_delta_editor: register svn file copies
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
83 return unittest.TestSuite(all) |