~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_versioning.py

  • Committer: Jelmer Vernooij
  • Date: 2011-02-19 15:23:08 UTC
  • mto: (5582.12.2 weave-plugin)
  • mto: This revision was merged to the branch mainline in revision 5718.
  • Revision ID: jelmer@samba.org-20110219152308-5shhc4rj0ez4oa12
move xml4 to weave plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2009-2012 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2009, 2010 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
39
39
        # here locally.
40
40
        shared_repo = self.make_repository('.')
41
41
        self.run_bzr(['mkdir', 'abc'], retcode=3)
42
 
        self.assertPathDoesNotExist('abc')
 
42
        self.failIfExists('abc')
 
43
 
 
44
 
 
45
class TestVersioning(TestCaseInTempDir):
43
46
 
44
47
    def test_mkdir(self):
45
48
        """Basic 'bzr mkdir' operation"""
46
49
 
47
 
        self.make_branch_and_tree('.')
 
50
        self.run_bzr('init')
48
51
        self.run_bzr(['mkdir', 'foo'])
49
52
        self.assert_(os.path.isdir('foo'))
50
53
 
58
61
 
59
62
        self.assertEquals(len(delta.added), 1)
60
63
        self.assertEquals(delta.added[0][0], 'foo')
61
 
        self.assertFalse(delta.modified)
 
64
        self.failIf(delta.modified)
62
65
 
63
66
    def test_mkdir_in_subdir(self):
64
67
        """'bzr mkdir' operation in subdirectory"""
65
68
 
66
 
        self.make_branch_and_tree('.')
 
69
        self.run_bzr('init')
67
70
        self.run_bzr(['mkdir', 'dir'])
68
71
        self.assert_(os.path.isdir('dir'))
69
72
 
 
73
        os.chdir('dir')
70
74
        self.log('Run mkdir in subdir')
71
 
        self.run_bzr(['mkdir', 'subdir'], working_dir='dir')
72
 
        self.assert_(os.path.isdir('dir/subdir'))
 
75
        self.run_bzr(['mkdir', 'subdir'])
 
76
        self.assert_(os.path.isdir('subdir'))
 
77
        os.chdir('..')
73
78
 
74
79
        wt = WorkingTree.open('.')
75
80
 
80
85
        self.assertEquals(len(delta.added), 2)
81
86
        self.assertEquals(delta.added[0][0], 'dir')
82
87
        self.assertEquals(delta.added[1][0], pathjoin('dir','subdir'))
83
 
        self.assertFalse(delta.modified)
 
88
        self.failIf(delta.modified)
84
89
 
85
90
    def test_mkdir_w_nested_trees(self):
86
91
        """'bzr mkdir' with nested trees"""
87
92
 
88
 
        self.make_branch_and_tree('.')
89
 
        self.make_branch_and_tree('a')
90
 
        self.make_branch_and_tree('a/b')
 
93
        self.run_bzr('init')
 
94
        os.mkdir('a')
 
95
        os.chdir('a')
 
96
        self.run_bzr('init')
 
97
        os.mkdir('b')
 
98
        os.chdir('b')
 
99
        self.run_bzr('init')
 
100
        os.chdir('../..')
91
101
 
92
102
        self.run_bzr(['mkdir', 'dir', 'a/dir', 'a/b/dir'])
93
 
        self.assertTrue(os.path.isdir('dir'))
94
 
        self.assertTrue(os.path.isdir('a/dir'))
95
 
        self.assertTrue(os.path.isdir('a/b/dir'))
 
103
        self.failUnless(os.path.isdir('dir'))
 
104
        self.failUnless(os.path.isdir('a/dir'))
 
105
        self.failUnless(os.path.isdir('a/b/dir'))
96
106
 
97
107
        wt = WorkingTree.open('.')
98
108
        wt_a = WorkingTree.open('a')
101
111
        delta = wt.changes_from(wt.basis_tree())
102
112
        self.assertEquals(len(delta.added), 1)
103
113
        self.assertEquals(delta.added[0][0], 'dir')
104
 
        self.assertFalse(delta.modified)
 
114
        self.failIf(delta.modified)
105
115
 
106
116
        delta = wt_a.changes_from(wt_a.basis_tree())
