/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5697.1.1 by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file.
1
# Copyright (C) 2005-2011 Canonical Ltd
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
6379.6.7 by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear.
18
"""Tests for weave-era working tree formats."""
19
6379.6.3 by Jelmer Vernooij
Use absolute_import.
20
from __future__ import absolute_import
21
5697.1.1 by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file.
22
import os
23
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
24
from ... import (
5697.1.1 by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file.
25
    conflicts,
26
    errors,
27
    )
28
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
29
from ...tests import (
5697.1.1 by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file.
30
    TestCaseWithTransport,
31
    )
32
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
33
from .bzrdir import BzrDirFormat6
5697.1.1 by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file.
34
35
36
class TestFormat2WorkingTree(TestCaseWithTransport):
37
    """Tests that are specific to format 2 trees."""
38
39
    def create_format2_tree(self, url):
40
        return self.make_branch_and_tree(
41
            url, format=BzrDirFormat6())
42
43
    def test_conflicts(self):
6745.1.2 by Jelmer Vernooij
s/compatability/compatibility/
44
        # test backwards compatibility
5697.1.1 by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file.
45
        tree = self.create_format2_tree('.')
46
        self.assertRaises(errors.UnsupportedOperation, tree.set_conflicts,
47
                          None)
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
48
        with open('lala.BASE', 'wb') as f:
49
            f.write(b'labase')
5697.1.1 by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file.
50
        expected = conflicts.ContentsConflict('lala')
51
        self.assertEqual(list(tree.conflicts()), [expected])
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
52
        with open('lala', 'wb') as f:
53
            f.write(b'la')
6855.4.1 by Jelmer Vernooij
Yet more bees.
54
        tree.add('lala', b'lala-id')
5697.1.1 by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file.
55
        expected = conflicts.ContentsConflict('lala', file_id='lala-id')
56
        self.assertEqual(list(tree.conflicts()), [expected])
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
57
        with open('lala.THIS', 'wb') as f:
58
            f.write(b'lathis')
59
        with open('lala.OTHER', 'wb') as f:
60
            f.write(b'laother')
5697.1.1 by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file.
61
        # When "text conflict"s happen, stem, THIS and OTHER are text
62
        expected = conflicts.TextConflict('lala', file_id='lala-id')
63
        self.assertEqual(list(tree.conflicts()), [expected])
64
        os.unlink('lala.OTHER')
65
        os.mkdir('lala.OTHER')
66
        expected = conflicts.ContentsConflict('lala', file_id='lala-id')
67
        self.assertEqual(list(tree.conflicts()), [expected])
68
69
    def test_detect_conflicts(self):
70
        """Conflicts are detected properly"""
71
        tree = self.create_format2_tree('.')
6855.4.1 by Jelmer Vernooij
Yet more bees.
72
        self.build_tree_contents([('hello', b'hello world4'),
73
                                  ('hello.THIS', b'hello world2'),
74
                                  ('hello.BASE', b'hello world1'),
75
                                  ('hello.OTHER', b'hello world3'),
76
                                  ('hello.sploo.BASE', b'yellowworld'),
77
                                  ('hello.sploo.OTHER', b'yellowworld2'),
5697.1.1 by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file.
78
                                  ])
79
        tree.lock_read()
80
        self.assertLength(6, list(tree.list_files()))
81
        tree.unlock()
82
        tree_conflicts = tree.conflicts()
83
        self.assertLength(2, tree_conflicts)
84
        self.assertTrue('hello' in tree_conflicts[0].path)
85
        self.assertTrue('hello.sploo' in tree_conflicts[1].path)
86
        conflicts.restore('hello')
87
        conflicts.restore('hello.sploo')
88
        self.assertLength(0, tree.conflicts())
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
89
        self.assertFileEqual(b'hello world2', 'hello')
5697.1.1 by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file.
90
        self.assertFalse(os.path.lexists('hello.sploo'))
91
        self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
92
        self.assertRaises(errors.NotConflicted,
93
                          conflicts.restore, 'hello.sploo')