comparison tests/test_push_command.py @ 24:5954a514ae26

Pushing fails in 1.4's SWIG bindings, so double check for that in the test.
author Augie Fackler <durin42@gmail.com>
date Thu, 09 Oct 2008 23:36:20 -0500
parents 48a44546c12f
children b66ed66c82e4
comparison
equal deleted inserted replaced
23:1f8854804795 24:5954a514ae26
10 from mercurial import revlog 10 from mercurial import revlog
11 11
12 import fetch_command 12 import fetch_command
13 import push_cmd 13 import push_cmd
14 import test_util 14 import test_util
15 # push fails in 1.4-SWIG-land.
16 push_works = False
17 try:
18 import csvn
19 push_works = True
20 except ImportError:
21 from svn import core
22 if (core.SVN_VER_MAJOR, core.SVN_VER_MINOR, core.SVN_VER_MICRO) >= (1, 5, 0):
23 push_works = True
15 24
16 class PushTests(unittest.TestCase): 25 if push_works:
17 def setUp(self): 26 class PushTests(unittest.TestCase):
18 self.oldwd = os.getcwd() 27 def setUp(self):
19 self.tmpdir = tempfile.mkdtemp('svnwrap_test') 28 self.oldwd = os.getcwd()
20 self.repo_path = '%s/testrepo' % self.tmpdir 29 self.tmpdir = tempfile.mkdtemp('svnwrap_test')
21 self.wc_path = '%s/testrepo_wc' % self.tmpdir 30 self.repo_path = '%s/testrepo' % self.tmpdir
22 test_util.load_svndump_fixture(self.repo_path, 'simple_branch.svndump') 31 self.wc_path = '%s/testrepo_wc' % self.tmpdir
23 fetch_command.fetch_revisions(ui.ui(), 32 test_util.load_svndump_fixture(self.repo_path, 'simple_branch.svndump')
24 svn_url='file://%s' % self.repo_path, 33 fetch_command.fetch_revisions(ui.ui(),
25 hg_repo_path=self.wc_path) 34 svn_url='file://%s' % self.repo_path,
35 hg_repo_path=self.wc_path)
26 36
27 # define this as a property so that it reloads anytime we need it 37 # define this as a property so that it reloads anytime we need it
28 @property 38 @property
29 def repo(self): 39 def repo(self):
30 return hg.repository(ui.ui(), self.wc_path) 40 return hg.repository(ui.ui(), self.wc_path)
31 41
32 def tearDown(self): 42 def tearDown(self):
33 shutil.rmtree(self.tmpdir) 43 shutil.rmtree(self.tmpdir)
34 os.chdir(self.oldwd) 44 os.chdir(self.oldwd)
35 45
36 def test_push_to_default(self, commit=True): 46 def test_push_to_default(self, commit=True):
37 repo = self.repo 47 repo = self.repo
38 old_tip = repo['tip'].node() 48 old_tip = repo['tip'].node()
39 expected_parent = repo['default'].node() 49 expected_parent = repo['default'].node()
40 def file_callback(repo, memctx, path): 50 def file_callback(repo, memctx, path):
41 if path == 'adding_file': 51 if path == 'adding_file':
42 return context.memfilectx(path=path, 52 return context.memfilectx(path=path,
43 data='foo', 53 data='foo',
44 islink=False, 54 islink=False,
45 isexec=False, 55 isexec=False,
46 copied=False) 56 copied=False)
47 raise IOError() 57 raise IOError()
48 ctx = context.memctx(repo, 58 ctx = context.memctx(repo,
49 (repo['default'].node(), node.nullid), 59 (repo['default'].node(), node.nullid),
50 'automated test', 60 'automated test',
51 ['adding_file'], 61 ['adding_file'],
52 file_callback, 62 file_callback,
53 'an_author', 63 'an_author',
54 '2008-10-07 20:59:48 -0500', 64 '2008-10-07 20:59:48 -0500',
55 {'branch': 'default',}) 65 {'branch': 'default',})
56 new_hash = repo.commitctx(ctx) 66 new_hash = repo.commitctx(ctx)
57 if not commit: 67 if not commit:
58 return # some tests use this test as an extended setup. 68 return # some tests use this test as an extended setup.
59 hg.update(repo, repo['tip'].node()) 69 hg.update(repo, repo['tip'].node())
60 push_cmd.push_revisions_to_subversion(ui.ui(), repo=self.repo, 70 push_cmd.push_revisions_to_subversion(ui.ui(), repo=self.repo,
61 hg_repo_path=self.wc_path, 71 hg_repo_path=self.wc_path,
62 svn_url='file://'+self.repo_path) 72 svn_url='file://'+self.repo_path)
63 tip = self.repo['tip'] 73 tip = self.repo['tip']
64 self.assertNotEqual(tip.node(), old_tip) 74 self.assertNotEqual(tip.node(), old_tip)
65 self.assertEqual(tip.parents()[0].node(), expected_parent) 75 self.assertEqual(tip.parents()[0].node(), expected_parent)
66 self.assertEqual(tip['adding_file'].data(), 'foo') 76 self.assertEqual(tip['adding_file'].data(), 'foo')
67 self.assertEqual(tip.branch(), 'default') 77 self.assertEqual(tip.branch(), 'default')
68 78
69 def test_push_two_revs(self): 79 def test_push_two_revs(self):
70 # set up some work for us 80 # set up some work for us
71 self.test_push_to_default(commit=False) 81 self.test_push_to_default(commit=False)
72 repo = self.repo 82 repo = self.repo
73 old_tip = repo['tip'].node() 83 old_tip = repo['tip'].node()
74 expected_parent = repo['tip'].parents()[0].node() 84 expected_parent = repo['tip'].parents()[0].node()
75 def file_callback(repo, memctx, path): 85 def file_callback(repo, memctx, path):
76 if path == 'adding_file2': 86 if path == 'adding_file2':
77 return context.memfilectx(path=path, 87 return context.memfilectx(path=path,
78 data='foo2', 88 data='foo2',
79 islink=False, 89 islink=False,
80 isexec=False, 90 isexec=False,
81 copied=False) 91 copied=False)
82 raise IOError() 92 raise IOError()
83 ctx = context.memctx(repo, 93 ctx = context.memctx(repo,
84 (repo['default'].node(), node.nullid), 94 (repo['default'].node(), node.nullid),
85 'automated test', 95 'automated test',
86 ['adding_file2'], 96 ['adding_file2'],
87 file_callback, 97 file_callback,
88 'an_author', 98 'an_author',
89 '2008-10-07 20:59:48 -0500', 99 '2008-10-07 20:59:48 -0500',
90 {'branch': 'default',}) 100 {'branch': 'default',})
91 new_hash = repo.commitctx(ctx) 101 new_hash = repo.commitctx(ctx)
92 hg.update(repo, repo['tip'].node()) 102 hg.update(repo, repo['tip'].node())
93 push_cmd.push_revisions_to_subversion(ui.ui(), repo=self.repo, 103 push_cmd.push_revisions_to_subversion(ui.ui(), repo=self.repo,
94 hg_repo_path=self.wc_path, 104 hg_repo_path=self.wc_path,
95 svn_url='file://'+self.repo_path) 105 svn_url='file://'+self.repo_path)
96 tip = self.repo['tip'] 106 tip = self.repo['tip']
97 self.assertNotEqual(tip.node(), old_tip) 107 self.assertNotEqual(tip.node(), old_tip)
98 self.assertNotEqual(tip.parents()[0].node(), old_tip) 108 self.assertNotEqual(tip.parents()[0].node(), old_tip)
99 self.assertEqual(tip.parents()[0].parents()[0].node(), expected_parent) 109 self.assertEqual(tip.parents()[0].parents()[0].node(), expected_parent)
100 self.assertEqual(tip['adding_file2'].data(), 'foo2') 110 self.assertEqual(tip['adding_file2'].data(), 'foo2')
101 self.assertEqual(tip['adding_file'].data(), 'foo') 111 self.assertEqual(tip['adding_file'].data(), 'foo')
102 self.assertEqual(tip.parents()[0]['adding_file'].data(), 'foo') 112 self.assertEqual(tip.parents()[0]['adding_file'].data(), 'foo')
103 try: 113 try:
104 self.assertEqual(tip.parents()[0]['adding_file2'].data(), 'foo') 114 self.assertEqual(tip.parents()[0]['adding_file2'].data(), 'foo')
105 assert False, "this is impossible, adding_file2 should not be in this manifest." 115 assert False, "this is impossible, adding_file2 should not be in this manifest."
106 except revlog.LookupError, e: 116 except revlog.LookupError, e:
107 pass 117 pass
108 self.assertEqual(tip.branch(), 'default') 118 self.assertEqual(tip.branch(), 'default')
109 119
110 def test_push_to_branch(self): 120 def test_push_to_branch(self):
111 repo = self.repo 121 repo = self.repo
112 def file_callback(repo, memctx, path): 122 def file_callback(repo, memctx, path):
113 if path == 'adding_file': 123 if path == 'adding_file':
114 return context.memfilectx(path=path, 124 return context.memfilectx(path=path,
115 data='foo', 125 data='foo',
116 islink=False, 126 islink=False,
117 isexec=False, 127 isexec=False,
118 copied=False) 128 copied=False)
119 raise IOError() 129 raise IOError()
120 ctx = context.memctx(repo, 130 ctx = context.memctx(repo,
121 (repo['the_branch'].node(), node.nullid), 131 (repo['the_branch'].node(), node.nullid),
122 'automated test', 132 'automated test',
123 ['adding_file'], 133 ['adding_file'],
124 file_callback, 134 file_callback,
125 'an_author', 135 'an_author',
126 '2008-10-07 20:59:48 -0500', 136 '2008-10-07 20:59:48 -0500',
127 {'branch': 'the_branch',}) 137 {'branch': 'the_branch',})
128 new_hash = repo.commitctx(ctx) 138 new_hash = repo.commitctx(ctx)
129 push_cmd.push_revisions_to_subversion(ui.ui(), repo=self.repo, 139 push_cmd.push_revisions_to_subversion(ui.ui(), repo=self.repo,
130 hg_repo_path=self.wc_path, 140 hg_repo_path=self.wc_path,
131 svn_url='file://'+self.repo_path) 141 svn_url='file://'+self.repo_path)
132 tip = self.repo['tip'] 142 tip = self.repo['tip']
133 self.assertEqual(tip['adding_file'].data(), 'foo') 143 self.assertEqual(tip['adding_file'].data(), 'foo')
134 self.assertEqual(tip.branch(), 'the_branch') 144 self.assertEqual(tip.branch(), 'the_branch')
135 145
136 # 146 #
137 # def test_delete_file(self): 147 # def test_delete_file(self):
138 # assert False 148 # assert False
139 # 149 #
142 # 152 #
143 # def test_push_symlink_file(self): 153 # def test_push_symlink_file(self):
144 # assert False 154 # assert False
145 155
146 def suite(): 156 def suite():
147 return unittest.TestLoader().loadTestsFromTestCase(PushTests) 157 if push_works:
158 return unittest.TestLoader().loadTestsFromTestCase(PushTests)
159 return []
160