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

Revision 1213, 12.8 KB checked in by lele@…, 7 years ago (diff)

Remove the directory once the test is done (commented out by error)

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.basedir, dwd.target.basedir,
296                            stdout=PIPE)[0]
297            return out.read()
298        else:
299            return ""
300
301    def tailorize(self, project):
302        "The actual test"
303
304        tailorizer = Tailorizer(project, self.config)
305        self.assert_(not tailorizer.exists(),
306                     "For test purposes, better start from scratch!")
307        tailorizer()
308        self.assertEqual(self.diffWhenPossible(tailorizer), "")
309
310class Darcs(OperationalTest):
311    "Test darcs backend"
312
313    def testConfiguration(self):
314        "Test basic configuration"
315
316        p = Tailorizer('darcs2svn', self.config)
317        self.assertEqual(p.source.subdir, 'darcside')
318        self.assertEqual(p.rootdir, '%s/darcs2svn' % self.TESTDIR)
319        self.assertEqual(p.source.repository, self.tailor_repo)
320        self.assertEqual(p.target.repository,
321                         'file://%s/svnrepo' % self.TESTDIR)
322        self.assertEqual(p.state_file.filename,
323                         '%s/darcs2svn/tailor.state' % self.TESTDIR)
324
325        tailorizer = Tailorizer('cvs2darcs', self.config)
326        self.assertEqual(tailorizer.subdir, 'pxlib')
327        self.assertEqual(tailorizer.source.subdir, 'pxlib')
328
329    def testDarcsAndBazaarng(self):
330        "Test darcs to bazaar-ng and the other way around"
331
332        self.tailorize('darcs2bzr')
333        self.tailorize('bzr2darcs')
334
335    def testDarcsToMercurial(self):
336        "Test darcs to mercurial"
337
338        self.tailorize('darcs2hg')
339
340    def testDarcsToCodeville(self):
341        "Test darcs to codeville"
342
343        self.tailorize('darcs2cdv')
344
345    def testDarcsAndSubversion(self):
346        "Test darcs to subversion and the other way around"
347
348        self.tailorize('darcs2svn')
349        self.tailorize('svn2darcs')
350
351    def testDarcsAndMonotone(self):
352        "Test darcs to monotone and the other way around"
353
354        self.tailorize('darcs2monotone')
355        self.tailorize('monotone2darcs')
356
357
358class Bazaarng(OperationalTest):
359    "Test the BazaarNG source backend"
360
361    def testBazaarngAndPython23(self):
362        "Test we detect early when running under Python < 2.4"
363
364        from sys import version_info
365
366        if version_info < (2,4):
367            try:
368                self.tailorize('bazaarng2darcs')
369            except TailorException, e:
370                self.assert_("Bazaar-NG backend requires Python 2.4"
371                             in str(e))
372            else:
373                self.fail("Expected a specific TailorException")
374
375    def testBazaarngToDarcs(self):
376        "Test bazaar-ng to darcs"
377
378        try:
379            self.tailorize('bazaarng2darcs')
380        except TailorException, e:
381            from sys import version_info
382
383            if version_info < (2,4):
384                # Under python 2.3 we expect an exception here, but
385                # different from the above: since we are still in a
386                # single python session importing the bzr stuff does
387                # not raise the same error, because from the python
388                # runtime pov the module is already loaded and thus
389                # the second import does not fail. The repository
390                # class will then instantiate the raw Repository
391                # class, not the specific bzr one. Still, when asked
392                # for a working dir, it will fail again
393                self.assert_("object has no attribute 'BzrWorkingDir'"
394                             in str(e))
395            else:
396                raise
397
398
399
400class Cvs(OperationalTest):
401    "Test the CVS source backend"
402
403    def testCvsToDarcs(self):
404        "Test CVS to darcs"
405
406        self.tailorize('cvs2darcs')
407
408    def testDarcsToCvs(self):
409        "Test Darcs to CVS"
410
411        self.tailorize('darcs2cvs')
412
413    def testCvsToMercurial(self):
414        "Test CVS to mercurial"
415
416        self.tailorize('cvs2hg')
417
418    def testCvsToBazaarng(self):
419        "Test CVS to bazaar-ng"
420
421        self.tailorize('cvs2bzr')
422
423    def testCvsToSubversion(self):
424        "Test CVS branch to Subversion"
425
426        self.tailorize('cvs2svn')
427
428
429class Svn(OperationalTest):
430    "Test the subversion backend"
431
432    def testExternals(self):
433        "Exercise svn to mercurial with and without svn:externals"
434
435        from os.path import exists
436
437        external = self.TESTDIR + '/svn2hg%s/test/make/docutils.make'
438        self.tailorize('svn2hg')
439        self.failIf(exists(external % ''))
440
441        self.tailorize('svn2hg_with_externals')
442        self.failUnless(exists(external % '_we'))
443
444    def testDarcsRenameDelete(self):
445        "Try to migrate a darcs patch that renames and removes the same file"
446
447        from os import mkdir
448        from os.path import join
449
450        drepo = join(self.TESTDIR, 'rename_delete')
451        mkdir(drepo)
452
453        dinit = ExternalCommand(command=['darcs', 'init'], cwd=drepo)
454        dinit.execute()
455
456        fileA = join(drepo, 'fileA')
457        open(fileA, 'w')
458        dadd = ExternalCommand(command=['darcs', 'add'], cwd=drepo)
459        dadd.execute(fileA)
460
461        drecord = ExternalCommand(command=['darcs', 'record',
462                                           '-a', '-m'], cwd=drepo)
463        drecord.execute('Add A')
464
465        fileB = join(drepo, 'fileB')
466        drename = ExternalCommand(command=['darcs', 'mv'], cwd=drepo)
467        drename.execute(fileA, fileB)
468
469        dremove = ExternalCommand(command=['darcs', 'remove'], cwd=drepo)
470        dremove.execute(fileB)
471
472        drecord.execute('Move A to B and delete B')
473
474        self.tailorize('darcs_rename_delete')
475
476    def testDarcsRenameDeleteDir(self):
477        "Test if darcs to svn fails on moves combined with directory deletes"
478
479        from os import mkdir
480        from os.path import join
481
482        drepo = join(self.TESTDIR, 'rename_delete_dir')
483        mkdir(drepo)
484
485        dinit = ExternalCommand(command=['darcs', 'init'], cwd=drepo)
486        dinit.execute()
487
488        dir = join(drepo, 'dir')
489        mkdir(dir)
490        dadd = ExternalCommand(command=['darcs', 'add'], cwd=drepo)
491        dadd.execute(dir)
492        fileA = join(dir, 'fileA')
493        open(fileA, 'w')
494        dadd.execute(fileA)
495
496        drecord = ExternalCommand(command=['darcs', 'record',
497                                           '-a', '-m'], cwd=drepo)
498        drecord.execute('Add dir and dir/A')
499
500        fileB = join(drepo, 'fileA')
501        drename = ExternalCommand(command=['darcs', 'mv'], cwd=drepo)
502        drename.execute(fileA, fileB)
503
504        dremove = ExternalCommand(command=['darcs', 'remove'], cwd=drepo)
505        dremove.execute(dir)
506
507        drecord.execute('Move dir/A to A and delete dir')
508
509        self.tailorize('darcs_rename_delete_dir')
Note: See TracBrowser for help on using the repository browser.