~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_conflicts.py

Cleanup test classes.

* bzrlib/tests/blackbox/test_conflicts.py:
(TestBase): A new helper.
(TestConflicts, TestResolve): One class for each command.
(TestResolve.test_resolve_in_subdir): No need to restore the
current dir.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
# FIXME: These don't really look at the output of the conflict commands, just
26
26
# the number of lines - there should be more examination.
27
27
 
28
 
class TestConflicts(tests.TestCaseWithTransport):
 
28
class TestBase(tests.TestCaseWithTransport):
29
29
 
30
 
    def setUp(self):
31
 
        super(TestConflicts, self).setUp()
 
30
    def make_tree_with_conflicts(self):
32
31
        a_tree = self.make_branch_and_tree('a')
33
32
        self.build_tree_contents([
34
33
            ('a/myfile', 'contentsa\n'),
55
54
        a_tree.merge_from_branch(b_tree.branch)
56
55
        os.chdir('a')
57
56
 
 
57
 
 
58
class TestConflicts(TestBase):
 
59
 
 
60
    def setUp(self):
 
61
        super(TestConflicts, self).setUp()
 
62
        self.make_tree_with_conflicts()
 
63
 
58
64
    def test_conflicts(self):
59
65
        conflicts, errs = self.run_bzr('conflicts')
60
66
        self.assertEqual(3, len(conflicts.splitlines()))
63
69
        conflicts = self.run_bzr('conflicts --text')[0].splitlines()
64
70
        self.assertEqual(['my_other_file', 'myfile'], conflicts)
65
71
 
 
72
 
 
73
class TestResolve(TestBase):
 
74
 
 
75
    def setUp(self):
 
76
        super(TestResolve, self).setUp()
 
77
        self.make_tree_with_conflicts()
 
78
 
66
79
    def test_resolve(self):
67
80
        self.run_bzr('resolve myfile')
68
81
        conflicts, errs = self.run_bzr('conflicts')
79
92
 
80
93
    def test_resolve_in_subdir(self):
81
94
        """resolve when run from subdirectory should handle relative paths"""
82
 
        orig_dir = os.getcwdu()
83
 
        try:
84
 
            os.mkdir("subdir")
85
 
            os.chdir("subdir")
86
 
            self.run_bzr("resolve ../myfile")
87
 
            os.chdir("../../b")
88
 
            self.run_bzr("resolve ../a/myfile")
89
 
            wt = workingtree.WorkingTree.open_containing('.')[0]
90
 
            conflicts = wt.conflicts()
91
 
            if not conflicts.is_empty():
92
 
                self.fail("tree still contains conflicts: %r" % conflicts)
93
 
        finally:
94
 
            os.chdir(orig_dir)
 
95
        os.mkdir("subdir")
 
96
        os.chdir("subdir")
 
97
        self.run_bzr("resolve ../myfile")
 
98
        os.chdir("../../b")
 
99
        self.run_bzr("resolve ../a/myfile")
 
100
        wt = workingtree.WorkingTree.open_containing('.')[0]
 
101
        conflicts = wt.conflicts()
 
102
        if not conflicts.is_empty():
 
103
            self.fail("tree still contains conflicts: %r" % conflicts)
95
104
 
96
105
    def test_auto_resolve(self):
97
106
        """Text conflicts can be resolved automatically"""
110
119
        self.build_tree_contents([('file', 'a\n')])
111
120
        note = self.run_bzr('resolve')[1]
112
121
        self.assertContainsRe(note, 'All conflicts resolved.')
 
122