~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testworkingtree.py

- refactor handling of short option names

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from bzrlib.branch import Branch
20
20
from bzrlib.selftest import TestCaseInTempDir
21
21
from bzrlib.trace import mutter
22
 
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
23
 
                                WorkingTree)
 
22
from bzrlib.workingtree import TreeEntry, TreeDirectory, TreeFile, TreeLink
24
23
 
25
24
class TestTreeDirectory(TestCaseInTempDir):
26
25
 
58
57
        self.assertEqual(files[0], ('dir', '?', 'directory', None, TreeDirectory()))
59
58
        self.assertEqual(files[1], ('file', '?', 'file', None, TreeFile()))
60
59
        self.assertEqual(files[2], ('symlink', '?', 'symlink', None, TreeLink()))
61
 
 
62
 
    def test_construct_with_branch(self):
63
 
        branch = Branch.initialize('.')
64
 
        tree = WorkingTree(branch.base, branch)
65
 
        self.assertEqual(branch, tree.branch)
66
 
        self.assertEqual(branch.inventory, tree._inventory)
67
 
        self.assertEqual(branch.base, tree.basedir)
68
 
    
69
 
    def test_construct_without_branch(self):
70
 
        branch = Branch.initialize('.')
71
 
        tree = WorkingTree(branch.base)
72
 
        self.assertEqual(branch.base, tree.branch.base)
73
 
        self.assertEqual(branch.inventory, tree._inventory)
74
 
        self.assertEqual(branch.base, tree.basedir)
75
 
 
76
 
    def test_basic_relpath(self):
77
 
        # for comprehensive relpath tests, see whitebox.py.
78
 
        branch = Branch.initialize('.')
79
 
        tree = WorkingTree(branch.base)
80
 
        self.assertEqual('child',
81
 
                         tree.relpath(os.path.join(os.getcwd(), 'child')))
82
 
 
83
 
    def test_lock_locks_branch(self):
84
 
        branch = Branch.initialize('.')
85
 
        tree = WorkingTree(branch.base)
86
 
        tree.lock_read()
87
 
        self.assertEqual(1, tree.branch._lock_count)
88
 
        self.assertEqual('r', tree.branch._lock_mode)
89
 
        tree.unlock()
90
 
        self.assertEqual(None, tree.branch._lock_count)
91
 
        tree.lock_write()
92
 
        self.assertEqual(1, tree.branch._lock_count)
93
 
        self.assertEqual('w', tree.branch._lock_mode)
94
 
        tree.unlock()
95
 
        self.assertEqual(None, tree.branch._lock_count)
96
 
 
97
 
    def get_pullable_branches(self):
98
 
        self.build_tree(['from/', 'from/file', 'to/'])
99
 
        br_a = Branch.initialize('from')
100
 
        br_a.add('file')
101
 
        br_a.commit('foo', rev_id='A')
102
 
        br_b = Branch.initialize('to')
103
 
        return br_a, br_b
104
 
 
105
 
    def test_pull(self):
106
 
        br_a, br_b = self.get_pullable_branches()
107
 
        br_b.working_tree().pull(br_a)
108
 
        self.failUnless(br_b.has_revision('A'))
109
 
        self.assertEqual(['A'], br_b.revision_history())
110
 
 
111
 
    def test_pull_clobbers(self):
112
 
        br_a, br_b = self.get_pullable_branches()
113
 
        br_b.commit('foo', rev_id='B')
114
 
        self.assertEqual(['B'], br_b.revision_history())
115
 
        br_b.working_tree().pull(br_a, clobber=True)
116
 
        self.failUnless(br_b.has_revision('A'))
117
 
        self.failUnless(br_b.has_revision('B'))
118
 
        self.assertEqual(['A'], br_b.revision_history())