~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Marius Kruger
  • Date: 2007-04-19 05:59:47 UTC
  • mto: This revision was merged to the branch mainline in revision 2455.
  • Revision ID: amanic@gmail.com-20070419055947-x776pmmp7uj7utva
* tests/__init__.run_bzr
  Now gives better assert message for 'Unexpected return code'
* blackbox/test_remove
  - Add changed file tests
  - When checking changed/unknown rm fails, always wheck if we can forec it.
  - Move one file tests to top
  - Fixed copy-paste pattern induced mishaps where more-than-one-file-tests
    were actually just testing one-file
  - Add test to remove while in a child dir
  - Add remove deleted file test

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
class TestRemove(ExternalBase):
33
33
 
34
 
    def _make_add_and_assert_tree(self,files):
 
34
    def _make_add_and_assert_tree(self, files):
35
35
        tree = self.make_branch_and_tree('.')
36
36
        self.build_tree(files)
37
37
        for f in files:
42
42
            self.assertInWorkingTree(f)
43
43
        return tree
44
44
 
45
 
    def assertFilesDeleted(self,files):
 
45
    def assertFilesDeleted(self, files):
46
46
        for f in files:
47
47
            id=f+_id
48
48
            self.assertNotInWorkingTree(f)
49
49
            self.failIfExists(f)
50
50
 
51
 
    def assertFilesUnversioned(self,files):
 
51
    def assertFilesUnversioned(self, files):
52
52
        for f in files:
53
53
            self.assertNotInWorkingTree(f)
54
54
            self.failUnlessExists(f)
55
55
 
56
 
    def run_bzr_remove_changed_files(self, error_regexes, cmd):
 
56
    def changeFile(self, file_name):
 
57
        f = file(file_name, 'ab')
 
58
        f.write("\nsome other new content!")
 
59
        f.close()
 
60
 
 
61
    def run_bzr_remove_changed_files(self, error_regexes, files_to_remove):
57
62
        error_regexes.extend(["Can't remove changed or unknown files:",
58
63
            'Use --keep to not delete them,'
59
64
            ' or --force to delete them regardless.'
60
65
            ])
61
 
        self.run_bzr_error(error_regexes, cmd)
 
66
        self.run_bzr_error(error_regexes,
 
67
            'remove ' + ' '.join(files_to_remove))
 
68
        #see if we can force it now
 
69
        self.run_bzr('remove --force ' + ' '.join(files_to_remove))
62
70
 
63
71
    def test_remove_no_files_specified(self):
64
72
        tree = self._make_add_and_assert_tree([])
70
78
        self.run_bzr_error(["bzr: ERROR: No matching files."],
71
79
            'remove --new .')
72
80
 
 
81
    def test_rm_one_file(self):
 
82
        tree = self._make_add_and_assert_tree([a])
 
83
        self.run_bzr("commit -m 'added a'")
 
84
        self.run_bzr('rm a', error_regexes=["deleted a"])
 
85
        self.assertFilesDeleted([a])
 
86
 
 
87
    def test_remove_one_file(self):
 
88
        tree = self._make_add_and_assert_tree([a])
 
89
        self.run_bzr("commit -m 'added a'")
 
90
        self.run_bzr('remove a', error_regexes=["deleted a"])
 
91
        self.assertFilesDeleted([a])
 
92
 
 
93
    def test_remove_keep_one_file(self):
 
94
        tree = self._make_add_and_assert_tree([a])
 
95
        self.run_bzr('remove --keep a', error_regexes=["removed a"])
 
96
        self.assertFilesUnversioned([a])
 
97
 
 
98
    def test_remove_one_deleted_file(self):
 
99
        tree = self._make_add_and_assert_tree([a])
 
100
        self.run_bzr("commit -m 'added a'")
 
101
        os.unlink(a)
 
102
        self.assertInWorkingTree(a)
 
103
        self.run_bzr('remove a')
 
104
        self.assertNotInWorkingTree(a)
 
105
 
73
106
    def test_remove_invalid_files(self):
74
 
        self.build_tree([a])
 
107
        self.build_tree(files)
75
108
        tree = self.make_branch_and_tree('.')
76
 
        self.run_bzr('remove .')
 
109
        self.run_bzr_remove_changed_files(['unknown:[.\s]*xyz[.\s]*abc/def'],
 
110
            ['.', 'xyz', 'abc/def'])
77
111
 
78
112
    def test_remove_unversioned_files(self):
79
 
        self.build_tree([a])
 
113
        self.build_tree(files)
80
114
        tree = self.make_branch_and_tree('.')
81
 
        self.run_bzr_remove_changed_files(['unknown:[.\s]*a'], 'remove a')
 
115
        self.run_bzr_remove_changed_files(
 
116
            ['unknown:[.\s]*d/[.\s]*b/c[.\s]*b/[.\s]*a'], files)
 
117
 
 
118
    def test_remove_changed_files(self):
 
119
        tree = self._make_add_and_assert_tree(files)
 
120
        self.run_bzr("commit -m 'added files'")
 
121
        self.changeFile(a)
 
122
        self.changeFile(c)
 
