comparison tests/test_util.py @ 304:ce676eff002b

First merge, totally untested.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Fri, 01 May 2009 10:28:59 +0200
parents dc2bb6faf904
children 33736e2e25f0
comparison
equal deleted inserted replaced
303:f423a8780832 304:ce676eff002b
11 from mercurial import context 11 from mercurial import context
12 from mercurial import hg 12 from mercurial import hg
13 from mercurial import node 13 from mercurial import node
14 from mercurial import ui 14 from mercurial import ui
15 15
16 import fetch_command 16 import wrappers
17 import push_cmd
18 17
19 # Fixtures that need to be pulled at a subdirectory of the repo path 18 # Fixtures that need to be pulled at a subdirectory of the repo path
20 subdir = {'truncatedhistory.svndump': '/project2', 19 subdir = {'truncatedhistory.svndump': '/project2',
21 'fetch_missing_files_subdir.svndump': '/foo', 20 'fetch_missing_files_subdir.svndump': '/foo',
21 'empty_dir_in_trunk_not_repo_root.svndump': '/project',
22 } 22 }
23 23
24 FIXTURES = os.path.join(os.path.abspath(os.path.dirname(__file__)), 24 FIXTURES = os.path.join(os.path.abspath(os.path.dirname(__file__)),
25 'fixtures') 25 'fixtures')
26 26
43 inp = open(os.path.join(FIXTURES, fixture_name)) 43 inp = open(os.path.join(FIXTURES, fixture_name))
44 proc.stdin.write(inp.read()) 44 proc.stdin.write(inp.read())
45 proc.stdin.flush() 45 proc.stdin.flush()
46 proc.communicate() 46 proc.communicate()
47 47
48 def load_fixture_and_fetch(fixture_name, repo_path, wc_path, stupid=False, subdir=''): 48 def load_fixture_and_fetch(fixture_name, repo_path, wc_path, stupid=False, subdir='', noupdate=True):
49 load_svndump_fixture(repo_path, fixture_name) 49 load_svndump_fixture(repo_path, fixture_name)
50 if subdir: 50 if subdir:
51 repo_path += '/' + subdir 51 repo_path += '/' + subdir
52 fetch_command.fetch_revisions(ui.ui(), 52 wrappers.clone(None, ui.ui(), source=fileurl(repo_path),
53 svn_url=fileurl(repo_path), 53 dest=wc_path, stupid=stupid, noupdate=noupdate)
54 hg_repo_path=wc_path,
55 stupid=stupid)
56 repo = hg.repository(ui.ui(), wc_path) 54 repo = hg.repository(ui.ui(), wc_path)
57 return repo 55 return repo
58 56
59 def rmtree(path): 57 def rmtree(path):
60 # Read-only files cannot be removed under Windows 58 # Read-only files cannot be removed under Windows
73 71
74 72
75 class MockUI(object): 73 class MockUI(object):
76 real_ui = ui.ui 74 real_ui = ui.ui
77 _isatty = False 75 _isatty = False
78 def __init__(self, parentui=None): 76 def __init__(self, src=None):
79 self.stream = StringIO.StringIO() 77 self.stream = StringIO.StringIO()
80 self.inner_ui = self.real_ui(parentui=parentui) 78 self.inner_ui = self.real_ui(src)
81 79
82 def status(self, *args): 80 def status(self, *args):
83 self.stream.write(''.join(args)) 81 self.stream.write(''.join(args))
84 82
85 def warn(self, *args): 83 def warn(self, *args):
86 self.stream.write(*args) 84 self.stream.write(*args)
87 85
88 def write(self, *args): 86 def write(self, *args):
89 self.stream.write(*args) 87 self.stream.write(*args)
88
89 def copy(self):
90 return self.__class__(self.inner_ui)
90 91
91 def __getattr__(self, attr): 92 def __getattr__(self, attr):
92 return getattr(self.inner_ui, attr) 93 return getattr(self.inner_ui, attr)
93 94
94 95
95 class TestBase(unittest.TestCase): 96 class TestBase(unittest.TestCase):
96 def setUp(self): 97 def setUp(self):
97 self.oldwd = os.getcwd() 98 self.oldwd = os.getcwd()
98 self.tmpdir = tempfile.mkdtemp( 99 self.tmpdir = tempfile.mkdtemp(
99 'svnwrap_test', dir=os.environ.get('HGSUBVERSION_TEST_TEMP', None)) 100 'svnwrap_test', dir=os.environ.get('HGSUBVERSION_TEST_TEMP', None))
101 self.hgrc = os.path.join(self.tmpdir, '.hgrc')
102 os.environ['HGRCPATH'] = self.hgrc
103 rc = open(self.hgrc, 'w')
104 rc.write('[extensions]\nhgsubversion=')
100 105
101 self.repo_path = '%s/testrepo' % self.tmpdir 106 self.repo_path = '%s/testrepo' % self.tmpdir
102 self.wc_path = '%s/testrepo_wc' % self.tmpdir 107 self.wc_path = '%s/testrepo_wc' % self.tmpdir
103 self._real_ui = ui.ui 108 self._real_ui = ui.ui
104 ui.ui = MockUI 109 ui.ui = MockUI
118 def repo(self): 123 def repo(self):
119 return hg.repository(ui.ui(), self.wc_path) 124 return hg.repository(ui.ui(), self.wc_path)
120 125
121 def pushrevisions(self, stupid=False): 126 def pushrevisions(self, stupid=False):
122 before = len(self.repo) 127 before = len(self.repo)
123 push_cmd.push_revisions_to_subversion( 128 wrappers.push(None, ui.ui(), repo=self.repo, stupid=stupid)
124 ui.ui(), repo=self.repo, hg_repo_path=self.wc_path,
125 svn_url=fileurl(self.repo_path), stupid=stupid)
126 after = len(self.repo) 129 after = len(self.repo)
127 self.assertEqual(0, after - before) 130 self.assertEqual(0, after - before)
128 131
129 def svnls(self, path, rev='HEAD'): 132 def svnls(self, path, rev='HEAD'):
130 path = self.repo_path + '/' + path 133 path = self.repo_path + '/' + path
138 raise Exception('svn ls failed on %s: %r' % (path, stderr)) 141 raise Exception('svn ls failed on %s: %r' % (path, stderr))
139 entries = [e.strip('/') for e in stdout.splitlines()] 142 entries = [e.strip('/') for e in stdout.splitlines()]
140 entries.sort() 143 entries.sort()
141 return entries 144 return entries
142 145
143 def commitchanges(self, changes): 146 def commitchanges(self, changes, parent='tip'):
144 """Commit changes to mercurial directory 147 """Commit changes to mercurial directory
145 148
146 'changes' is a sequence of tuples (source, dest, data). It can look 149 'changes' is a sequence of tuples (source, dest, data). It can look
147 like: 150 like:
148 - (source, source, data) to set source content to data 151 - (source, source, data) to set source content to data
151 - (source, dest, data) to set dest content to data, and mark it as copied 154 - (source, dest, data) to set dest content to data, and mark it as copied
152 from source. 155 from source.
153 - (source, None, None) to remove source. 156 - (source, None, None) to remove source.
154 """ 157 """
155 repo = self.repo 158 repo = self.repo
156 parentctx = repo['tip'] 159 parentctx = repo[parent]
157 160
158 changed, removed = [], [] 161 changed, removed = [], []
159 for source, dest, newdata in changes: 162 for source, dest, newdata in changes:
160 if dest is None: 163 if dest is None:
161 removed.append(source) 164 removed.append(source)
185 filectxfn, 188 filectxfn,
186 'an_author', 189 'an_author',
187 '2008-10-07 20:59:48 -0500') 190 '2008-10-07 20:59:48 -0500')
188 nodeid = repo.commitctx(ctx) 191 nodeid = repo.commitctx(ctx)
189 repo = self.repo 192 repo = self.repo
190 hg.update(repo, nodeid) 193 hg.clean(repo, nodeid)
191 return nodeid 194 return nodeid
192 195
193 def assertchanges(self, changes, ctx): 196 def assertchanges(self, changes, ctx):
194 """Assert that all 'changes' (as in defined in commitchanged()) 197 """Assert that all 'changes' (as in defined in commitchanged())
195 went into ctx. 198 went into ctx.