/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1534.7.1 by Aaron Bentley
Got creation of a versioned file working
1
from bzrlib.tests import TestCaseInTempDir
2
from bzrlib.branch import Branch
3
from bzrlib.transform import TreeTransform
1534.7.6 by Aaron Bentley
Added conflict handling
4
from bzrlib.errors import DuplicateKey, MalformedTransform
1534.7.1 by Aaron Bentley
Got creation of a versioned file working
5
6
class TestTreeTransform(TestCaseInTempDir):
7
    def test_build(self):
8
        branch = Branch.initialize('.')
9
        wt = branch.working_tree()
10
        transform = TreeTransform(wt)
11
        try:
12
            root = transform.get_id_tree(wt.get_root_id())
1534.7.3 by Aaron Bentley
Updated to use a real root id. Or whatever the working tree considers real.
13
            trans_id = transform.create_path('name', root)
1534.7.1 by Aaron Bentley
Got creation of a versioned file working
14
            transform.create_file('contents', trans_id)
1534.7.5 by Aaron Bentley
Got unique_add under test
15
            self.assertRaises(DuplicateKey, transform.create_file, 'contents', 
16
                              trans_id)
1534.7.1 by Aaron Bentley
Got creation of a versioned file working
17
            transform.version_file('my_pretties', trans_id)
1534.7.5 by Aaron Bentley
Got unique_add under test
18
            self.assertRaises(DuplicateKey, transform.version_file,
19
                              'my_pretties', trans_id)
1534.7.1 by Aaron Bentley
Got creation of a versioned file working
20
            transform.apply()
21
            self.assertEqual('contents', file('name').read())
22
            self.assertEqual(wt.path2id('name'), 'my_pretties')
23
        finally:
24
            transform.finalize()
25
        # is it safe to finalize repeatedly?
26
        transform.finalize()
1534.7.2 by Aaron Bentley
Added convenience function
27
28
    def test_convenience(self):
29
        branch = Branch.initialize('.')
30
        wt = branch.working_tree()
31
        transform = TreeTransform(wt)
32
        try:
1534.7.3 by Aaron Bentley
Updated to use a real root id. Or whatever the working tree considers real.
33
            root = transform.get_id_tree(wt.get_root_id())
34
            trans_id = transform.new_file('name', root, 'contents', 
1534.7.2 by Aaron Bentley
Added convenience function
35
                                          'my_pretties')
36
            transform.apply()
1534.7.6 by Aaron Bentley
Added conflict handling
37
            self.assertEqual(len(transform.find_conflicts()), 0)
38
            self.assertEqual('contents', file('name').read())
39
            self.assertEqual(wt.path2id('name'), 'my_pretties')
40
        finally:
41
            transform.finalize()
42
43
    def test_conflicts(self):
44
        branch = Branch.initialize('.')
45
        wt = branch.working_tree()
46
        transform = TreeTransform(wt)
47
        try:
48
            root = transform.get_id_tree(wt.get_root_id())
49
            trans_id = transform.new_file('name', root, 'contents', 
50
                                          'my_pretties')
51
            self.assertEqual(len(transform.find_conflicts()), 0)
52
            trans_id2 = transform.new_file('name', root, 'Crontents', 'toto')
53
            self.assertEqual(transform.find_conflicts(), 
54
                             [('duplicate', trans_id, trans_id2)])
55
            self.assertRaises(MalformedTransform, transform.apply)
56
            transform.adjust_path('name2', root, trans_id2)
57
            transform.apply()
1534.7.2 by Aaron Bentley
Added convenience function
58
            self.assertEqual('contents', file('name').read())
59
            self.assertEqual(wt.path2id('name'), 'my_pretties')
60
        finally:
61
            transform.finalize()