1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
# Copyright (C) 2020 Jelmer Vernooij <jelmer@jelmer.uk>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import os
from . import (
TestCaseWithTransport,
multiply_scenarios,
features,
)
from .scenarios import load_tests_apply_scenarios
from ..workspace import (
WorkspaceDirty,
Workspace,
check_clean_tree,
)
load_tests = load_tests_apply_scenarios
class CheckCleanTreeTests(TestCaseWithTransport):
def make_test_tree(self, format=None):
tree = self.make_branch_and_tree('.', format=format)
self.build_tree_contents([
('debian/', ),
('debian/control', """\
Source: blah
Vcs-Git: https://example.com/blah
Testsuite: autopkgtest
Binary: blah
Arch: all
"""),
('debian/changelog', 'Some contents')])
tree.add(['debian', 'debian/changelog', 'debian/control'])
tree.commit('Initial thingy.')
return tree
def test_pending_changes(self):
tree = self.make_test_tree()
self.build_tree_contents([('debian/changelog', 'blah')])
with tree.lock_write():
self.assertRaises(
WorkspaceDirty, check_clean_tree, tree)
def test_pending_changes_bzr_empty_dir(self):
# See https://bugs.debian.org/914038
tree = self.make_test_tree(format='bzr')
self.build_tree_contents([('debian/upstream/', )])
with tree.lock_write():
self.assertRaises(
WorkspaceDirty, check_clean_tree, tree)
def test_pending_changes_git_empty_dir(self):
# See https://bugs.debian.org/914038
tree = self.make_test_tree(format='git')
self.build_tree_contents([('debian/upstream/', )])
with tree.lock_write():
check_clean_tree(tree)
def test_pending_changes_git_dir_with_ignored(self):
# See https://bugs.debian.org/914038
tree = self.make_test_tree(format='git')
self.build_tree_contents([
('debian/upstream/', ),
('debian/upstream/blah', ''),
('.gitignore', 'blah\n'),
])
tree.add('.gitignore')
tree.commit('add gitignore')
with tree.lock_write():
check_clean_tree(tree)
def test_extra(self):
tree = self.make_test_tree()
self.build_tree_contents([('debian/foo', 'blah')])
with tree.lock_write():
self.assertRaises(
WorkspaceDirty, check_clean_tree,
tree)
def vary_by_inotify():
return [
('with_inotify', dict(_use_inotify=True)),
('without_inotify', dict(_use_inotify=False)),
]
def vary_by_format():
return [
('bzr', dict(_format='bzr')),
('git', dict(_format='git')),
]
class WorkspaceTests(TestCaseWithTransport):
scenarios = multiply_scenarios(
vary_by_inotify(),
vary_by_format(),
)
def setUp(self):
super(WorkspaceTests, self).setUp()
if self._use_inotify:
self.requireFeature(features.pyinotify)
def test_root_add(self):
tree = self.make_branch_and_tree('.', format=self._format)
with Workspace(tree, use_inotify=self._use_inotify) as ws:
self.build_tree_contents([('afile', 'somecontents')])
changes = [c for c in ws.iter_changes() if c.path[1] != '']
self.assertEqual(1, len(changes), changes)
self.assertEqual((None, 'afile'), changes[0].path)
ws.commit(message='Commit message')
self.assertEqual(list(ws.iter_changes()), [])
self.build_tree_contents([('afile', 'newcontents')])
[change] = list(ws.iter_changes())
self.assertEqual(('afile', 'afile'), change.path)
def test_root_remove(self):
tree = self.make_branch_and_tree('.', format=self._format)
self.build_tree_contents([('afile', 'somecontents')])
tree.add(['afile'])
tree.commit('Afile')
with Workspace(tree, use_inotify=self._use_inotify) as ws:
os.remove('afile')
changes = list(ws.iter_changes())
self.assertEqual(1, len(changes), changes)
self.assertEqual(('afile', None), changes[0].path)
ws.commit(message='Commit message')
self.assertEqual(list(ws.iter_changes()), [])
def test_subpath_add(self):
tree = self.make_branch_and_tree('.', format=self._format)
self.build_tree(['subpath/'])
tree.add('subpath')
tree.commit('add subpath')
with Workspace(
tree, subpath='subpath', use_inotify=self._use_inotify) as ws:
self.build_tree_contents([('outside', 'somecontents')])
self.build_tree_contents([('subpath/afile', 'somecontents')])
changes = [c for c in ws.iter_changes() if c.path[1] != 'subpath']
self.assertEqual(1, len(changes), changes)
self.assertEqual((None, 'subpath/afile'), changes[0].path)
ws.commit(message='Commit message')
self.assertEqual(list(ws.iter_changes()), [])
def test_dirty(self):
tree = self.make_branch_and_tree('.', format=self._format)
self.build_tree(['subpath'])
self.assertRaises(
WorkspaceDirty, Workspace(tree, use_inotify=self._use_inotify).__enter__)
def test_reset(self):
tree = self.make_branch_and_tree('.', format=self._format)
with Workspace(tree, use_inotify=self._use_inotify) as ws:
self.build_tree(['blah'])
ws.reset()
self.assertPathDoesNotExist('blah')
def test_tree_path(self):
tree = self.make_branch_and_tree('.', format=self._format)
tree.mkdir('subdir')
tree.commit('Add subdir')
with Workspace(tree, use_inotify=self._use_inotify) as ws:
self.assertEqual('foo', ws.tree_path('foo'))
self.assertEqual('', ws.tree_path())
with Workspace(tree, subpath='subdir', use_inotify=self._use_inotify) as ws:
self.assertEqual('subdir/foo', ws.tree_path('foo'))
self.assertEqual('subdir/', ws.tree_path())
def test_abspath(self):
tree = self.make_branch_and_tree('.', format=self._format)
tree.mkdir('subdir')
tree.commit('Add subdir')
with Workspace(tree, use_inotify=self._use_inotify) as ws:
self.assertEqual(tree.abspath('foo'), ws.abspath('foo'))
self.assertEqual(tree.abspath(''), ws.abspath())
with Workspace(tree, subpath='subdir', use_inotify=self._use_inotify) as ws:
self.assertEqual(tree.abspath('subdir/foo'), ws.abspath('foo'))
self.assertEqual(tree.abspath('subdir') + '/', ws.abspath(''))
self.assertEqual(tree.abspath('subdir') + '/', ws.abspath())
def test_open_containing(self):
tree = self.make_branch_and_tree('.', format=self._format)
tree.mkdir('subdir')
tree.commit('Add subdir')
ws = Workspace.from_path('subdir')
self.assertEqual(ws.tree.abspath('.'), tree.abspath('.'))
self.assertEqual(ws.subpath, 'subdir')
self.assertEqual(None, ws.use_inotify)
|