69
77
def test_create_if_missing(self):
70
78
# $HOME should be set to '.'
71
79
ignore_path = config.user_ignore_config_filename()
72
self.failIfExists(ignore_path)
80
self.assertPathDoesNotExist(ignore_path)
73
81
user_ignores = ignores.get_user_ignores()
74
82
self.assertEqual(set(ignores.USER_DEFAULTS), user_ignores)
76
self.failUnlessExists(ignore_path)
84
self.assertPathExists(ignore_path)
77
85
f = open(ignore_path, 'rb')
79
87
entries = ignores.parse_ignore_file(f)
134
142
added = ignores.add_unique_user_ignores(
135
143
['xxx', './bar', 'xxx', 'dir1/', 'dir2/', 'dir3\\'])
136
144
self.assertEqual(['xxx', 'dir2'], added)
137
self.assertEqual(set(['foo', './bar', u'b\xe5z',
138
'xxx', 'dir1', 'dir2', 'dir3']),
145
self.assertEqual({'foo', './bar', u'b\xe5z',
146
'xxx', 'dir1', 'dir2', 'dir3'},
139
147
ignores.get_user_ignores())
142
150
class TestRuntimeIgnores(TestCase):
153
super(TestRuntimeIgnores, self).setUp()
147
155
# For the purposes of these tests, we must have no
148
156
# runtime ignores
153
161
self.assertEqual(set(), ignores.get_runtime_ignores())
155
163
ignores.add_runtime_ignores(['foo'])
156
self.assertEqual(set(['foo']), ignores.get_runtime_ignores())
164
self.assertEqual({'foo'}, ignores.get_runtime_ignores())
158
166
def test_add_duplicate(self):
159
167
"""Adding the same ignore twice shouldn't add a new entry."""
160
168
ignores.add_runtime_ignores(['foo', 'bar'])
161
self.assertEqual(set(['foo', 'bar']), ignores.get_runtime_ignores())
169
self.assertEqual({'foo', 'bar'}, ignores.get_runtime_ignores())
163
171
ignores.add_runtime_ignores(['bar'])
164
self.assertEqual(set(['foo', 'bar']), ignores.get_runtime_ignores())
172
self.assertEqual({'foo', 'bar'}, ignores.get_runtime_ignores())
167
175
class TestTreeIgnores(TestCaseWithTransport):
177
def assertPatternsEquals(self, patterns):
178
contents = open(".bzrignore", 'rU').read().strip().split('\n')
179
self.assertEqual(sorted(patterns), sorted(contents))
169
181
def test_new_file(self):
170
182
tree = self.make_branch_and_tree(".")
171
183
ignores.tree_ignores_add_patterns(tree, ["myentry"])
172
184
self.assertTrue(tree.has_filename(".bzrignore"))
173
self.assertEquals("myentry\n",
174
open(".bzrignore", 'r').read())
185
self.assertPatternsEquals(["myentry"])
176
187
def test_add_to_existing(self):
177
188
tree = self.make_branch_and_tree(".")
178
189
self.build_tree_contents([('.bzrignore', "myentry1\n")])
179
190
tree.add([".bzrignore"])
180
191
ignores.tree_ignores_add_patterns(tree, ["myentry2", "foo"])
181
self.assertEquals("myentry1\nmyentry2\nfoo\n",
182
open(".bzrignore", 'r').read())
192
self.assertPatternsEquals(["myentry1", "myentry2", "foo"])
184
194
def test_adds_ending_newline(self):
185
195
tree = self.make_branch_and_tree(".")
186
196
self.build_tree_contents([('.bzrignore', "myentry1")])
187
197
tree.add([".bzrignore"])
188
198
ignores.tree_ignores_add_patterns(tree, ["myentry2"])
189
self.assertEquals("myentry1\nmyentry2\n",
190
open(".bzrignore", 'r').read())
199
self.assertPatternsEquals(["myentry1", "myentry2"])
200
text = open(".bzrignore", 'r').read()
201
self.assertTrue(text.endswith('\r\n') or
202
text.endswith('\n') or
205
def test_does_not_add_dupe(self):
206
tree = self.make_branch_and_tree(".")
207
self.build_tree_contents([('.bzrignore', "myentry\n")])
208
tree.add([".bzrignore"])
209
ignores.tree_ignores_add_patterns(tree, ["myentry"])
210
self.assertPatternsEquals(["myentry"])
212
def test_non_ascii(self):
213
tree = self.make_branch_and_tree(".")
214
self.build_tree_contents([('.bzrignore',
215
u"myentry\u1234\n".encode('utf-8'))])
216
tree.add([".bzrignore"])
217
ignores.tree_ignores_add_patterns(tree, [u"myentry\u5678"])
218
self.assertPatternsEquals([u"myentry\u1234".encode('utf-8'),
219
u"myentry\u5678".encode('utf-8')])
222
tree = self.make_branch_and_tree(".")
223
self.build_tree_contents([('.bzrignore', "myentry1\r\n")])
224
tree.add([".bzrignore"])
225
ignores.tree_ignores_add_patterns(tree, ["myentry2", "foo"])
226
self.assertEqual(open('.bzrignore', 'rb').read(), 'myentry1\r\nmyentry2\r\nfoo\r\n')
227
self.assertPatternsEquals(["myentry1", "myentry2", "foo"])