source: tailor/vcpx/tests/tailor.py @ 1214

Revision 1214, 12.9 KB checked in by lele@…, 7 years ago (diff)

The basedir was moved to the Repository

Line 
1# -*- mode: python; coding: utf-8 -*-
2# :Progetto: vcpx -- Operational tests
3# :Creato:   lun 08 ago 2005 22:17:10 CEST
4# :Autore:   Lele Gaifax <lele@nautilus.homeip.net>
5# :Licenza:  GNU General Public License
6#
7
8"""\
9#!tailor
10'''
11[DEFAULT]
12target-module = None
13source-repository = %(tailor_repo)s
14encoding = None
15target-repository = None
16use-svn-propset = False
17source-module = None
18update = True
19subdir = test
20debug = False
21remove-first-log-line = False
22patch-name-format = None
23verbose = False
24state-file = tailor.state
25start-revision = Version 0.9.17
26
27[darcs2bzr]
28target = bzr:tailor
29root-directory = %(testdir)s/darcs2bzr
30source = darcs:tailor
31patch-name-format = %(revision)s
32
33[bzr2darcs]
34source = bzr:tailor
35root-directory = %(testdir)s/bzr2darcs
36target = darcs:bzrtailor
37patch-name-format = %(revision)s
38start-revision = INITIAL
39
40[darcs:tailor]
41
42[bzr:tailor]
43repository = %(testdir)s/darcs2bzr
44
45[darcs:bzrtailor]
46
47
48[darcs2cdv]
49target = cdv:tailor
50root-directory = %(testdir)s/darcs2cdv
51source = darcs:tailor
52
53[cdv:tailor]
54
55
56[darcs2hg]
57target = hg:tailor
58root-directory = %(testdir)s/darcs2hg
59source = darcs:tailor
60
61[hg:tailor]
62
63
64[darcs2svn]
65target = svn:tailor
66root-directory = %(testdir)s/darcs2svn
67source = darcs:svntailor
68start-revision = INITIAL
69
70[svn2darcs]
71target = darcs:svntailor
72root-directory = %(testdir)s/svn2darcs
73source = svn:tailor
74start-revision = 1
75
76[svn:tailor]
77repository = file://%(testdir)s/svnrepo
78module = tailor
79subdir = svnside
80use-propset = True
81
82[darcs:svntailor]
83repository = %(tailor_repo)s
84subdir = darcside
85
86
87[darcs2monotone]
88target = monotone:tailor
89root-directory = %(testdir)s/darcs2monotone
90source = darcs:tailor
91
92[monotone2darcs]
93source = monotone:tailor
94root-directory = %(testdir)s/monotone2darcs
95target = darcs:mtntailor
96start-revision = INITIAL
97
98[monotone:tailor]
99keyid = tailor
100passphrase = fin che la barca va
101repository = %(testdir)s/tailor-mtn.db
102module = tailor.test
103subdir = mntside
104
105[darcs:mtntailor]
106subdir = darcside
107
108
109[cvs2darcs]
110target = darcs:pxlib
111root-directory = %(testdir)s/cvs2darcs
112source = cvs:pxlib
113start-revision = R-0-5-1
114subdir = pxlib
115
116[darcs:pxlib]
117
118[cvs:pxlib]
119repository = :pserver:anonymous@pxlib.cvs.sourceforce.net:/cvsroot/pxlib
120module = pxlib
121encoding = iso-8859-1
122
123
124[darcs2cvs]
125target = cvs:tailor
126root-directory = %(testdir)s/darcs2cvs
127source = darcs:tailor
128
129[cvs:tailor]
130repository = :local:%(testdir)s/cvsrepo
131module = tailor
132
133
134[cvs2hg]
135root-directory = %(testdir)s/cvs2hg
136source = cvs:cmsmini
137target = hg:cmsmini
138start-revision = INITIAL
139subdir = cmsmini
140before-commit = remap_authors
141
142[cvs:cmsmini]
143repository = :pserver:anonymous@cvs.savannah.nongnu.org:/sources/cmsmini
144module = cmsmini
145
146[hg:cmsmini]
147
148
149[cvs2bzr]
150root-directory = %(testdir)s/cvs2bzr
151source = cvs:atse
152target = bzr:atse
153start-revision = spamies-improvement-branch INITIAL
154subdir = atse
155
156[cvs:atse]
157repository = :pserver:anonymous@collective.cvs.sourceforge.net:/cvsroot/collective
158module = ATSchemaEditorNG
159
160[bzr:atse]
161
162
163[cvs2svn]
164source = cvs:cmfeditions-houston-sprint
165target = svn:cmfeditions
166start-revision = houston-sprint-branch INITIAL
167root-directory = %(testdir)s/cvs2svn
168
169[cvs:cmfeditions-houston-sprint]
170repository = :pserver:anonymous@collective.cvs.sourceforge.net:/cvsroot/collective
171module = CMFEditions
172subdir = cvside
173
174[svn:cmfeditions]
175repository = file://%(testdir)s/cmfeditions.svnrepo
176module = cmfeditions
177subdir = svnside
178
179
180[svn2hg]
181source = svn:plonebook
182target = hg:plonebook
183start-revision = 1101
184root-directory = %(testdir)s/svn2hg
185
186[svn:plonebook]
187repository = http://docit.bice.dyndns.org
188module = /Plone/PloneBook2/it
189
190[hg:plonebook]
191
192[svn2hg_with_externals]
193source = svn:plonebook_we
194target = hg:plonebook
195start-revision = HEAD
196root-directory = %(testdir)s/svn2hg_we
197
198[svn:plonebook_we]
199repository = http://docit.bice.dyndns.org
200module = /Plone/PloneBook2/it
201ignore-externals = False
202
203
204[bazaarng2darcs]
205source = bzr:oodoctest
206target = darcs:oodoctest
207root-directory = %(testdir)s/bazaarng2darcs
208start-revision = INITIAL
209
210[bzr:oodoctest]
211repository = http://download.gna.org/oodoctest/oodoctest.og.main/
212
213[darcs:oodoctest]
214
215
216[darcs_rename_delete]
217source = darcs:darcs_rename_delete
218target = svn:darcs_rename_delete
219root-directory = %(testdir)s/darcs_rename_delete
220start-revision = INITIAL
221
222[darcs:darcs_rename_delete]
223repository = %(testdir)s/rename_delete
224subdir = darcs
225
226[svn:darcs_rename_delete]
227repository = file://%(testdir)s/darcs_rename_delete.svnrepo
228module = /
229subdir = svn
230
231
232[darcs_rename_delete_dir]
233source = darcs:darcs_rename_delete_dir
234target = svn:darcs_rename_delete_dir
235root-directory = %(testdir)s/darcs_rename_delete_dir
236start-revision = INITIAL
237
238[darcs:darcs_rename_delete_dir]
239repository = %(testdir)s/rename_delete_dir
240subdir = darcs
241
242[svn:darcs_rename_delete_dir]
243repository = file://%(testdir)s/darcs_rename_delete_dir.svnrepo
244module = /
245subdir = svn
246
247'''
248
249def remap_authors(context, changeset):
250    if changeset.author == 'tizziano':
251        changeset.author = 'tiziano'
252    return True
253"""
254
255from unittest import TestCase
256from cStringIO import StringIO
257from vcpx import TailorException
258from vcpx.config import Config
259from vcpx.tailor import Tailorizer
260from vcpx.shwrap import ExternalCommand, PIPE
261
262
263class OperationalTest(TestCase):
264
265    TESTDIR = '/tmp/tailor-tests'
266
267    def setUp(self):
268        from os import mkdir, getcwd
269        from os.path import exists, split, join
270        from atexit import register
271        from shutil import rmtree
272
273        tailor_repo = getcwd()
274        while tailor_repo != '/' and not exists(join(tailor_repo, '_darcs')):
275            tailor_repo = split(tailor_repo)[0]
276        assert exists(join(tailor_repo, '_darcs')), "Tailor Darcs repository not found!"
277        self.tailor_repo = tailor_repo
278        self.config = Config(StringIO(__doc__), {'tailor_repo': tailor_repo,
279                                                 'testdir': self.TESTDIR})
280        if not exists(self.TESTDIR):
281            mkdir(self.TESTDIR)
282            register(rmtree, self.TESTDIR)
283
284    def diffWhenPossible(self, tailorizer):
285        "Diff the resulting sides"
286
287        dwd = tailorizer.workingDir()
288        if not dwd.shared_basedirs:
289            cmd = ["diff", "-r", "-u"]
290            if tailorizer.source.METADIR:
291                cmd.extend(["-x", tailorizer.source.METADIR])
292            if tailorizer.target.METADIR:
293                cmd.extend(["-x", tailorizer.target.METADIR])
294            d = ExternalCommand(command=cmd)
295            out = d.execute(dwd.source.repository.basedir,
296                            dwd.target.repository.basedir,
297                            stdout=PIPE)[0]
298            return out.read()
299        else:
300            return ""
301
302    def tailorize(self, project):
303        "The actual test"
304
305        tailorizer = Tailorizer(project, self.config)
306        self.assert_(not tailorizer.exists(),
307                     "For test purposes, better start from scratch!")
308        tailorizer()
309        self.assertEqual(self.diffWhenPossible(tailorizer), "")
310
311class Darcs(OperationalTest):
312    "Test darcs backend"
313
314    def testConfiguration(self):
315        "Test basic configuration"
316
317        p = Tailorizer('darcs2svn', self.config)
318        self.assertEqual(p.source.subdir, 'darcside')
319        self.assertEqual(p.rootdir, '%s/darcs2svn' % self.TESTDIR)
320        self.assertEqual(p.source.repository, self.tailor_repo)
321        self.assertEqual(p.target.repository,
322                         'file://%s/svnrepo' % self.TESTDIR)
323        self.assertEqual(p.state_file.filename,
324                         '%s/darcs2svn/tailor.state' % self.TESTDIR)
325
326        tailorizer = Tailorizer('cvs2darcs', self.config)
327        self.assertEqual(tailorizer.subdir, 'pxlib')
328        self.assertEqual(tailorizer.source.subdir, 'pxlib')
329
330    def testDarcsAndBazaarng(self):
331        "Test darcs to bazaar-ng and the other way around"
332
333        self.tailorize('darcs2bzr')
334        self.tailorize('bzr2darcs')
335
336    def testDarcsToMercurial(self):
337        "Test darcs to mercurial"
338
339        self.tailorize('darcs2hg')
340
341    def testDarcsToCodeville(self):
342        "Test darcs to codeville"
343
344        self.tailorize('darcs2cdv')
345
346    def testDarcsAndSubversion(self):
347        "Test darcs to subversion and the other way around"
348
349        self.tailorize('darcs2svn')
350        self.tailorize('svn2darcs')
351
352    def testDarcsAndMonotone(self):
353        "Test darcs to monotone and the other way around"
354
355        self.tailorize('darcs2monotone')
356        self.tailorize('monotone2darcs')
357
358
359class Bazaarng(OperationalTest):
360    "Test the BazaarNG source backend"
361
362    def testBazaarngAndPython23(self):
363        "Test we detect early when running under Python < 2.4"
364
365        from sys import version_info
366
367        if version_info < (2,4):
368            try:
369                self.tailorize('bazaarng2darcs')
370            except TailorException, e:
371                self.assert_("Bazaar-NG backend requires Python 2.4"
372                             in str(e))
373            else:
374                self.fail("Expected a specific TailorException")
375
376    def testBazaarngToDarcs(self):
377        "Test bazaar-ng to darcs"
378
379        try:
380            self.tailorize('bazaarng2darcs')
381        except TailorException, e:
382            from sys import version_info
383
384            if version_info < (2,4):
385                # Under python 2.3 we expect an exception here, but
386                # different from the above: since we are still in a
387                # single python session importing the bzr stuff does
388                # not raise the same error, because from the python
389                # runtime pov the module is already loaded and thus
390                # the second import does not fail. The repository
391                # class will then instantiate the raw Repository
392                # class, not the specific bzr one. Still, when asked
393                # for a working dir, it will fail again
394                self.assert_("object has no attribute 'BzrWorkingDir'"
395                             in str(e))
396            else:
397                raise
398
399
400
401class Cvs(OperationalTest):
402    "Test the CVS source backend"
403
404    def testCvsToDarcs(self):
405        "Test CVS to darcs"
406
407        self.tailorize('cvs2darcs')
408
409    def testDarcsToCvs(self):
410        "Test Darcs to CVS"
411
412        self.tailorize('darcs2cvs')
413
414    def testCvsToMercurial(self):
415        "Test CVS to mercurial"
416
417        self.tailorize('cvs2hg')
418
419    def testCvsToBazaarng(self):
420        "Test CVS to bazaar-ng"
421
422        self.tailorize('cvs2bzr')
423
424    def testCvsToSubversion(self):
425        "Test CVS branch to Subversion"
426
427        self.tailorize('cvs2svn')
428
429
430class Svn(OperationalTest):
431    "Test the subversion backend"
432
433    def testExternals(self):
434        "Exercise svn to mercurial with and without svn:externals"
435
436        from os.path import exists
437
438        external = self.TESTDIR + '/svn2hg%s/test/make/docutils.make'
439        self.tailorize('svn2hg')
440        self.failIf(exists(external % ''))
441
442        self.tailorize('svn2hg_with_externals')
443        self.failUnless(exists(external % '_we'))
444
445    def testDarcsRenameDelete(self):
446        "Try to migrate a darcs patch that renames and removes the same file"
447
448        from os import mkdir
449        from os.path import join
450
451        drepo = join(self.TESTDIR, 'rename_delete')
452        mkdir(drepo)
453
454        dinit = ExternalCommand(command=['darcs', 'init'], cwd=drepo)
455        dinit.execute()
456
457        fileA = join(drepo, 'fileA')
458        open(fileA, 'w')
459        dadd = ExternalCommand(command=['darcs', 'add'], cwd=drepo)
460        dadd.execute(fileA)
461
462        drecord = ExternalCommand(command=['darcs', 'record',
463                                           '-a', '-m'], cwd=drepo)
464        drecord.execute('Add A')
465
466        fileB = join(drepo, 'fileB')
467        drename = ExternalCommand(command=['darcs', 'mv'], cwd=drepo)
468        drename.execute(fileA, fileB)
469
470        dremove = ExternalCommand(command=['darcs', 'remove'], cwd=drepo)
471        dremove.execute(fileB)
472
473        drecord.execute('Move A to B and delete B')
474
475        self.tailorize('darcs_rename_delete')
476
477    def testDarcsRenameDeleteDir(self):
478        "Test if darcs to svn fails on moves combined with directory deletes"
479
480        from os import mkdir
481        from os.path import join
482
483        drepo = join(self.TESTDIR, 'rename_delete_dir')
484        mkdir(drepo)
485
486        dinit = ExternalCommand(command=['darcs', 'init'], cwd=drepo)
487        dinit.execute()
488
489        dir = join(drepo, 'dir')
490        mkdir(dir)
491        dadd = ExternalCommand(command=['darcs', 'add'], cwd=drepo)
492        dadd.execute(dir)
493        fileA = join(dir, 'fileA')
494        open(fileA, 'w')
495        dadd.execute(fileA)
496
497        drecord = ExternalCommand(command=['darcs', 'record',
498                                           '-a', '-m'], cwd=drepo)
499        drecord.execute('Add dir and dir/A')
500
501        fileB = join(drepo, 'fileA')
502        drename = ExternalCommand(command=['darcs', 'mv'], cwd=drepo)
503        drename.execute(fileA, fileB)
504
505        dremove = ExternalCommand(command=['darcs', 'remove'], cwd=drepo)
506        dremove.execute(dir)
507
508        drecord.execute('Move dir/A to A and delete dir')
509
510        self.tailorize('darcs_rename_delete_dir')
Note: See TracBrowser for help on using the repository browser.