~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

Added conflict handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from bzrlib.tests import TestCaseInTempDir
2
2
from bzrlib.branch import Branch
3
3
from bzrlib.transform import TreeTransform
4
 
from bzrlib.errors import DuplicateKey
 
4
from bzrlib.errors import DuplicateKey, MalformedTransform
5
5
 
6
6
class TestTreeTransform(TestCaseInTempDir):
7
7
    def test_build(self):
34
34
            trans_id = transform.new_file('name', root, 'contents', 
35
35
                                          'my_pretties')
36
36
            transform.apply()
 
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()
37
58
            self.assertEqual('contents', file('name').read())
38
59
            self.assertEqual(wt.path2id('name'), 'my_pretties')
39
60
        finally: