Mercurial > hgsubversion
comparison tests/test_push_dirs.py @ 84:01e747937d35
test_util: add commitchanges() to TestBase
| author | Patrick Mezard <pmezard@gmail.com> |
|---|---|
| date | Fri, 14 Nov 2008 16:18:24 -0600 |
| parents | 6c9b7cf1c5aa |
| children | 05a0c4f6060f |
comparison
equal
deleted
inserted
replaced
| 83:6c9b7cf1c5aa | 84:01e747937d35 |
|---|---|
| 1 import os | |
| 2 import sys | |
| 3 import unittest | 1 import unittest |
| 4 | |
| 5 from mercurial import context | |
| 6 from mercurial import hg | |
| 7 from mercurial import node | |
| 8 | 2 |
| 9 import test_util | 3 import test_util |
| 10 | 4 |
| 11 class TestPushDirectories(test_util.TestBase): | 5 class TestPushDirectories(test_util.TestBase): |
| 12 def setUp(self): | 6 def setUp(self): |
| 13 test_util.TestBase.setUp(self) | 7 test_util.TestBase.setUp(self) |
| 14 test_util.load_fixture_and_fetch('emptyrepo.svndump', | 8 test_util.load_fixture_and_fetch('emptyrepo.svndump', |
| 15 self.repo_path, | 9 self.repo_path, |
| 16 self.wc_path) | 10 self.wc_path) |
| 17 | 11 |
| 18 def _commitchanges(self, repo, changes): | 12 def test_push_dirs(self): |
| 19 parentctx = repo['tip'] | |
| 20 | |
| 21 changed, removed = [], [] | |
| 22 for source, dest, newdata in changes: | |
| 23 if dest is None: | |
| 24 removed.append(source) | |
| 25 else: | |
| 26 changed.append(dest) | |
| 27 | |
| 28 def filectxfn(repo, memctx, path): | |
| 29 if path in removed: | |
| 30 raise IOError() | |
| 31 entry = [e for e in changes if path == e[1]][0] | |
| 32 source, dest, newdata = entry | |
| 33 if newdata is None: | |
| 34 newdata = parentctx[source].data() | |
| 35 copied = None | |
| 36 if source != dest: | |
| 37 copied = source | |
| 38 return context.memfilectx(path=dest, | |
| 39 data=newdata, | |
| 40 islink=False, | |
| 41 isexec=False, | |
| 42 copied=copied) | |
| 43 | |
| 44 ctx = context.memctx(repo, | |
| 45 (parentctx.node(), node.nullid), | |
| 46 'automated test', | |
| 47 changed + removed, | |
| 48 filectxfn, | |
| 49 'an_author', | |
| 50 '2008-10-07 20:59:48 -0500') | |
| 51 nodeid = repo.commitctx(ctx) | |
| 52 repo = self.repo | |
| 53 hg.update(repo, nodeid) | |
| 54 return nodeid | |
| 55 | |
| 56 def test_push_dirs(self, commit=True): | |
| 57 changes = [ | 13 changes = [ |
| 58 # Single file in single directory | 14 # Single file in single directory |
| 59 ('d1/a', 'd1/a', 'a\n'), | 15 ('d1/a', 'd1/a', 'a\n'), |
| 60 # Two files in one directory | 16 # Two files in one directory |
| 61 ('d2/a', 'd2/a', 'a\n'), | 17 ('d2/a', 'd2/a', 'a\n'), |
| 62 ('d2/b', 'd2/b', 'a\n'), | 18 ('d2/b', 'd2/b', 'a\n'), |
| 63 # Single file in empty directory hierarchy | 19 # Single file in empty directory hierarchy |
| 64 ('d31/d32/d33/d34/a', 'd31/d32/d33/d34/a', 'a\n'), | 20 ('d31/d32/d33/d34/a', 'd31/d32/d33/d34/a', 'a\n'), |
| 65 ('d31/d32/a', 'd31/d32/a', 'a\n'), | 21 ('d31/d32/a', 'd31/d32/a', 'a\n'), |
| 66 ] | 22 ] |
| 67 self._commitchanges(self.repo, changes) | 23 self.commitchanges(changes) |
| 68 self.pushrevisions() | 24 self.pushrevisions() |
| 69 self.assertEqual(self.svnls('trunk'), | 25 self.assertEqual(self.svnls('trunk'), |
| 70 ['d1', 'd1/a', 'd2', 'd2/a', 'd2/b', 'd31', | 26 ['d1', 'd1/a', 'd2', 'd2/a', 'd2/b', 'd31', |
| 71 'd31/d32', 'd31/d32/a', 'd31/d32/d33', | 27 'd31/d32', 'd31/d32/a', 'd31/d32/d33', |
| 72 'd31/d32/d33/d34', 'd31/d32/d33/d34/a']) | 28 'd31/d32/d33/d34', 'd31/d32/d33/d34/a']) |
| 77 # Remove one file out of two | 33 # Remove one file out of two |
| 78 ('d2/a', None, None), | 34 ('d2/a', None, None), |
| 79 # Removing this file should remove one empty parent dir too | 35 # Removing this file should remove one empty parent dir too |
| 80 ('d31/d32/d33/d34/a', None, None), | 36 ('d31/d32/d33/d34/a', None, None), |
| 81 ] | 37 ] |
| 82 self._commitchanges(self.repo, changes) | 38 self.commitchanges(changes) |
| 83 self.pushrevisions() | 39 self.pushrevisions() |
| 84 self.assertEqual(self.svnls('trunk'), | 40 self.assertEqual(self.svnls('trunk'), |
| 85 ['d2', 'd2/b', 'd31', 'd31/d32', 'd31/d32/a', 'd31/d32/d33']) | 41 ['d2', 'd2/b', 'd31', 'd31/d32', 'd31/d32/a', 'd31/d32/d33']) |
| 86 | 42 |
| 87 def suite(): | 43 def suite(): |
