comparison tests/test_push_command.py @ 16:48a44546c12f

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