annotate tests/test_rebuildmeta.py @ 616:532c545d162c

svncommands: add two missing imports Two imports used when printing tracebacks were missing. They were easily missed as this code isn't exercised unless an exception happens to be raised during the execution of one of the `svn' subcommands.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Sat, 15 May 2010 20:33:05 +0200
parents 00393e9abff8
children 25714b4954b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1 import os
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2 import pickle
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3 import unittest
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 337
diff changeset
5 import test_util
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 337
diff changeset
6
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
7 from mercurial import hg
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
8 from mercurial import ui
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
9
337
46e69be8e2c8 Reorganize to have a more conventional module structure.
Augie Fackler <durin42@gmail.com>
parents: 331
diff changeset
10 from hgsubversion import svncommands
416
cd6317fe70be invert the svnmeta/editor relationship
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 414
diff changeset
11 from hgsubversion import svnmeta
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
12
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
13 def _do_case(self, name, stupid, single):
194
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents: 182
diff changeset
14 subdir = test_util.subdir.get(name, '')
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
15 layout = 'auto'
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
16 if single:
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
17 layout = 'single'
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
18 self._load_fixture_and_fetch(name, subdir=subdir, stupid=stupid, layout=layout)
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19 assert len(self.repo) > 0
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
20 wc2_path = self.wc_path + '_clone'
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
21 u = ui.ui()
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
22 src, dest = hg.clone(u, self.wc_path, wc2_path, update=False)
246
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 225
diff changeset
23 svncommands.rebuildmeta(u,
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
24 dest,
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
25 args=[test_util.fileurl(self.repo_path +
194
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents: 182
diff changeset
26 subdir), ])
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 246
diff changeset
27 self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')),
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 246
diff changeset
28 'no .hg/svn directory in the source!')
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 246
diff changeset
29 self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')),
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 246
diff changeset
30 'no .hg/svn directory in the destination!')
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
31 dest = hg.repository(u, os.path.dirname(dest.path))
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
32 for tf in ('rev_map', 'uuid', 'tagmap', 'layout', ):
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 246
diff changeset
33 stf = os.path.join(src.path, 'svn', tf)
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 246
diff changeset
34 self.assertTrue(os.path.isfile(stf), '%r is missing!' % stf)
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 246
diff changeset
35 dtf = os.path.join(dest.path, 'svn', tf)
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 246
diff changeset
36 self.assertTrue(os.path.isfile(dtf), '%r is missing!' % tf)
447
0d3b5acb1d51 tags: handle edits to tags as gracefully as possible
Augie Fackler <durin42@gmail.com>
parents: 416
diff changeset
37 old, new = open(stf).read(), open(dtf).read()
452
ae35c389cdef tags: allow editing tags of closed branches without reopening the branch
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
38 # uncomment next line for easy-ish debugging.
474
63cb630d667d tags: handle the most recent commit being an edit to an svn tag properly
Augie Fackler <durin42@gmail.com>
parents: 453
diff changeset
39 # os.system('diff -u %s %s' % (stf, dtf))
447
0d3b5acb1d51 tags: handle edits to tags as gracefully as possible
Augie Fackler <durin42@gmail.com>
parents: 416
diff changeset
40 self.assertEqual(old, new)
0d3b5acb1d51 tags: handle edits to tags as gracefully as possible
Augie Fackler <durin42@gmail.com>
parents: 416
diff changeset
41 self.assertEqual(src.branchtags(), dest.branchtags())
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
42 srcbi = pickle.load(open(os.path.join(src.path, 'svn', 'branch_info')))
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
43 destbi = pickle.load(open(os.path.join(dest.path, 'svn', 'branch_info')))
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
44 self.assertEqual(sorted(srcbi.keys()), sorted(destbi.keys()))
416
cd6317fe70be invert the svnmeta/editor relationship
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 414
diff changeset
45 revkeys = svnmeta.SVNMeta(dest).revmap.keys()
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
46 for branch in destbi:
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
47 srcinfo = srcbi[branch]
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
48 destinfo = destbi[branch]
447
0d3b5acb1d51 tags: handle edits to tags as gracefully as possible
Augie Fackler <durin42@gmail.com>
parents: 416
diff changeset
49 if srcinfo[:2] == (None, 0) or destinfo[:2] == (None, 0):
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
50 self.assert_(srcinfo[2] <= destinfo[2])
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
51 self.assertEqual(srcinfo[0], destinfo[0])
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
52 else:
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
53 pr = sorted(filter(lambda x: x[1] == srcinfo[0] and x[0] <= srcinfo[1],
405
a98b8d424221 editor: simplify HgChangeReceiver constructor signature
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 383
diff changeset
54 revkeys), reverse=True)[0][0]
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
55 self.assertEqual(pr, destinfo[1])
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
56 self.assertEqual(srcinfo[2], destinfo[2])
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
57
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
58
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
59 def buildmethod(case, name, stupid, single):
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
60 m = lambda self: self._do_case(case, stupid, single)
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
61 m.__name__ = name
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
62 m.__doc__ = ('Test rebuildmeta on %s with %s replay. (%s)' %
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
63 (case,
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
64 (stupid and 'stupid') or 'real',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
65 (single and 'single') or 'standard',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
66 )
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
67 )
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
68 return m
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
69
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
70
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
71 attrs = {'_do_case': _do_case,
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
72 }
182
47d25d61abfa remove generators (compat with python2.3)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 155
diff changeset
73 for case in [f for f in os.listdir(test_util.FIXTURES) if f.endswith('.svndump')]:
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 337
diff changeset
74 # this fixture results in an empty repository, don't use it
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 337
diff changeset
75 if case == 'project_root_not_repo_root.svndump':
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 337
diff changeset
76 continue
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
77 bname = 'test_' + case[:-len('.svndump')]
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
78 attrs[bname] = buildmethod(case, bname, False, False)
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
79 name = bname + '_stupid'
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
80 attrs[name] = buildmethod(case, name, True, False)
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
81 name = bname + '_single'
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
82 attrs[name] = buildmethod(case, name, False, True)
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 474
diff changeset
83
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
84 RebuildMetaTests = type('RebuildMetaTests', (test_util.TestBase, ), attrs)
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
85
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
86
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
87 def suite():
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
88 all = [unittest.TestLoader().loadTestsFromTestCase(RebuildMetaTests),
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
89 ]
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
90 return unittest.TestSuite(all)