20
20
from bzrlib import (
29
from bzrlib.tests import script
32
def load_tests(standard_tests, module, loader):
33
result = loader.suiteClass()
35
sp_tests, remaining_tests = tests.split_suite_by_condition(
36
standard_tests, tests.condition_isinstance((
37
TestParametrizedResolveConflicts,
39
# Each test class defines its own scenarios. This is needed for
40
# TestResolvePathConflictBefore531967 that verifies that the same tests as
41
# TestResolvePathConflict still pass.
42
for test in tests.iter_suite_tests(sp_tests):
43
tests.apply_scenarios(test, test.scenarios(), result)
45
# No parametrization for the remaining tests
46
result.addTests(remaining_tests)
28
from bzrlib.tests import (
34
load_tests = scenarios.load_tests_apply_scenarios
51
37
# TODO: Test commit with some added, and added-but-missing files
298
"""Return the scenario list for the conflict type defined by the class.
300
Each scenario is of the form:
301
(common, (left_name, left_dict), (right_name, right_dict))
305
* left_name and right_name are the scenario names that will be combined
307
* left_dict and right_dict are the attributes specific to each half of
308
the scenario. They should include at least 'actions' and 'check' and
309
will be available as '_this' and '_other' test instance attributes.
311
Daughters classes are free to add their specific attributes as they see
312
fit in any of the three dicts.
314
This is a class method so that load_tests can find it.
316
'_base_actions' in the common dict, 'actions' and 'check' in the left
317
and right dicts use names that map to methods in the test classes. Some
318
prefixes are added to these names to get the correspong methods (see
319
_get_actions() and _get_check()). The motivation here is to avoid
320
collisions in the class namespace.
322
# Only concrete classes return actual scenarios
278
"""The scenario list for the conflict type defined by the class.
280
Each scenario is of the form:
281
(common, (left_name, left_dict), (right_name, right_dict))
285
* left_name and right_name are the scenario names that will be combined
287
* left_dict and right_dict are the attributes specific to each half of
288
the scenario. They should include at least 'actions' and 'check' and
289
will be available as '_this' and '_other' test instance attributes.
291
Daughters classes are free to add their specific attributes as they see
292
fit in any of the three dicts.
294
This is a class method so that load_tests can find it.
296
'_base_actions' in the common dict, 'actions' and 'check' in the left
297
and right dicts use names that map to methods in the test classes. Some
298
prefixes are added to these names to get the correspong methods (see
299
_get_actions() and _get_check()). The motivation here is to avoid
300
collisions in the class namespace.
326
304
super(TestParametrizedResolveConflicts, self).setUp()
369
class TestResolveTextConflicts(TestParametrizedResolveConflicts):
371
_conflict_type = conflicts.TextConflict
373
# Set by the scenarios
374
# path and file-id for the file involved in the conflict
378
scenarios = mirror_scenarios(
380
# File modified on both sides
381
(dict(_base_actions='create_file',
382
_path='file', _file_id='file-id'),
384
dict(actions='modify_file_A', check='file_has_content_A')),
386
dict(actions='modify_file_B', check='file_has_content_B')),),
387
# File modified on both sides in dir
388
(dict(_base_actions='create_file_in_dir',
389
_path='dir/file', _file_id='file-id'),
390
('filed_modified_A_in_dir',
391
dict(actions='modify_file_A',
392
check='file_in_dir_has_content_A')),
394
dict(actions='modify_file_B',
395
check='file_in_dir_has_content_B')),),
398
def do_create_file(self, path='file'):
399
return [('add', (path, 'file-id', 'file', 'trunk content\n'))]
401
def do_modify_file_A(self):
402
return [('modify', ('file-id', 'trunk content\nfeature A\n'))]
404
def do_modify_file_B(self):
405
return [('modify', ('file-id', 'trunk content\nfeature B\n'))]
407
def check_file_has_content_A(self, path='file'):
408
self.assertFileEqual('trunk content\nfeature A\n',
409
osutils.pathjoin('branch', path))
411
def check_file_has_content_B(self, path='file'):
412
self.assertFileEqual('trunk content\nfeature B\n',
413
osutils.pathjoin('branch', path))
415
def do_create_file_in_dir(self):
416
return [('add', ('dir', 'dir-id', 'directory', '')),
417
] + self.do_create_file('dir/file')
419
def check_file_in_dir_has_content_A(self):
420
self.check_file_has_content_A('dir/file')
422
def check_file_in_dir_has_content_B(self):
423
self.check_file_has_content_B('dir/file')
425
def _get_resolve_path_arg(self, wt, action):
428
def assertTextConflict(self, wt, c):
429
self.assertEqual(self._file_id, c.file_id)
430
self.assertEqual(self._path, c.path)
431
_assert_conflict = assertTextConflict
391
434
class TestResolveContentsConflict(TestParametrizedResolveConflicts):
393
_conflict_type = conflicts.ContentsConflict,
436
_conflict_type = conflicts.ContentsConflict
395
# Set by load_tests from scenarios()
438
# Set by the scenarios
396
439
# path and file-id for the file involved in the conflict
443
scenarios = mirror_scenarios(
403
445
# File modified/deleted
404
446
(dict(_base_actions='create_file',
405
447
_path='file', _file_id='file-id'),
407
449
dict(actions='modify_file', check='file_has_more_content')),
409
451
dict(actions='delete_file', check='file_doesnt_exist')),),
411
return mirror_scenarios(base_scenarios)
452
# File modified/deleted in dir
453
(dict(_base_actions='create_file_in_dir',
454
_path='dir/file', _file_id='file-id'),
455
('file_modified_in_dir',
456
dict(actions='modify_file_in_dir',
457
check='file_in_dir_has_more_content')),
458
('file_deleted_in_dir',
459
dict(actions='delete_file',
460
check='file_in_dir_doesnt_exist')),),
413
463
def do_create_file(self):
414
464
return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
425
475
def check_file_doesnt_exist(self):
426
476
self.failIfExists('branch/file')
478
def do_create_file_in_dir(self):
479
return [('add', ('dir', 'dir-id', 'directory', '')),
480
('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
482
def do_modify_file_in_dir(self):
483
return [('modify', ('file-id', 'trunk content\nmore content\n'))]
485
def check_file_in_dir_has_more_content(self):
486
self.assertFileEqual('trunk content\nmore content\n', 'branch/dir/file')
488
def check_file_in_dir_doesnt_exist(self):
489
self.failIfExists('branch/dir/file')
428
491
def _get_resolve_path_arg(self, wt, action):
429
492
return self._path
457
519
# PathConflicts deletion handling requires a special
458
520
# hard-coded value
459
521
path='<deleted>', file_id='file-id')),),
522
# File renamed/deleted in dir
523
(dict(_base_actions='create_file_in_dir'),
524
('file_renamed_in_dir',
525
dict(actions='rename_file_in_dir', check='file_in_dir_renamed',
526
path='dir/new-file', file_id='file-id')),
528
dict(actions='delete_file', check='file_in_dir_doesnt_exist',
529
# PathConflicts deletion handling requires a special
531
path='<deleted>', file_id='file-id')),),
460
532
# File renamed/renamed differently
461
533
(dict(_base_actions='create_file'),
532
603
def check_dir_doesnt_exist(self):
533
604
self.failIfExists('branch/dir')
606
def do_create_file_in_dir(self):
607
return [('add', ('dir', 'dir-id', 'directory', '')),
608
('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
610
def do_rename_file_in_dir(self):
611
return [('rename', ('dir/file', 'dir/new-file'))]
613
def check_file_in_dir_renamed(self):
614
self.failIfExists('branch/dir/file')
615
self.failUnlessExists('branch/dir/new-file')
617
def check_file_in_dir_doesnt_exist(self):
618
self.failIfExists('branch/dir/file')
535
620
def _get_resolve_path_arg(self, wt, action):
536
621
tpath = self._this['path']
537
622
opath = self._other['path']
670
751
$ echo 'trunk content' >dir/file
672
$ bzr commit -m 'Create trunk'
753
$ bzr commit -m 'Create trunk' -q
674
754
$ echo 'trunk content' >dir/file2
676
$ bzr commit -m 'Add dir/file2 in branch'
678
$ bzr branch . -r 1 ../branch
755
$ bzr add -q dir/file2
756
$ bzr commit -q -m 'Add dir/file2 in branch'
757
$ bzr branch -q . -r 1 ../branch
680
$ bzr rm dir/file --force
682
$ bzr commit -m 'Remove dir/file'
759
$ bzr rm -q dir/file --force
761
$ bzr commit -q -m 'Remove dir/file'
684
762
$ bzr merge ../trunk
692
770
def test_keep_them_all(self):
693
771
self.run_script("""
694
772
$ bzr resolve dir
695
$ bzr commit --strict -m 'No more conflicts nor unknown files'
773
2>2 conflict(s) resolved, 0 remaining
774
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
698
777
def test_adopt_child(self):
699
778
self.run_script("""
700
$ bzr mv dir/file2 file2
779
$ bzr mv -q dir/file2 file2
780
$ bzr rm -q dir --force
702
781
$ bzr resolve dir
703
$ bzr commit --strict -m 'No more conflicts nor unknown files'
782
2>2 conflict(s) resolved, 0 remaining
783
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
706
786
def test_kill_them_all(self):
707
787
self.run_script("""
788
$ bzr rm -q dir --force
709
789
$ bzr resolve dir
710
$ bzr commit --strict -m 'No more conflicts nor unknown files'
790
2>2 conflict(s) resolved, 0 remaining
791
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
713
794
def test_resolve_taking_this(self):
714
795
self.run_script("""
715
796
$ bzr resolve --take-this dir
716
$ bzr commit --strict -m 'No more conflicts nor unknown files'
798
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
719
801
def test_resolve_taking_other(self):
720
802
self.run_script("""
721
803
$ bzr resolve --take-other dir
722
$ bzr commit --strict -m 'No more conflicts nor unknown files'
805
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
732
816
$ echo 'trunk content' >dir/file
734
$ bzr commit -m 'Create trunk'
736
$ bzr rm dir/file --force
738
$ bzr commit -m 'Remove dir/file'
740
$ bzr branch . -r 1 ../branch
818
$ bzr commit -m 'Create trunk' -q
819
$ bzr rm -q dir/file --force
820
$ bzr rm -q dir --force
821
$ bzr commit -q -m 'Remove dir/file'
822
$ bzr branch -q . -r 1 ../branch
742
824
$ echo 'branch content' >dir/file2
744
$ bzr commit -m 'Add dir/file2 in branch'
825
$ bzr add -q dir/file2
826
$ bzr commit -q -m 'Add dir/file2 in branch'
746
827
$ bzr merge ../trunk
748
829
2>Conflict: can't delete dir because it is not empty. Not deleting.
753
834
def test_keep_them_all(self):
754
835
self.run_script("""
755
836
$ bzr resolve dir
756
$ bzr commit --strict -m 'No more conflicts nor unknown files'
837
2>2 conflict(s) resolved, 0 remaining
838
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
759
841
def test_adopt_child(self):
760
842
self.run_script("""
761
$ bzr mv dir/file2 file2
843
$ bzr mv -q dir/file2 file2
844
$ bzr rm -q dir --force
763
845
$ bzr resolve dir
764
$ bzr commit --strict -m 'No more conflicts nor unknown files'
846
2>2 conflict(s) resolved, 0 remaining
847
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
767
850
def test_kill_them_all(self):
768
851
self.run_script("""
852
$ bzr rm -q dir --force
770
853
$ bzr resolve dir
771
$ bzr commit --strict -m 'No more conflicts nor unknown files'
854
2>2 conflict(s) resolved, 0 remaining
855
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
774
858
def test_resolve_taking_this(self):
775
859
self.run_script("""
776
860
$ bzr resolve --take-this dir
777
$ bzr commit --strict -m 'No more conflicts nor unknown files'
861
2>2 conflict(s) resolved, 0 remaining
862
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
780
865
def test_resolve_taking_other(self):
781
866
self.run_script("""
782
867
$ bzr resolve --take-other dir
783
$ bzr commit --strict -m 'No more conflicts nor unknown files'
870
2>2 conflict(s) resolved, 0 remaining
871
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
787
875
class TestResolveParentLoop(TestParametrizedResolveConflicts):
789
_conflict_type = conflicts.ParentLoop,
877
_conflict_type = conflicts.ParentLoop
791
879
_this_args = None
792
880
_other_args = None
796
# Each side dict additionally defines:
797
# - dir_id: the directory being moved
798
# - target_id: The target directory
799
# - xfail: whether the test is expected to fail if the action is
800
# involved as 'other'
882
# Each side dict additionally defines:
883
# - dir_id: the directory being moved
884
# - target_id: The target directory
885
# - xfail: whether the test is expected to fail if the action is
886
# involved as 'other'
887
scenarios = mirror_scenarios(
802
889
# Dirs moved into each other
803
890
(dict(_base_actions='create_dir1_dir2'),
804
891
('dir1_into_dir2',
907
993
def test_take_this(self):
908
994
self.run_script("""
909
$ bzr rm foo.new --force
995
$ bzr rm -q foo.new --force
910
996
# FIXME: Isn't it weird that foo is now unkown even if foo.new has been put
911
997
# aside ? -- vila 090916
913
999
$ bzr resolve foo.new
914
$ bzr commit --strict -m 'No more conflicts nor unknown files'
1000
2>1 conflict(s) resolved, 0 remaining
1001
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
917
1004
def test_take_other(self):
918
1005
self.run_script("""
1006
$ bzr rm -q foo --force
1007
$ bzr mv -q foo.new foo
921
1008
$ bzr resolve foo
922
$ bzr commit --strict -m 'No more conflicts nor unknown files'
1009
2>1 conflict(s) resolved, 0 remaining
1010
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
925
1013
def test_resolve_taking_this(self):
926
1014
self.run_script("""
927
1015
$ bzr resolve --take-this foo.new
928
$ bzr commit --strict -m 'No more conflicts nor unknown files'
1017
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
931
1020
def test_resolve_taking_other(self):
932
1021
self.run_script("""
933
1022
$ bzr resolve --take-other foo.new
934
$ bzr commit --strict -m 'No more conflicts nor unknown files'
1024
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'