107
117
        self.assertEquals(len(delta.added), 1)
108
118
        self.assertEquals(delta.added[0][0], 'dir')
109
 
        self.assertFalse(delta.modified)
 
119
        self.failIf(delta.modified)
110
120
 
111
121
        delta = wt_b.changes_from(wt_b.basis_tree())
112
122
        self.assertEquals(len(delta.added), 1)
113
123
        self.assertEquals(delta.added[0][0], 'dir')
114
 
        self.assertFalse(delta.modified)
115
 
 
116
 
    def test_mkdir_quiet(self):
117
 
        """'bzr mkdir --quiet' should not print a status message"""
118
 
 
119
 
        self.make_branch_and_tree('.')
120
 
        out, err = self.run_bzr(['mkdir', '--quiet', 'foo'])
121
 
        self.assertEquals('', err)
122
 
        self.assertEquals('', out)
 
124
        self.failIf(delta.modified)
 
125
 
 
126
    def check_branch(self):
 
127
        """After all the above changes, run the check and upgrade commands.
 
128
 
 
129
        The upgrade should be a no-op."""
 
130
        b = Branch.open(u'.')
 
131
        mutter('branch has %d revisions', b.revno())
 
132
 
 
133
        mutter('check branch...')
 
134
        from bzrlib.check import check
 
135
        check(b, False)
123
136
 
124
137
 
125
138
class SubdirCommit(TestCaseWithTransport):
146
159
        new = b.repository.revision_tree(b.get_rev_id(2))
147
160
        new.lock_read()
148
161
 
149
 
        def get_text_by_path(tree, path):
150
 
            return tree.get_file_text(tree.path2id(path), path)
151
 
 
152
 
        self.assertEqual(get_text_by_path(new, 'b/two'), 'old contents')
153
 
        self.assertEqual(get_text_by_path(new, 'top'), 'old contents')
154
 
        self.assertEqual(get_text_by_path(new, 'a/one'), 'new contents')
 
162
        self.assertEqual(new.get_file_by_path('b/two').read(), 'old contents')
 
163
        self.assertEqual(new.get_file_by_path('top').read(), 'old contents')
 
164
        self.assertEqual(new.get_file_by_path('a/one').read(), 'new contents')
155
165
        new.unlock()
156
166
 
 
167
        os.chdir('a')
157
168
        # commit from here should do nothing
158
 
        self.run_bzr(['commit', '.', '-m', 'commit subdir only', '--unchanged'],
159
 
                     working_dir='a')
 
169
        self.run_bzr(['commit', '.', '-m', 'commit subdir only', '--unchanged'])
160
170
        v3 = b.repository.revision_tree(b.get_rev_id(3))
161
171
        v3.lock_read()
162
 
        self.assertEqual(get_text_by_path(v3, 'b/two'), 'old contents')
163
 
        self.assertEqual(get_text_by_path(v3, 'top'), 'old contents')
164
 
        self.assertEqual(get_text_by_path(v3, 'a/one'), 'new contents')
 
172
        self.assertEqual(v3.get_file_by_path('b/two').read(), 'old contents')
 
173
        self.assertEqual(v3.get_file_by_path('top').read(), 'old contents')
 
174
        self.assertEqual(v3.get_file_by_path('a/one').read(), 'new contents')
165
175
        v3.unlock()
166
176
 
167
177
        # commit in subdirectory commits whole tree
168
 
        self.run_bzr(['commit', '-m', 'commit whole tree from subdir'],
169
 
                     working_dir='a')
 
178
        self.run_bzr(['commit', '-m', 'commit whole tree from subdir'])
170
179
        v4 = b.repository.revision_tree(b.get_rev_id(4))
171
180
        v4.lock_read()
172
 
        self.assertEqual(get_text_by_path(v4, 'b/two'), 'new contents')
173
 
        self.assertEqual(get_text_by_path(v4, 'top'), 'new contents')
 
181
        self.assertEqual(v4.get_file_by_path('b/two').read(), 'new contents')
 
182
        self.assertEqual(v4.get_file_by_path('top').read(), 'new contents')
174
183
        v4.unlock()
175
184
 
176
185
        # TODO: factor out some kind of assert_tree_state() method