123
        self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'], files)
 
124
 
 
125
    def test_remove_changed_files_from_child_dir(self):
 
126
        tree = self._make_add_and_assert_tree(files)
 
127
        self.run_bzr("commit -m 'added files'")
 
128
        self.changeFile(a)
 
129
        self.changeFile(c)
 
130
        os.chdir('b')
 
131
        self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'],
 
132
            ['../a', 'c', '.', '../d'])
 
133
        os.chdir('..')
 
134
        self.assertNotInWorkingTree(files)
 
135
        self.failIfExists(files)
82
136
 
83
137
    def test_remove_keep_unversioned_files(self):
84
 
        self.build_tree([a])
 
138
        self.build_tree(files)
85
139
        tree = self.make_branch_and_tree('.')
86
140
        self.run_bzr('remove --keep a', error_regexes=["a is not versioned."])
 
141
        self.assertFilesUnversioned(files)
87
142
 
88
143
    def test_remove_force_unversioned_files(self):
89
 
        self.build_tree([a])
 
144
        self.build_tree(files)
90
145
        tree = self.make_branch_and_tree('.')
91
 
        self.run_bzr('remove --force a', error_regexes=["deleted a"])
92
 
        self.assertFilesDeleted([a])
 
146
        self.run_bzr('remove --force ' + ' '.join(files),
 
147
                     error_regexes=["deleted a", "deleted b",
 
148
                                    "deleted b/c", "deleted d"])
 
149
        self.assertFilesDeleted(files)
 
150
 
 
151
    def test_remove_deleted_files(self):
 
152
        tree = self._make_add_and_assert_tree(files)
 
153
        self.run_bzr("commit -m 'added files'")
 
154
        my_files=[f for f in files]
 
155
        my_files.sort(reverse=True)
 
156
        for f in my_files:
 
157
            osutils.delete_any(f)
 
158
        self.assertInWorkingTree(files)
 
159
        self.failIfExists(files)
 
160
        self.run_bzr('remove ' + ' '.join(files))
 
161
        self.assertNotInWorkingTree(a)
 
162
        self.failIfExists(files)
93
163
 
94
164
    def test_remove_non_existing_files(self):
95
165
        tree = self._make_add_and_assert_tree([])
96
 
        self.run_bzr_remove_changed_files(['unknown:[.\s]*b'], 'remove b')
 
166
        self.run_bzr_remove_changed_files(['unknown:[.\s]*b'], ['b'])
97
167
 
98
168
    def test_remove_keep_non_existing_files(self):
99
169
        tree = self._make_add_and_assert_tree([])
100
170
        self.run_bzr('remove --keep b', error_regexes=["b is not versioned."])
101
171
 
102
 
    def test_rm_one_file(self):
103
 
        tree = self._make_add_and_assert_tree([a])
104
 
        self.run_bzr("commit -m 'added a'")
105
 
        self.run_bzr('rm a', error_regexes=["deleted a"])
106
 
        self.assertFilesDeleted([a])
107
 
 
108
 
    def test_remove_one_file(self):
109
 
        tree = self._make_add_and_assert_tree([a])
110
 
        self.run_bzr("commit -m 'added a'")
111
 
        self.run_bzr('remove a', error_regexes=["deleted a"])
112
 
        self.assertFilesDeleted([a])
113
 
 
114
 
    def test_remove_keep_one_file(self):
115
 
        tree = self._make_add_and_assert_tree([a])
116
 
        self.run_bzr('remove --keep a', error_regexes=["removed a"])
117
 
        self.assertFilesUnversioned([a])
118
 
 
119
172
    def test_remove_files(self):
120
173
        tree = self._make_add_and_assert_tree(files)
121
174
        self.run_bzr("commit -m 'added files'")
132
185
                     "removed d"])
133
186
        self.assertFilesUnversioned(files)
134
187
 
135
 
    def test_remove_on_deleted(self):
136
 
        tree = self._make_add_and_assert_tree([a])
137
 
        self.run_bzr("commit -m 'added a'")
138
 
        os.unlink(a)
139
 
        self.assertInWorkingTree(a)
140
 
        self.run_bzr('remove a')
141
 
        self.assertNotInWorkingTree(a)
142
 
 
143
188
    def test_remove_with_new(self):
144
189
        tree = self._make_add_and_assert_tree(files)
145
190
        self.run_bzr('remove --new --keep',
152
197
                     error_regexes=["removed b", "removed b/c"])
153
198
        tree = WorkingTree.open('.')
154
199
        self.assertInWorkingTree(a)
155
 
        self.assertEqual(tree.path2id(a), a+_id)
 
200
        self.assertEqual(tree.path2id(a), a + _id)
156
201
        self.assertFilesUnversioned([b,c])
157
202
 
158
203
    def test_remove_with_new_in_dir2(self):
160
205
        self.run_bzr('remove --new --keep .',
161
206
                     error_regexes=["removed a", "removed b", "removed b/c"])
162
207
        tree = WorkingTree.open('.')
163
 
        self.assertFilesUnversioned([a])
 
208
        self.assertFilesUnversioned(files)