~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Wouter van Heyst
  • Date: 2006-07-09 20:12:49 UTC
  • mto: This revision was merged to the branch mainline in revision 1852.
  • Revision ID: larstiq@larstiq.dyndns.org-20060709201249-91fa66f6001eb965
Don't fail on 'bzr mv', extract move tests from OldTests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Test for 'bzr mv'"""
 
18
 
 
19
import os
 
20
 
 
21
from bzrlib.tests import TestCaseWithTransport
 
22
 
 
23
 
 
24
class TestMove(TestCaseWithTransport):
 
25
 
 
26
    def test_mv_modes(self):
 
27
        """Test two modes of operation for mv"""
 
28
        tree = self.make_branch_and_tree('.')
 
29
        files = self.build_tree(['a', 'c', 'subdir/'])
 
30
        tree.add(['a', 'c', 'subdir'])
 
31
 
 
32
        self.run_bzr('mv', 'a', 'b')
 
33
        self.run_bzr('mv', 'b', 'subdir')
 
34
        self.run_bzr('mv', 'subdir/b', 'a')
 
35
        self.run_bzr('mv', 'a', 'c', 'subdir')
 
36
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
 
37
 
 
38
    def test_mv_unversioned(self):
 
39
        self.build_tree(['unversioned.txt'])
 
40
        self.run_bzr_error(
 
41
            ["^bzr: ERROR: can't rename: old name .* is not versioned$"],
 
42
            'mv', 'unversioned.txt', 'elsewhere')
 
43
 
 
44
    def test_mv_nonexisting(self):
 
45
        self.run_bzr_error(
 
46
            ["^bzr: ERROR: can't rename: old working file .* does not exist$"],
 
47
            'mv', 'doesnotexist', 'somewhereelse')
 
48
 
 
49
    def test_mv_unqualified(self):
 
50
        self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
 
51
        
 
52
    def test_mv_newly_added(self):
 
53
        tree = self.make_branch_and_tree('.')
 
54
        self.build_tree(['test.txt'])
 
55
        tree.add(['test.txt'])
 
56
 
 
57
        self.run_bzr('mv', 'test.txt', 'hello.txt')
 
58
        self.failUnlessExists("hello.txt")
 
59
        self.failIfExists("test.txt")
 
60
 
 
61
    def test_mv_invalid(self):
 
62
        tree = self.make_branch_and_tree('.')
 
63
        self.build_tree(['test.txt', 'sub1/'])
 
64
        tree.add(['test.txt'])
 
65
 
 
66
        self.run_bzr_error(
 
67
            ["^bzr: ERROR: destination u'sub1' is not a versioned directory$"],
 
68
            'rename', 'test.txt', 'sub1')
 
69
        
 
70
        self.run_bzr_error(
 
71
            ["^bzr: ERROR: can't determine destination directory id for u'sub1'$"],
 
72
            'rename', 'test.txt', 'sub1/hello.txt')
 
73
        
 
74
        self.run_bzr_error(
 
75
            ["^bzr: ERROR: destination u'sub1' is not a versioned directory$"],
 
76
            'move', 'test.txt', 'sub1')
 
77
    
 
78
    def test_mv_dirs(self):
 
79
        tree = self.make_branch_and_tree('.')
 
80
        self.build_tree(['hello.txt', 'sub1/'])
 
81
        tree.add(['hello.txt', 'sub1'])
 
82
 
 
83
        self.run_bzr('rename', 'sub1', 'sub2')
 
84
        self.run_bzr('move', 'hello.txt', 'sub2')
 
85
 
 
86
        self.failUnlessExists("sub2")
 
87
        self.failUnlessExists("sub2/hello.txt")
 
88
        self.failIfExists("sub1")
 
89
        self.failIfExists("hello.txt")
 
90
 
 
91
        tree.read_working_inventory()
 
92
        tree.commit('commit with some things moved to subdirs')
 
93
 
 
94
        self.build_tree(['sub1/'])
 
95
        tree.add(['sub1'])
 
96
        self.run_bzr('move', 'sub2/hello.txt', 'sub1')
 
97
        self.failIfExists('sub2/hello.txt')
 
98
        self.failUnlessExists('sub1/hello.txt')
 
99
        self.run_bzr('move', 'sub2', 'sub1')
 
100
        self.failIfExists('sub2')
 
101
        self.failUnlessExists('sub1/sub2')
 
102
 
 
103
    def test_mv_relative(self): 
 
104
        self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
 
105
        tree = self.make_branch_and_tree('.')
 
106
        tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
 
107
        tree.commit('initial tree')
 
108
 
 
109
        os.chdir('sub1/sub2')
 
110
        self.run_bzr('move', '../hello.txt', '.')
 
111
        self.failUnlessExists('./hello.txt')
 
112
        tree.read_working_inventory()
 
113
        tree.commit('move to parent directory')
 
114
 
 
115
        os.chdir('..')
 
116
 
 
117
        self.run_bzr('move', 'sub2/hello.txt', '.')
 
118
        self.failUnlessExists('hello.txt')