/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_conflicts.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-12-21 06:03:07 UTC
  • mfrom: (4665.7.3 serve-init)
  • Revision ID: pqm@pqm.ubuntu.com-20091221060307-uvja3vdy1o6dzzy0
(mbp) example debian init script

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
 
18
18
import os
19
19
 
20
 
from bzrlib import bzrdir
21
 
from bzrlib.tests import TestCaseWithTransport, TestCase
22
 
from bzrlib.branch import Branch
23
 
from bzrlib.conflicts import (
24
 
    ConflictList,
25
 
    ContentsConflict,
26
 
    DuplicateID,
27
 
    DuplicateEntry,
28
 
    MissingParent,
29
 
    NonDirectoryParent,
30
 
    ParentLoop,
31
 
    PathConflict,
32
 
    TextConflict,
33
 
    UnversionedParent,
34
 
    resolve,
35
 
    restore,
 
20
from bzrlib import (
 
21
    bzrdir,
 
22
    conflicts,
 
23
    errors,
 
24
    tests,
 
25
    workingtree,
36
26
    )
37
 
from bzrlib.errors import NotConflicted
 
27
from bzrlib.tests import script
38
28
 
39
29
 
40
30
# TODO: Test commit with some added, and added-but-missing files
44
34
# be a sorted list.
45
35
# u'\xe5' == a with circle
46
36
# '\xc3\xae' == u'\xee' == i with hat
47
 
# So these are u'pathg' and 'idg' only with a circle and a hat. (shappo?)
48
 
example_conflicts = ConflictList([
49
 
    MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
50
 
    ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'),
51
 
    TextConflict(u'p\xe5tha'),
52
 
    PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
53
 
    DuplicateID('Unversioned existing file', u'p\xe5thc', u'p\xe5thc2',
54
 
                '\xc3\xaedc', '\xc3\xaedc'),
55
 
    DuplicateEntry('Moved existing file to',  u'p\xe5thdd.moved', u'p\xe5thd',
56
 
                   '\xc3\xaedd', None),
57
 
    ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
58
 
               None, '\xc3\xaed2e'),
59
 
    UnversionedParent('Versioned directory', u'p\xe5thf', '\xc3\xaedf'),
60
 
    NonDirectoryParent('Created directory', u'p\xe5thg', '\xc3\xaedg'),
 
37
# So these are u'path' and 'id' only with a circle and a hat. (shappo?)
 
38
example_conflicts = conflicts.ConflictList(
 
39
    [conflicts.MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
 
40
     conflicts.ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'),
 
41
     conflicts.TextConflict(u'p\xe5tha'),
 
42
     conflicts.PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
 
43
     conflicts.DuplicateID('Unversioned existing file',
 
44
                           u'p\xe5thc', u'p\xe5thc2',
 
45
                           '\xc3\xaedc', '\xc3\xaedc'),
 
46
    conflicts.DuplicateEntry('Moved existing file to',
 
47
                             u'p\xe5thdd.moved', u'p\xe5thd',
 
48
                             '\xc3\xaedd', None),
 
49
    conflicts.ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
 
50
                         None, '\xc3\xaed2e'),
 
51
    conflicts.UnversionedParent('Versioned directory',
 
52
                                u'p\xe5thf', '\xc3\xaedf'),
 
53
    conflicts.NonDirectoryParent('Created directory',
 
54
                                 u'p\xe5thg', '\xc3\xaedg'),
61
55
])
62
56
 
63
57
 
64
 
class TestConflicts(TestCaseWithTransport):
 
58
class TestConflicts(tests.TestCaseWithTransport):
65
59
 
66
60
    def test_conflicts(self):
67
61
        """Conflicts are detected properly"""
68
 
        tree = self.make_branch_and_tree('.',
69
 
            format=bzrdir.BzrDirFormat6())
70
 
        b = tree.branch
71
 
        file('hello', 'w').write('hello world4')
72
 
        file('hello.THIS', 'w').write('hello world2')
73
 
        file('hello.BASE', 'w').write('hello world1')
74
 
        file('hello.OTHER', 'w').write('hello world3')
75
 
        file('hello.sploo.BASE', 'w').write('yellow world')
76
 
        file('hello.sploo.OTHER', 'w').write('yellow world2')
 
62
        # Use BzrDirFormat6 so we can fake conflicts
 
63
        tree = self.make_branch_and_tree('.', format=bzrdir.BzrDirFormat6())
 
64
        self.build_tree_contents([('hello', 'hello world4'),
 
65
                                  ('hello.THIS', 'hello world2'),
 
66
                                  ('hello.BASE', 'hello world1'),
 
67
                                  ('hello.OTHER', 'hello world3'),
 
68
                                  ('hello.sploo.BASE', 'yellowworld'),
 
69
                                  ('hello.sploo.OTHER', 'yellowworld2'),
 
70
                                  ])
77
71
        tree.lock_read()
78
 
        self.assertEqual(len(list(tree.list_files())), 6)
 
72
        self.assertEqual(6, len(list(tree.list_files())))
79
73
        tree.unlock()
80
 
        conflicts = tree.conflicts()
81
 
        self.assertEqual(len(conflicts), 2)
82
 
        self.assert_('hello' in conflicts[0].path)
83
 
        self.assert_('hello.sploo' in conflicts[1].path)
84
 
        restore('hello')
85
 
        restore('hello.sploo')
86
 
        self.assertEqual(len(tree.conflicts()), 0)
 
74
        tree_conflicts = tree.conflicts()
 
75
        self.assertEqual(2, len(tree_conflicts))
 
76
        self.assertTrue('hello' in tree_conflicts[0].path)
 
77
        self.assertTrue('hello.sploo' in tree_conflicts[1].path)
 
78
        conflicts.restore('hello')
 
79
        conflicts.restore('hello.sploo')
 
80
        self.assertEqual(0, len(tree.conflicts()))
87
81
        self.assertFileEqual('hello world2', 'hello')
88
82
        self.assertFalse(os.path.lexists('hello.sploo'))
89
 
        self.assertRaises(NotConflicted, restore, 'hello')
90
 
        self.assertRaises(NotConflicted, restore, 'hello.sploo')
 
83
        self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
 
84
        self.assertRaises(errors.NotConflicted,
 
85
                          conflicts.restore, 'hello.sploo')
91
86
 
92
87
    def test_resolve_conflict_dir(self):
93
88
        tree = self.make_branch_and_tree('.')
94
 
        b = tree.branch
95
 
        file('hello', 'w').write('hello world4')
 
89
        self.build_tree_contents([('hello', 'hello world4'),
 
90
                                  ('hello.THIS', 'hello world2'),
 
91
                                  ('hello.BASE', 'hello world1'),
 
92
                                  ])
 
93
        os.mkdir('hello.OTHER')
96
94
        tree.add('hello', 'q')
97
 
        file('hello.THIS', 'w').write('hello world2')
98
 
        file('hello.BASE', 'w').write('hello world1')
99
 
        os.mkdir('hello.OTHER')
100
 
        l = ConflictList([TextConflict('hello')])
 
95
        l = conflicts.ConflictList([conflicts.TextConflict('hello')])
101
96
        l.remove_files(tree)
102
97
 
103
98
    def test_select_conflicts(self):
104
99
        tree = self.make_branch_and_tree('.')
105
 
        tree_conflicts = ConflictList([ContentsConflict('foo'),
106
 
                                       ContentsConflict('bar')])
107
 
        self.assertEqual((ConflictList([ContentsConflict('bar')]),
108
 
                          ConflictList([ContentsConflict('foo')])),
109
 
                         tree_conflicts.select_conflicts(tree, ['foo']))
110
 
        self.assertEqual((ConflictList(), tree_conflicts),
111
 
                         tree_conflicts.select_conflicts(tree, [''],
112
 
                         ignore_misses=True, recurse=True))
113
 
        tree_conflicts = ConflictList([ContentsConflict('foo/baz'),
114
 
                                       ContentsConflict('bar')])
115
 
        self.assertEqual((ConflictList([ContentsConflict('bar')]),
116
 
                          ConflictList([ContentsConflict('foo/baz')])),
117
 
                         tree_conflicts.select_conflicts(tree, ['foo'],
118
 
                                                         recurse=True,
119
 
                                                         ignore_misses=True))
120
 
        tree_conflicts = ConflictList([PathConflict('qux', 'foo/baz')])
121
 
        self.assertEqual((ConflictList(), tree_conflicts),
122
 
                         tree_conflicts.select_conflicts(tree, ['foo'],
123
 
                                                         recurse=True,
124
 
                                                         ignore_misses=True))
125
 
        self.assertEqual((tree_conflicts, ConflictList()),
126
 
                         tree_conflicts.select_conflicts(tree, ['foo'],
127
 
                                                         ignore_misses=True))
 
100
        clist = conflicts.ConflictList
 
101
 
 
102
        def check_select(not_selected, selected, paths, **kwargs):
 
103
            self.assertEqual(
 
104
                (not_selected, selected),
 
105
                tree_conflicts.select_conflicts(tree, paths, **kwargs))
 
106
 
 
107
        foo = conflicts.ContentsConflict('foo')
 
108
        bar = conflicts.ContentsConflict('bar')
 
109
        tree_conflicts = clist([foo, bar])
 
110
 
 
111
        check_select(clist([bar]), clist([foo]), ['foo'])
 
112
        check_select(clist(), tree_conflicts,
 
113
                     [''], ignore_misses=True, recurse=True)
 
114
 
 
115
        foobaz  = conflicts.ContentsConflict('foo/baz')
 
116
        tree_conflicts = clist([foobaz, bar])
 
117
 
 
118
        check_select(clist([bar]), clist([foobaz]),
 
119
                     ['foo'], ignore_misses=True, recurse=True)
 
120
 
 
121
        qux = conflicts.PathConflict('qux', 'foo/baz')
 
122
        tree_conflicts = clist([qux])
 
123
 
 
124
        check_select(clist(), tree_conflicts,
 
125
                     ['foo'], ignore_misses=True, recurse=True)
 
126
        check_select (tree_conflicts, clist(), ['foo'], ignore_misses=True)
128
127
 
129
128
    def test_resolve_conflicts_recursive(self):
130
129
        tree = self.make_branch_and_tree('.')
131
130
        self.build_tree(['dir/', 'dir/hello'])
132
131
        tree.add(['dir', 'dir/hello'])
133
 
        tree.set_conflicts(ConflictList([TextConflict('dir/hello')]))
134
 
        resolve(tree, ['dir'], recursive=False, ignore_misses=True)
135
 
        self.assertEqual(ConflictList([TextConflict('dir/hello')]),
136
 
                         tree.conflicts())
137
 
        resolve(tree, ['dir'], recursive=True, ignore_misses=True)
138
 
        self.assertEqual(ConflictList([]),
139
 
                         tree.conflicts())
140
 
 
141
 
 
142
 
class TestConflictStanzas(TestCase):
 
132
 
 
133
        dirhello = conflicts.ConflictList([conflicts.TextConflict('dir/hello')])
 
134
        tree.set_conflicts(dirhello)
 
135
 
 
136
        conflicts.resolve(tree, ['dir'], recursive=False, ignore_misses=True)
 
137
        self.assertEqual(dirhello, tree.conflicts())
 
138
 
 
139
        conflicts.resolve(tree, ['dir'], recursive=True, ignore_misses=True)
 
140
        self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
 
141
 
 
142
 
 
143
class TestConflictStanzas(tests.TestCase):
143
144
 
144
145
    def test_stanza_roundtrip(self):
145
146
        # write and read our example stanza.
146
147
        stanza_iter = example_conflicts.to_stanzas()
147
 
        processed = ConflictList.from_stanzas(stanza_iter)
 
148
        processed = conflicts.ConflictList.from_stanzas(stanza_iter)
148
149
        for o, p in zip(processed, example_conflicts):
149
150
            self.assertEqual(o, p)
150
151
 
171
172
                self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
172
173
            if 'conflict_file_id' in stanza:
173
174
                self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
 
175