Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

wconfig: don't remember access to unknown section

Follows behavior of Mercurial's config.config.

Changeset c53a2fa929ed

Parent 8106b9e458f9

by Yuya Nishihara

Changes to 2 files · Browse files at c53a2fa929ed Showing diff from parent 8106b9e458f9 Diff from another changeset...

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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
 import os, tempfile, shutil  from nose.tools import *  from nose.plugins.skip import SkipTest  from StringIO import StringIO  from mercurial import config  from tortoisehg.util import wconfig    def setup():   global _tempdir   _tempdir = tempfile.mkdtemp()    def teardown():   shutil.rmtree(_tempdir)      def newrconfig(vals={}):   c = config.config()   for k, v in isinstance(vals, dict) and vals.iteritems() or vals:   sec, it = k.split('.', 1)   c.set(sec, it, v)   return c    def newwconfig(vals={}):   return wconfig.config(newrconfig(vals))    def written(c):   dest = StringIO()   c.write(dest)   return dest.getvalue()    def writetempfile(s):   fd, path = tempfile.mkstemp(dir=_tempdir)   os.write(fd, s)   os.close(fd)   return path    class _Collector(list):   def __call__(self, func):   self.append(func)   return func    with_rconfig = _Collector()  with_wconfig = _Collector()  with_both = _Collector()      def test_both():   for e in with_wconfig + with_both:   if wconfig._hasiniparse:   yield e   else:   def skipped():   raise SkipTest   yield skipped     orighasiniparse = wconfig._hasiniparse   wconfig._hasiniparse = False   try:   for e in with_rconfig + with_both:   yield e   finally:   wconfig._hasiniparse = orighasiniparse      @with_both  def check_copy():   c = newwconfig({'foo.bar': 'baz'})   assert_equals(c.__class__, c.copy().__class__)   assert_equals('baz', c.copy().get('foo', 'bar'))    @with_both  def check_contains():   c = newwconfig({'foo.bar': 'baz'})   assert 'foo' in c   assert 'bar' not in c    @with_both  def check_getitem():   c = newwconfig({'foo.bar': 'x', 'foo.baz': 'y'})   assert_equals({'bar': 'x', 'baz': 'y'}, dict(c['foo']))   assert_equals({}, dict(c['unknown']))    @with_both  def check_getitem_empty_then_set_no_effect():   c = newwconfig()   c['unknown']['bar'] = 'baz'   assert not c.get('unknown', 'bar')    @with_both +def check_set_followed_by_getitem_empty(): + c = newwconfig() + c['unknown'] + c.set('unknown', 'foo', 'bar') + assert_equals('bar', c.get('unknown', 'foo')) + assert_equals('bar', c['unknown']['foo']) + +@with_both  def check_dict_contains():   c = newwconfig({'foo.bar': 'x'})   assert 'bar' in c['foo']   assert 'baz' not in c['foo']    @with_both  def check_dict_getitem():   c = newwconfig({'foo.bar': 'x'})   assert_equals('x', c['foo']['bar'])   assert_raises(KeyError, lambda: c['foo']['baz'])    @with_both  def check_dict_setitem():   c = newwconfig({'foo.bar': 'x'})   c['foo']['bar'] = 'y'   c['foo']['baz'] = 'z'   assert_equals('y', c['foo']['bar'])   assert_equals('z', c['foo']['baz'])    @with_wconfig # original config doesn't preserve the order  def check_dict_setitem_preserve_order():   c = newwconfig([('foo.bar', 'x'), ('foo.baz', 'y')])   assert_equals(['bar', 'baz'], list(c['foo']))   c['foo']['bar'] = 'z'   assert_equals(['bar', 'baz'], list(c['foo']))    @with_both  def check_dict_iter():   c = newwconfig({'foo.bar': 'x', 'foo.baz': 'y'})   assert_equals(set(['bar', 'baz']), set(c['foo']))    @with_both  def check_dict_len():   c = newwconfig({'foo.bar': 'x'})   assert_equals(1, len(c['foo']))    @with_both  def check_dict_update():   c = newwconfig({'foo.bar': 'x', 'foo.baz': 'y'})   c['foo'].update(newwconfig({'foo.bar': 'z', 'foo.baz': 'w'})['foo'])   assert_equals('z', c['foo']['bar'])   assert_equals('w', c['foo']['baz'])    @with_both  def check_dict_delitem():   c = newwconfig({'foo.bar': 'x'})   del c['foo']['bar']   assert 'bar' not in c['foo']    @with_both  def check_iter():   c = newwconfig({'foo.bar': 'x', 'baz.bax': 'y'})   assert_equals(set(['foo', 'baz']), set(c))    @with_both  def check_update():   c0 = newwconfig({'foo.bar': 'x', 'foo.blah': 'w'})   c1 = newwconfig({'foo.bar': 'y', 'baz.bax': 'z'})   c0.update(c1)   assert_equals('y', c0.get('foo', 'bar'))   assert_equals('z', c0.get('baz', 'bax'))   assert_equals('w', c0.get('foo', 'blah'))    @with_both  def check_get():   c = newwconfig({'foo.bar': 'baz'})   assert_equals('baz', c.get('foo', 'bar'))   assert_equals(None, c.get('foo', 'baz'))   assert_equals('x', c.get('foo', 'baz', 'x'))    @with_both  def check_source():   c = newwconfig()   c.set('foo', 'bar', 'baz', source='blah')   assert_equals('blah', c.source('foo', 'bar'))    @with_both  def check_sections():   c = newwconfig({'foo.bar': 'x', 'baz.bax': 'y'})   assert_equals(['baz', 'foo'], c.sections())    @with_both  def check_items():   c = newwconfig({'foo.bar': 'x', 'foo.baz': 'y'})   assert_equals({'bar': 'x', 'baz': 'y'}, dict(c.items('foo')))    @with_both  def check_set():   c = newwconfig({'foo.bar': 'x'})   c.set('foo', 'baz', 'y')   c.set('foo', 'bar', 'w')   c.set('newsection', 'bax', 'z')   assert_equals('y', c.get('foo', 'baz'))   assert_equals('w', c.get('foo', 'bar'))   assert_equals('z', c.get('newsection', 'bax'))    @with_wconfig # original config doesn't preserve the order  def check_set_preserve_order():   c = newwconfig([('foo.bar', 'x'), ('foo.baz', 'y')])   assert_equals(['bar', 'baz'], list(c['foo']))   c.set('foo', 'bar', 'z')   assert_equals(['bar', 'baz'], list(c['foo']))    # TODO: test_parse  # TODO: test_read    @with_wconfig  def check_write_after_set():   c = newwconfig()   c.set('foo', 'bar', 'baz')   assert_equals('[foo]\nbar = baz', written(c).rstrip())    @with_wconfig  def check_write_empty():   c = newwconfig()   assert_equals('', written(c).rstrip())    @with_wconfig  def check_write_after_update():   c = newwconfig()   c.update(newwconfig({'foo.bar': 'baz'}))   assert_equals('[foo]\nbar = baz', written(c).rstrip())    @with_wconfig  def check_read_write():   c = newwconfig()   s = '[foo]\nbar = baz'   c.read(path='foo', fp=StringIO(s))   assert_equals(s, written(c).rstrip())    @with_wconfig  def check_write_after_dict_setitem():   c = newwconfig({'foo.bar': 'x'})   c['foo']['bar'] = 'y'   assert_equals('[foo]\nbar = y', written(c).rstrip())    @with_wconfig  def check_write_after_dict_update():   c = newwconfig({'foo.bar': 'x'})   c['foo'].update({'bar': 'y'})   assert_equals('[foo]\nbar = y', written(c).rstrip())    @with_wconfig  def check_write_after_dict_delitem():   c = newwconfig({'foo.bar': 'x', 'foo.baz': 'y'})   del c['foo']['bar']   assert_equals('[foo]\nbaz = y', written(c).rstrip())    @with_wconfig  def check_read_write_rem():   c = newwconfig()   s = '[foo]\nrem = x'   c.read(path='foo', fp=StringIO(s))   c.set('foo', 'rem', 'y')   assert_equals('[foo]\nrem = y', written(c).rstrip())      @with_wconfig  def check_write_conflict_set_set():   fname = writetempfile('[foo]\nbar = x')   c0 = wconfig.readfile(fname)   c1 = wconfig.readfile(fname)   c1.set('foo', 'bar', 'y')   wconfig.writefile(c1, fname)   c0.set('foo', 'bar', 'z')   wconfig.writefile(c0, fname)     cr = wconfig.readfile(fname)   assert_equals('z', cr.get('foo', 'bar'))    @with_wconfig  def check_write_conflict_del_set():   fname = writetempfile('[foo]\nbar = x')   c0 = wconfig.readfile(fname)   c1 = wconfig.readfile(fname)   del c1['foo']['bar']   wconfig.writefile(c1, fname)   c0.set('foo', 'bar', 'z')   wconfig.writefile(c0, fname)     cr = wconfig.readfile(fname)   assert_equals('z', cr.get('foo', 'bar'))    @with_wconfig  def check_write_conflict_set_del():   fname = writetempfile('[foo]\nbar = x')   c0 = wconfig.readfile(fname)   c1 = wconfig.readfile(fname)   c1.set('foo', 'bar', 'y')   wconfig.writefile(c1, fname)   del c0['foo']['bar']   wconfig.writefile(c0, fname)     cr = wconfig.readfile(fname)   assert not cr.get('foo', 'bar')    @with_wconfig  def check_write_conflict_del_del():   fname = writetempfile('[foo]\nbar = x')   c0 = wconfig.readfile(fname)   c1 = wconfig.readfile(fname)   del c1['foo']['bar']   wconfig.writefile(c1, fname)   del c0['foo']['bar']   wconfig.writefile(c0, fname) # shouldn't raise KeyError     cr = wconfig.readfile(fname)   assert not cr.get('foo', 'bar')    @with_wconfig  def check_write_noconflict_set_set():   fname = writetempfile('[foo]\nbar = x')   c0 = wconfig.readfile(fname)   c1 = wconfig.readfile(fname)   c1.set('foo', 'baz', 'y')   wconfig.writefile(c1, fname)   c0.set('foo', 'bar', 'z')   wconfig.writefile(c0, fname) # should not override foo.baz = y     cr = wconfig.readfile(fname)   assert_equals('z', cr.get('foo', 'bar'))   assert_equals('y', cr.get('foo', 'baz'))   assert not c0.get('foo', 'baz') # don't reload c1's change implicitly    @with_wconfig  def check_write_noconflict_del():   fname = writetempfile('[foo]\nbar = x')   c0 = wconfig.readfile(fname)   c1 = wconfig.readfile(fname)   del c1['foo']['bar']   wconfig.writefile(c1, fname)   wconfig.writefile(c0, fname) # shouldn't override del foo.bar     cr = wconfig.readfile(fname)   assert not cr.get('foo', 'bar')   assert c0.get('foo', 'bar') # don't reload c1's change implicitly      @with_wconfig  def check_write_copied():   fname = writetempfile('[foo]\nbar = x')   c0 = wconfig.readfile(fname)   c1 = c0.copy()   c1.set('foo', 'baz', 'y')   wconfig.writefile(c1, fname)     cr = wconfig.readfile(fname)   assert_equals('x', cr.get('foo', 'bar'))   assert_equals('y', cr.get('foo', 'baz'))    @with_wconfig  def check_write_copied_conflict():   fname = writetempfile('[foo]\nbar = x')   c0 = wconfig.readfile(fname)   c1 = c0.copy()   c0.set('foo', 'bar', 'y')   wconfig.writefile(c0, fname)   wconfig.writefile(c1, fname) # shouldn't override foo.bar = y     cr = wconfig.readfile(fname)   assert_equals('y', cr.get('foo', 'bar'))    @with_wconfig  def test_write_copied_rconfig():   c0 = newrconfig({'foo.bar': 'x'})   c1 = wconfig.config(c0)   assert_equals('[foo]\nbar = x', written(c1).rstrip())    @with_both  def check_readfile():   fname = writetempfile('[foo]\nbar = baz')   c = wconfig.readfile(fname)   assert_equals('baz', c.get('foo', 'bar'))    @with_wconfig  def check_writefile():   c = newwconfig({'foo.bar': 'baz'})   fname = writetempfile('')   wconfig.writefile(c, fname)   assert_equals('[foo]\nbar = baz', open(fname).read().rstrip())
 
134
135
136
137
138
 
 
 
 
 
139
140
141
 
134
135
136
 
 
137
138
139
140
141
142
143
144
@@ -134,8 +134,11 @@
  try:   return self._sections[section]   except KeyError: - self._sections[section] = _wsortdict(self._config[section]) - return self._sections[section] + if self._config[section]: + self._sections[section] = _wsortdict(self._config[section]) + return self._sections[section] + else: + return {}     def __iter__(self):   return iter(self._config)