~ubuntu-branches/debian/jessie/bzr-fastimport/jessie

« back to all changes in this revision

Viewing changes to tests/test_generic_processor.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2010-11-06 18:40:27 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20101106184027-iclo8iim9equ6i8b
Tags: 0.9.0+bzr279-1
* New upstream snapshot.
* Bump standards version to 3.9.1 (no changes).
* Run testsuite during package build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import time
18
18
 
19
19
from bzrlib import (
20
 
    branch,
21
20
    tests,
22
21
    )
23
 
 
24
 
from bzrlib.plugins.fastimport import (
25
 
    commands,
26
 
    errors,
27
 
    )
28
 
 
29
 
from bzrlib.plugins.fastimport.processors import (
30
 
    generic_processor,
31
 
    )
 
22
from bzrlib.plugins.fastimport.helpers import (
 
23
    kind_to_mode,
 
24
    )
 
25
from bzrlib.plugins.fastimport.tests import (
 
26
    FastimportFeature,
 
27
    )
 
28
 
 
29
try:
 
30
    from fastimport import commands
 
31
except ImportError:
 
32
    commands = object()
32
33
 
33
34
 
34
35
def load_tests(standard_tests, module, loader):
49
50
 
50
51
class TestCaseForGenericProcessor(tests.TestCaseWithTransport):
51
52
 
 
53
    _test_needs_features = [FastimportFeature]
 
54
 
52
55
    branch_format = "pack-0.92"
53
56
 
54
57
    def get_handler(self):
 
58
        from bzrlib.plugins.fastimport.processors import (
 
59
            generic_processor,
 
60
            )
55
61
        branch = self.make_branch('.', format=self.branch_format)
56
62
        handler = generic_processor.GenericProcessor(branch.bzrdir)
57
63
        return handler, branch
192
198
 
193
199
    def file_command_iter(self, path, kind='file', content='aaa',
194
200
        executable=False, to_kind=None, to_content='bbb', to_executable=None):
 
201
 
195
202
        # Revno 1: create a file or symlink
196
203
        # Revno 2: modify it
197
204
        if to_kind is None:
198
205
            to_kind = kind
199
206
        if to_executable is None:
200
207
            to_executable = executable
 
208
        mode = kind_to_mode(kind, executable)
 
209
        to_mode = kind_to_mode(to_kind, to_executable)
201
210
        def command_list():
202
211
            author = ['', 'bugs@a.com', time.time(), time.timezone]
203
212
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
204
213
            def files_one():
205
 
                yield commands.FileModifyCommand(path, kind, executable,
206
 
                        None, content)
 
214
                yield commands.FileModifyCommand(path, mode, None, content)
207
215
            yield commands.CommitCommand('head', '1', author,
208
216
                committer, "commit 1", None, [], files_one)
209
217
            def files_two():
210
 
                yield commands.FileModifyCommand(path, to_kind, to_executable,
211
 
                        None, to_content)
 
218
                yield commands.FileModifyCommand(path, to_mode, None, to_content)
212
219
            yield commands.CommitCommand('head', '2', author,
213
220
                committer, "commit 2", ":1", [], files_two)
214
221
        return command_list
310
317
 
311
318
class TestImportToPackModifyTwice(TestCaseForGenericProcessor):
312
319
    """This tests when the same file is modified twice in the one commit.
313
 
    
 
320
 
314
321
    Note: hg-fast-export produces data like this on occasions.
315
322
    """
316
323
 
317
324
    def file_command_iter(self, path, kind='file', content='aaa',
318
325
        executable=False, to_kind=None, to_content='bbb', to_executable=None):
 
326
 
319
327
        # Revno 1: create a file twice
320
328
        if to_kind is None:
321
329
            to_kind = kind
325
333
            author = ['', 'bugs@a.com', time.time(), time.timezone]
326
334
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
327
335
            def files_one():
328
 
                yield commands.FileModifyCommand(path, kind, executable,
 
336
                yield commands.FileModifyCommand(path, kind_to_mode(kind, executable),
329
337
                        None, content)
330
 
                yield commands.FileModifyCommand(path, to_kind, to_executable,
 
338
                yield commands.FileModifyCommand(path, kind_to_mode(to_kind, to_executable),
331
339
                        None, to_content)
332
340
            yield commands.CommitCommand('head', '1', author,
333
341
                committer, "commit 1", None, [], files_one)
346
354
class TestImportToPackModifyTricky(TestCaseForGenericProcessor):
347
355
 
348
356
    def file_command_iter(self, path1, path2, kind='file'):
 
357
 
349
358
        # Revno 1: create a file or symlink in a directory
350
359
        # Revno 2: create a second file that implicitly deletes the
351
360
        # first one because either:
355
364
            author = ['', 'bugs@a.com', time.time(), time.timezone]
356
365
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
357
366
            def files_one():
358
 
                yield commands.FileModifyCommand(path1, kind, False,
 
367
                yield commands.FileModifyCommand(path1, kind_to_mode(kind, False),
359
368
                        None, "aaa")
360
369
            yield commands.CommitCommand('head', '1', author,
361
370
                committer, "commit 1", None, [], files_one)
362
371
            def files_two():
363
 
                yield commands.FileModifyCommand(path2, kind, False,
 
372
                yield commands.FileModifyCommand(path2, kind_to_mode(kind, False),
364
373
                        None, "bbb")
365
374
            yield commands.CommitCommand('head', '2', author,
366
375
                committer, "commit 2", ":1", [], files_two)
423
432
class TestImportToPackDelete(TestCaseForGenericProcessor):
424
433
 
425
434
    def file_command_iter(self, path, kind='file'):
 
435
 
426
436
        # Revno 1: create a file or symlink
427
437
        # Revno 2: delete it
428
438
        def command_list():
429
439
            author = ['', 'bugs@a.com', time.time(), time.timezone]
430
440
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
431
441
            def files_one():
432
 
                yield commands.FileModifyCommand(path, kind, False,
 
442
                yield commands.FileModifyCommand(path, kind_to_mode(kind, False),
433
443
                        None, "aaa")
434
444
            yield commands.CommitCommand('head', '1', author,
435
445
                committer, "commit 1", None, [], files_one)
494
504
    """Test deletion of a newly added file."""
495
505
 
496
506
    def file_command_iter(self, path, kind='file'):
 
507
 
497
508
        # Revno 1: create a file or symlink then delete it
498
509
        def command_list():
499
510
            author = ['', 'bugs@a.com', time.time(), time.timezone]
500
511
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
501
512
            def files_one():
502
 
                yield commands.FileModifyCommand(path, kind, False,
 
513
                yield commands.FileModifyCommand(path, kind_to_mode(kind, False),
503
514
                        None, "aaa")
504
515
                yield commands.FileDeleteCommand(path)
505
516
            yield commands.CommitCommand('head', '1', author,
540
551
class TestImportToPackDeleteMultiLevel(TestCaseForGenericProcessor):
541
552
 
542
553
    def file_command_iter(self, paths, paths_to_delete):
 
554
 
543
555
        # Revno 1: create multiple files
544
556
        # Revno 2: delete multiple files
545
557
        def command_list():
547
559
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
548
560
            def files_one():
549
561
                for i, path in enumerate(paths):
550
 
                    yield commands.FileModifyCommand(path, 'file', False,
 
562
                    yield commands.FileModifyCommand(path, kind_to_mode('file', False),
551
563
                            None, "aaa%d" % i)
552
564
            yield commands.CommitCommand('head', '1', author,
553
565
                committer, "commit 1", None, [], files_one)
615
627
 
616
628
    def file_command_iter(self, path, kind='file', content='aaa',
617
629
        executable=False, to_kind=None, to_content='bbb', to_executable=None):
 
630
 
618
631
        # Revno 1: create a file or symlink
619
632
        # Revno 2: delete it and add it
620
633
        if to_kind is None:
625
638
            author = ['', 'bugs@a.com', time.time(), time.timezone]
626
639
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
627
640
            def files_one():
628
 
                yield commands.FileModifyCommand(path, kind, executable,
 
641
                yield commands.FileModifyCommand(path, kind_to_mode(kind, executable),
629
642
                        None, content)
630
643
            yield commands.CommitCommand('head', '1', author,
631
644
                committer, "commit 1", None, [], files_one)
632
645
            def files_two():
633
646
                yield commands.FileDeleteCommand(path)
634
 
                yield commands.FileModifyCommand(path, to_kind, to_executable,
 
647
                yield commands.FileModifyCommand(path, kind_to_mode(to_kind, to_executable),
635
648
                        None, to_content)
636
649
            yield commands.CommitCommand('head', '2', author,
637
650
                committer, "commit 2", ":1", [], files_two)
691
704
class TestImportToPackDeleteDirectory(TestCaseForGenericProcessor):
692
705
 
693
706
    def file_command_iter(self, paths, dir):
 
707
 
694
708
        # Revno 1: create multiple files
695
709
        # Revno 2: delete a directory holding those files
696
710
        def command_list():
698
712
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
699
713
            def files_one():
700
714
                for i, path in enumerate(paths):
701
 
                    yield commands.FileModifyCommand(path, 'file', False,
 
715
                    yield commands.FileModifyCommand(path, kind_to_mode('file', False),
702
716
                            None, "aaa%d" % i)
703
717
            yield commands.CommitCommand('head', '1', author,
704
718
                committer, "commit 1", None, [], files_one)
732
746
    """Test deleting a directory then adding a file in the same commit."""
733
747
 
734
748
    def file_command_iter(self, paths, dir, new_path, kind='file'):
 
749
 
735
750
        # Revno 1: create files in a directory
736
751
        # Revno 2: delete the directory then add a file into it
737
752
        def command_list():
739
754
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
740
755
            def files_one():
741
756
                for i, path in enumerate(paths):
742
 
                    yield commands.FileModifyCommand(path, kind, False,
 
757
                    yield commands.FileModifyCommand(path, kind_to_mode(kind, False),
743
758
                            None, "aaa%d" % i)
744
759
            yield commands.CommitCommand('head', '1', author,
745
760
                committer, "commit 1", None, [], files_one)
746
761
            def files_two():
747
762
                yield commands.FileDeleteCommand(dir)
748
 
                yield commands.FileModifyCommand(new_path, kind, False,
 
763
                yield commands.FileModifyCommand(new_path, kind_to_mode(kind, False),
749
764
                        None, "bbb")
750
765
            yield commands.CommitCommand('head', '2', author,
751
766
                committer, "commit 2", ":1", [], files_two)
781
796
class TestImportToPackRename(TestCaseForGenericProcessor):
782
797
 
783
798
    def get_command_iter(self, old_path, new_path, kind='file'):
 
799
 
784
800
        # Revno 1: create a file or symlink
785
801
        # Revno 2: rename it
786
802
        def command_list():
787
803
            author = ['', 'bugs@a.com', time.time(), time.timezone]
788
804
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
789
805
            def files_one():
790
 
                yield commands.FileModifyCommand(old_path, kind, False,
 
806
                yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
791
807
                        None, "aaa")
792
808
            yield commands.CommitCommand('head', '1', author,
793
809
                committer, "commit 1", None, [], files_one)
856
872
    """Test rename of a newly added file."""
857
873
 
858
874
    def get_command_iter(self, old_path, new_path, kind='file'):
 
875
 
859
876
        # Revno 1: create a file and rename it
860
877
        def command_list():
861
878
            author = ['', 'bugs@a.com', time.time(), time.timezone]
862
879
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
863
880
            def files_one():
864
 
                yield commands.FileModifyCommand(old_path, kind, False,
 
881
                yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
865
882
                        None, "aaa")
866
883
                yield commands.FileRenameCommand(old_path, new_path)
867
884
            yield commands.CommitCommand('head', '1', author,
907
924
    """Test rename to a destination path deleted in this commit."""
908
925
 
909
926
    def get_command_iter(self, old_path, new_path, kind='file'):
 
927
 
910
928
        # Revno 1: create two files
911
929
        # Revno 2: delete one, rename the other one to that path
912
930
        def command_list():
913
931
            author = ['', 'bugs@a.com', time.time(), time.timezone]
914
932
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
915
933
            def files_one():
916
 
                yield commands.FileModifyCommand(old_path, kind, False,
 
934
                yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
917
935
                        None, "aaa")
918
 
                yield commands.FileModifyCommand(new_path, kind, False,
 
936
                yield commands.FileModifyCommand(new_path, kind_to_mode(kind, False),
919
937
                        None, "bbb")
920
938
            yield commands.CommitCommand('head', '1', author,
921
939
                committer, "commit 1", None, [], files_one)
1019
1037
    """Test rename of a path previously modified in this commit."""
1020
1038
 
1021
1039
    def get_command_iter(self, old_path, new_path, kind='file'):
 
1040
 
1022
1041
        # Revno 1: create a file or symlink
1023
1042
        # Revno 2: modify then rename it
1024
1043
        def command_list():
1025
1044
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1026
1045
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1027
1046
            def files_one():
1028
 
                yield commands.FileModifyCommand(old_path, kind, False,
 
1047
                yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
1029
1048
                        None, "aaa")
1030
1049
            yield commands.CommitCommand('head', '1', author,
1031
1050
                committer, "commit 1", None, [], files_one)
1032
1051
            def files_two():
1033
 
                yield commands.FileModifyCommand(old_path, kind, False,
 
1052
                yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
1034
1053
                        None, "bbb")
1035
1054
                yield commands.FileRenameCommand(old_path, new_path)
1036
1055
            yield commands.CommitCommand('head', '2', author,
1134
1153
    """Test rename of a path then modfy the new-path in the same commit."""
1135
1154
 
1136
1155
    def get_command_iter(self, old_path, new_path, kind='file'):
 
1156
 
1137
1157
        # Revno 1: create a file or symlink
1138
1158
        # Revno 2: rename it then modify the newly created path
1139
1159
        def command_list():
1140
1160
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1141
1161
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1142
1162
            def files_one():
1143
 
                yield commands.FileModifyCommand(old_path, kind, False,
 
1163
                yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
1144
1164
                        None, "aaa")
1145
1165
            yield commands.CommitCommand('head', '1', author,
1146
1166
                committer, "commit 1", None, [], files_one)
1147
1167
            def files_two():
1148
1168
                yield commands.FileRenameCommand(old_path, new_path)
1149
 
                yield commands.FileModifyCommand(new_path, kind, False,
 
1169
                yield commands.FileModifyCommand(new_path, kind_to_mode(kind, False),
1150
1170
                        None, "bbb")
1151
1171
            yield commands.CommitCommand('head', '2', author,
1152
1172
                committer, "commit 2", ":1", [], files_two)
1249
1269
    """Test rename of to a deleted path then modfy the new-path in the same commit."""
1250
1270
 
1251
1271
    def get_command_iter(self, old_path, new_path, kind='file'):
 
1272
 
1252
1273
        # Revno 1: create two files or symlinks
1253
1274
        # Revno 2: delete one, rename the other to it then modify the newly created path
1254
1275
        def command_list():
1255
1276
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1256
1277
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1257
1278
            def files_one():
1258
 
                yield commands.FileModifyCommand(old_path, kind, False,
 
1279
                yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
1259
1280
                        None, "aaa")
1260
 
                yield commands.FileModifyCommand(new_path, kind, False,
 
1281
                yield commands.FileModifyCommand(new_path, kind_to_mode(kind, False),
1261
1282
                        None, "zzz")
1262
1283
            yield commands.CommitCommand('head', '1', author,
1263
1284
                committer, "commit 1", None, [], files_one)
1264
1285
            def files_two():
1265
1286
                yield commands.FileDeleteCommand(new_path)
1266
1287
                yield commands.FileRenameCommand(old_path, new_path)
1267
 
                yield commands.FileModifyCommand(new_path, kind, False,
 
1288
                yield commands.FileModifyCommand(new_path, kind_to_mode(kind, False),
1268
1289
                        None, "bbb")
1269
1290
            yield commands.CommitCommand('head', '2', author,
1270
1291
                committer, "commit 2", ":1", [], files_two)
1376
1397
class TestImportToPackRenameTricky(TestCaseForGenericProcessor):
1377
1398
 
1378
1399
    def file_command_iter(self, path1, old_path2, new_path2, kind='file'):
 
1400
 
1379
1401
        # Revno 1: create two files or symlinks in a directory
1380
1402
        # Revno 2: rename the second file so that it implicitly deletes the
1381
1403
        # first one because either:
1385
1407
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1386
1408
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1387
1409
            def files_one():
1388
 
                yield commands.FileModifyCommand(path1, kind, False,
 
1410
                yield commands.FileModifyCommand(path1, kind_to_mode(kind, False),
1389
1411
                        None, "aaa")
1390
 
                yield commands.FileModifyCommand(old_path2, kind, False,
 
1412
                yield commands.FileModifyCommand(old_path2, kind_to_mode(kind, False),
1391
1413
                        None, "bbb")
1392
1414
            yield commands.CommitCommand('head', '1', author,
1393
1415
                committer, "commit 1", None, [], files_one)
1459
1481
class TestImportToPackCopy(TestCaseForGenericProcessor):
1460
1482
 
1461
1483
    def file_command_iter(self, src_path, dest_path, kind='file'):
 
1484
 
1462
1485
        # Revno 1: create a file or symlink
1463
1486
        # Revno 2: copy it
1464
1487
        def command_list():
1465
1488
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1466
1489
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1467
1490
            def files_one():
1468
 
                yield commands.FileModifyCommand(src_path, kind, False,
 
1491
                yield commands.FileModifyCommand(src_path, kind_to_mode(kind, False),
1469
1492
                        None, "aaa")
1470
1493
            yield commands.CommitCommand('head', '1', author,
1471
1494
                committer, "commit 1", None, [], files_one)
1550
1573
    """Test copy of a newly added file."""
1551
1574
 
1552
1575
    def file_command_iter(self, src_path, dest_path, kind='file'):
 
1576
 
1553
1577
        # Revno 1: create a file or symlink and copy it
1554
1578
        def command_list():
1555
1579
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1556
1580
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1557
1581
            def files_one():
1558
 
                yield commands.FileModifyCommand(src_path, kind, False,
 
1582
                yield commands.FileModifyCommand(src_path, kind_to_mode(kind, False),
1559
1583
                        None, "aaa")
1560
1584
                yield commands.FileCopyCommand(src_path, dest_path)
1561
1585
            yield commands.CommitCommand('head', '1', author,
1630
1654
class TestImportToPackCopyToDeleted(TestCaseForGenericProcessor):
1631
1655
 
1632
1656
    def file_command_iter(self, src_path, dest_path, kind='file'):
 
1657
 
1633
1658
        # Revno 1: create two files or symlinks
1634
1659
        # Revno 2: delete one and copy the other one to its path
1635
1660
        def command_list():
1636
1661
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1637
1662
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1638
1663
            def files_one():
1639
 
                yield commands.FileModifyCommand(src_path, kind, False,
 
1664
                yield commands.FileModifyCommand(src_path, kind_to_mode(kind, False),
1640
1665
                        None, "aaa")
1641
 
                yield commands.FileModifyCommand(dest_path, kind, False,
 
1666
                yield commands.FileModifyCommand(dest_path, kind_to_mode(kind, False),
1642
1667
                        None, "bbb")
1643
1668
            yield commands.CommitCommand('head', '1', author,
1644
1669
                committer, "commit 1", None, [], files_one)
1718
1743
    """Test copy of file/symlink already modified in this commit."""
1719
1744
 
1720
1745
    def file_command_iter(self, src_path, dest_path, kind='file'):
 
1746
 
1721
1747
        # Revno 1: create a file or symlink
1722
1748
        # Revno 2: modify and copy it
1723
1749
        def command_list():
1724
1750
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1725
1751
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1726
1752
            def files_one():
1727
 
                yield commands.FileModifyCommand(src_path, kind, False,
 
1753
                yield commands.FileModifyCommand(src_path, kind_to_mode(kind, False),
1728
1754
                        None, "aaa")
1729
1755
            yield commands.CommitCommand('head', '1', author,
1730
1756
                committer, "commit 1", None, [], files_one)
1731
1757
            def files_two():
1732
 
                yield commands.FileModifyCommand(src_path, kind, False,
 
1758
                yield commands.FileModifyCommand(src_path, kind_to_mode(kind, False),
1733
1759
                        None, "bbb")
1734
1760
                yield commands.FileCopyCommand(src_path, dest_path)
1735
1761
            yield commands.CommitCommand('head', '2', author,
1816
1842
class TestImportToPackFileKinds(TestCaseForGenericProcessor):
1817
1843
 
1818
1844
    def get_command_iter(self, path, kind, content):
 
1845
 
1819
1846
        def command_list():
1820
1847
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1821
1848
            def files_one():
1822
 
                yield commands.FileModifyCommand(path, kind, False,
 
1849
                yield commands.FileModifyCommand(path, kind_to_mode(kind, False),
1823
1850
                        None, content)
1824
1851
            yield commands.CommitCommand('head', '1', None,
1825
1852
                committer, "commit 1", None, [], files_one)
1850
1877
            committer_c = ['', 'c@elmer.com', time.time(), time.timezone]
1851
1878
            committer_d = ['', 'd@elmer.com', time.time(), time.timezone]
1852
1879
            def files_one():
1853
 
                yield commands.FileModifyCommand('foo', 'file', False,
 
1880
                yield commands.FileModifyCommand('foo', kind_to_mode('file', False),
1854
1881
                        None, "content A\n")
1855
1882
            yield commands.CommitCommand('head', '1', None,
1856
1883
                committer_a, "commit 1", None, [], files_one)
1857
1884
            def files_two():
1858
 
                yield commands.FileModifyCommand('foo', 'file', False,
 
1885
                yield commands.FileModifyCommand('foo', kind_to_mode('file', False),
1859
1886
                        None, "content B\n")
1860
1887
            yield commands.CommitCommand('head', '2', None,
1861
1888
                committer_b, "commit 2", ":1", [], files_two)
1862
1889
            def files_three():
1863
 
                yield commands.FileModifyCommand('foo', 'file', False,
 
1890
                yield commands.FileModifyCommand('foo', kind_to_mode('file', False),
1864
1891
                        None, "content A\n")
1865
1892
            yield commands.CommitCommand('head', '3', None,
1866
1893
                committer_c, "commit 3", ":2", [], files_three)