Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork966
Expand file tree
/
Copy pathtest_config.py
More file actions
620 lines (516 loc) · 26 KB
/
test_config.py
File metadata and controls
620 lines (516 loc) · 26 KB
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors
#
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
importglob
importio
importos
importos.pathasosp
importsys
fromunittestimportmock
importpytest
fromgitimportGitConfigParser
fromgit.configimport_OMD,cp
fromgit.utilimportrmfile
fromtest.libimportSkipTest,TestCase,fixture_path,with_rw_directory
_tc_lock_fpaths=osp.join(osp.dirname(__file__),"fixtures/*.lock")
def_rm_lock_files():
forlfpinglob.glob(_tc_lock_fpaths):
rmfile(lfp)
classTestBase(TestCase):
defsetUp(self):
_rm_lock_files()
deftearDown(self):
forlfpinglob.glob(_tc_lock_fpaths):
ifosp.isfile(lfp):
raiseAssertionError("Previous TC left hanging git-lock file: {}".format(lfp))
def_to_memcache(self,file_path):
withopen(file_path,"rb")asfp:
sio=io.BytesIO(fp.read())
sio.name=file_path
returnsio
deftest_read_write(self):
# The writer must create the exact same file as the one read before.
forfilenamein ("git_config","git_config_global"):
file_obj=self._to_memcache(fixture_path(filename))
withGitConfigParser(file_obj,read_only=False)asw_config:
w_config.read()# Enforce reading.
assertw_config._sections
w_config.write()# Enforce writing.
# We stripped lines when reading, so the results differ.
assertfile_obj.getvalue()
self.assertEqual(
file_obj.getvalue(),
self._to_memcache(fixture_path(filename)).getvalue(),
)
# Creating an additional config writer must fail due to exclusive
# access.
withself.assertRaises(IOError):
GitConfigParser(file_obj,read_only=False)
# Should still have a lock and be able to make changes.
assertw_config._lock._has_lock()
# Changes should be written right away.
sname="my_section"
oname="mykey"
val="myvalue"
w_config.add_section(sname)
assertw_config.has_section(sname)
w_config.set(sname,oname,val)
assertw_config.has_option(sname,oname)
assertw_config.get(sname,oname)==val
sname_new="new_section"
oname_new="new_key"
ival=10
w_config.set_value(sname_new,oname_new,ival)
assertw_config.get_value(sname_new,oname_new)==ival
file_obj.seek(0)
r_config=GitConfigParser(file_obj,read_only=True)
assertr_config.has_section(sname)
assertr_config.has_option(sname,oname)
assertr_config.get(sname,oname)==val
# END for each filename
deftest_includes_order(self):
withGitConfigParser(list(map(fixture_path, ("git_config","git_config_global"))))asr_config:
r_config.read()# Enforce reading.
# Simple inclusions, again checking them taking precedence.
assertr_config.get_value("sec","var0")=="value0_included"
# This one should take the git_config_global value since included values
# must be considered as soon as they get them.
assertr_config.get_value("diff","tool")=="meld"
try:
# FIXME: Split this assertion out somehow and mark it xfail (or fix it).
assertr_config.get_value("sec","var1")=="value1_main"
exceptAssertionErrorase:
raiseSkipTest("Known failure -- included values are not in effect right away")frome
@with_rw_directory
deftest_lock_reentry(self,rw_dir):
fpl=osp.join(rw_dir,"l")
gcp=GitConfigParser(fpl,read_only=False)
withgcpascw:
cw.set_value("include","some_value","a")
# Entering again locks the file again...
withgcpascw:
cw.set_value("include","some_other_value","b")
# ...so creating an additional config writer must fail due to exclusive
# access.
withself.assertRaises(IOError):
GitConfigParser(fpl,read_only=False)
# but work when the lock is removed
withGitConfigParser(fpl,read_only=False):
assertosp.exists(fpl)
# Reentering with an existing lock must fail due to exclusive access.
withself.assertRaises(IOError):
gcp.__enter__()
deftest_multi_line_config(self):
file_obj=self._to_memcache(fixture_path("git_config_with_comments"))
withGitConfigParser(file_obj,read_only=False)asconfig:
ev="ruby -e '\n"
ev+="system %(git), %(merge-file), %(--marker-size=%L), %(%A), %(%O), %(%B)\n"
ev+="b = File.read(%(%A))\n"
ev+="b.sub!(/^<+ .*\\nActiveRecord::Schema\\.define.:version => (\\d+). do\\n=+\\nActiveRecord::Schema\\."# noqa: E501
ev+="define.:version => (\\d+). do\\n>+ .*/) do\n"
ev+=" %(ActiveRecord::Schema.define(:version => #{[$1, $2].max}) do)\n"
ev+="end\n"
ev+="File.open(%(%A), %(w)) {|f| f.write(b)}\n"
ev+="exit 1 if b.include?(%(<)*%L)'"
self.assertEqual(config.get('merge "railsschema"',"driver"),ev)
self.assertEqual(
config.get("alias","lg"),
"log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset'"
" --abbrev-commit --date=relative",
)
self.assertEqual(len(config.sections()),23)
deftest_config_value_with_trailing_new_line(self):
config_content=b'[section-header]\nkey:"value\n"'
config_file=io.BytesIO(config_content)
config_file.name="multiline_value.config"
git_config=GitConfigParser(config_file)
git_config.read()# This should not throw an exception
deftest_base(self):
path_repo=fixture_path("git_config")
path_global=fixture_path("git_config_global")
r_config=GitConfigParser([path_repo,path_global],read_only=True)
assertr_config.read_only
num_sections=0
num_options=0
# Test reader methods.
assertr_config._is_initializedisFalse
forsectioninr_config.sections():
num_sections+=1
foroptioninr_config.options(section):
num_options+=1
val=r_config.get(section,option)
val_typed=r_config.get_value(section,option)
assertisinstance(val_typed, (bool,int,float,str))
assertval
assert"\n"notinoption
assert"\n"notinval
# Writing must fail.
withself.assertRaises(IOError):
r_config.set(section,option,None)
withself.assertRaises(IOError):
r_config.remove_option(section,option)
# END for each option
withself.assertRaises(IOError):
r_config.remove_section(section)
# END for each section
assertnum_sectionsandnum_options
assertr_config._is_initializedisTrue
# Get value which doesn't exist, with default.
default="my default value"
assertr_config.get_value("doesnt","exist",default)==default
# It raises if there is no default though.
withself.assertRaises(cp.NoSectionError):
r_config.get_value("doesnt","exist")
@with_rw_directory
deftest_config_include(self,rw_dir):
defwrite_test_value(cw,value):
cw.set_value(value,"value",value)
defcheck_test_value(cr,value):
assertcr.get_value(value,"value")==value
# PREPARE CONFIG FILE A
fpa=osp.join(rw_dir,"a")
withGitConfigParser(fpa,read_only=False)ascw:
write_test_value(cw,"a")
fpb=osp.join(rw_dir,"b")
fpc=osp.join(rw_dir,"c")
cw.set_value("include","relative_path_b","b")
cw.set_value("include","doesntexist","foobar")
cw.set_value("include","relative_cycle_a_a","a")
cw.set_value("include","absolute_cycle_a_a",fpa)
assertosp.exists(fpa)
# PREPARE CONFIG FILE B
withGitConfigParser(fpb,read_only=False)ascw:
write_test_value(cw,"b")
cw.set_value("include","relative_cycle_b_a","a")
cw.set_value("include","absolute_cycle_b_a",fpa)
cw.set_value("include","relative_path_c","c")
cw.set_value("include","absolute_path_c",fpc)
# PREPARE CONFIG FILE C
withGitConfigParser(fpc,read_only=False)ascw:
write_test_value(cw,"c")
withGitConfigParser(fpa,read_only=True)ascr:
fortvin ("a","b","c"):
check_test_value(cr,tv)
# END for each test to verify
assertlen(cr.items("include"))==8,"Expected all include sections to be merged"
# Test writable config writers - assure write-back doesn't involve includes.
withGitConfigParser(fpa,read_only=False,merge_includes=True)ascw:
tv="x"
write_test_value(cw,tv)
withGitConfigParser(fpa,read_only=True)ascr:
withself.assertRaises(cp.NoSectionError):
check_test_value(cr,tv)
# But can make it skip includes altogether, and thus allow write-backs.
withGitConfigParser(fpa,read_only=False,merge_includes=False)ascw:
write_test_value(cw,tv)
withGitConfigParser(fpa,read_only=True)ascr:
check_test_value(cr,tv)
@pytest.mark.xfail(
sys.platform=="win32",
reason='Second config._has_includes() assertion fails (for "config is included if path is matching git_dir")',
raises=AssertionError,
)
@with_rw_directory
deftest_conditional_includes_from_git_dir(self,rw_dir):
# Initiate repository path.
git_dir=osp.join(rw_dir,"target1","repo1")
os.makedirs(git_dir)
# Initiate mocked repository.
repo=mock.Mock(git_dir=git_dir)
# Initiate config files.
path1=osp.join(rw_dir,"config1")
path2=osp.join(rw_dir,"config2")
template='[includeIf "{}:{}"]\n path={}\n'
withopen(path1,"w")asstream:
stream.write(template.format("gitdir",git_dir,path2))
# Ensure that config is ignored if no repo is set.
withGitConfigParser(path1)asconfig:
assertnotconfig._has_includes()
assertconfig._included_paths()== []
# Ensure that config is included if path is matching git_dir.
withGitConfigParser(path1,repo=repo)asconfig:
assertconfig._has_includes()
assertconfig._included_paths()== [("path",path2)]
# Ensure that config is ignored if case is incorrect.
withopen(path1,"w")asstream:
stream.write(template.format("gitdir",git_dir.upper(),path2))
withGitConfigParser(path1,repo=repo)asconfig:
assertnotconfig._has_includes()
assertconfig._included_paths()== []
# Ensure that config is included if case is ignored.
withopen(path1,"w")asstream:
stream.write(template.format("gitdir/i",git_dir.upper(),path2))
withGitConfigParser(path1,repo=repo)asconfig:
assertconfig._has_includes()
assertconfig._included_paths()== [("path",path2)]
# Ensure that config is included with path using glob pattern.
withopen(path1,"w")asstream:
stream.write(template.format("gitdir","**/repo1",path2))
withGitConfigParser(path1,repo=repo)asconfig:
assertconfig._has_includes()
assertconfig._included_paths()== [("path",path2)]
# Ensure that config is ignored if path is not matching git_dir.
withopen(path1,"w")asstream:
stream.write(template.format("gitdir","incorrect",path2))
withGitConfigParser(path1,repo=repo)asconfig:
assertnotconfig._has_includes()
assertconfig._included_paths()== []
# Ensure that config is included if path in hierarchy.
withopen(path1,"w")asstream:
stream.write(template.format("gitdir","target1/",path2))
withGitConfigParser(path1,repo=repo)asconfig:
assertconfig._has_includes()
assertconfig._included_paths()== [("path",path2)]
@with_rw_directory
deftest_conditional_includes_from_branch_name(self,rw_dir):
# Initiate mocked branch.
branch=mock.Mock()
type(branch).name=mock.PropertyMock(return_value="/foo/branch")
# Initiate mocked repository.
repo=mock.Mock(active_branch=branch)
# Initiate config files.
path1=osp.join(rw_dir,"config1")
path2=osp.join(rw_dir,"config2")
template='[includeIf "onbranch:{}"]\n path={}\n'
# Ensure that config is included is branch is correct.
withopen(path1,"w")asstream:
stream.write(template.format("/foo/branch",path2))
withGitConfigParser(path1,repo=repo)asconfig:
assertconfig._has_includes()
assertconfig._included_paths()== [("path",path2)]
# Ensure that config is included is branch is incorrect.
withopen(path1,"w")asstream:
stream.write(template.format("incorrect",path2))
withGitConfigParser(path1,repo=repo)asconfig:
assertnotconfig._has_includes()
assertconfig._included_paths()== []
# Ensure that config is included with branch using glob pattern.
withopen(path1,"w")asstream:
stream.write(template.format("/foo/**",path2))
withGitConfigParser(path1,repo=repo)asconfig:
assertconfig._has_includes()
assertconfig._included_paths()== [("path",path2)]
@with_rw_directory
deftest_conditional_includes_from_branch_name_error(self,rw_dir):
# Initiate mocked repository to raise an error if HEAD is detached.
repo=mock.Mock()
type(repo).active_branch=mock.PropertyMock(side_effect=TypeError)
# Initiate config file.
path1=osp.join(rw_dir,"config1")
# Ensure that config is ignored when active branch cannot be found.
withopen(path1,"w")asstream:
stream.write('[includeIf "onbranch:foo"]\n path=/path\n')
withGitConfigParser(path1,repo=repo)asconfig:
assertnotconfig._has_includes()
assertconfig._included_paths()== []
@with_rw_directory
deftest_conditional_includes_remote_url(self,rw_dir):
# Initiate mocked repository.
repo=mock.Mock()
repo.remotes= [mock.Mock(url="https://github.com/foo/repo")]
# Initiate config files.
path1=osp.join(rw_dir,"config1")
path2=osp.join(rw_dir,"config2")
template='[includeIf "hasconfig:remote.*.url:{}"]\n path={}\n'
# Ensure that config with hasconfig and full url is correct.
withopen(path1,"w")asstream:
stream.write(template.format("https://github.com/foo/repo",path2))
withGitConfigParser(path1,repo=repo)asconfig:
assertconfig._has_includes()
assertconfig._included_paths()== [("path",path2)]
# Ensure that config with hasconfig and incorrect url is incorrect.
withopen(path1,"w")asstream:
stream.write(template.format("incorrect",path2))
withGitConfigParser(path1,repo=repo)asconfig:
assertnotconfig._has_includes()
assertconfig._included_paths()== []
# Ensure that config with hasconfig and url using glob pattern is correct.
withopen(path1,"w")asstream:
stream.write(template.format("**/**github.com*/**",path2))
withGitConfigParser(path1,repo=repo)asconfig:
assertconfig._has_includes()
assertconfig._included_paths()== [("path",path2)]
deftest_rename(self):
file_obj=self._to_memcache(fixture_path("git_config"))
withGitConfigParser(file_obj,read_only=False,merge_includes=False)ascw:
withself.assertRaises(ValueError):
cw.rename_section("doesntexist","foo")
withself.assertRaises(ValueError):
cw.rename_section("core","include")
nn="bee"
assertcw.rename_section("core",nn)iscw
assertnotcw.has_section("core")
assertlen(cw.items(nn))==4
deftest_complex_aliases(self):
file_obj=self._to_memcache(fixture_path(".gitconfig"))
withGitConfigParser(file_obj,read_only=False)asw_config:
self.assertEqual(
w_config.get("alias","rbi"),
"!g() { git rebase -i origin/${1:-master} ; } ; g",
)
self.assertEqual(
file_obj.getvalue(),
self._to_memcache(fixture_path(".gitconfig")).getvalue(),
)
deftest_config_with_extra_whitespace(self):
cr=GitConfigParser(fixture_path("git_config_with_extra_whitespace"),read_only=True)
self.assertEqual(cr.get("init","defaultBranch"),"trunk")
deftest_empty_config_value(self):
cr=GitConfigParser(fixture_path("git_config_with_empty_value"),read_only=True)
assertcr.get_value("core","filemode"),"Should read keys with values"
withself.assertRaises(cp.NoOptionError):
cr.get_value("color","ui")
deftest_config_with_quotes(self):
cr=GitConfigParser(fixture_path("git_config_with_quotes"),read_only=True)
self.assertEqual(cr.get("user","name"),"Cody Veal")
self.assertEqual(cr.get("user","email"),"cveal05@gmail.com")
deftest_config_with_empty_quotes(self):
cr=GitConfigParser(fixture_path("git_config_with_empty_quotes"),read_only=True)
self.assertEqual(cr.get("core","filemode"),"","quotes can form a literal empty string as value")
deftest_config_with_quotes_with_literal_whitespace(self):
cr=GitConfigParser(fixture_path("git_config_with_quotes_whitespace_inside"),read_only=True)
self.assertEqual(cr.get("core","commentString"),"# ")
deftest_config_with_quotes_with_whitespace_outside_value(self):
cr=GitConfigParser(fixture_path("git_config_with_quotes_whitespace_outside"),read_only=True)
self.assertEqual(cr.get("init","defaultBranch"),"trunk")
deftest_config_with_quotes_containing_escapes(self):
"""For now just suppress quote removal. But it would be good to interpret most of these."""
cr=GitConfigParser(fixture_path("git_config_with_quotes_escapes"),read_only=True)
# These can eventually be supported by substituting the represented character.
self.assertEqual(cr.get("custom","hasnewline"),R'"first\nsecond"')
self.assertEqual(cr.get("custom","hasbackslash"),R'"foo\\bar"')
self.assertEqual(cr.get("custom","hasquote"),R'"ab\"cd"')
self.assertEqual(cr.get("custom","hastrailingbackslash"),R'"word\\"')
self.assertEqual(cr.get("custom","hasunrecognized"),R'"p\qrs"')
# It is less obvious whether and what to eventually do with this.
self.assertEqual(cr.get("custom","hasunescapedquotes"),'"ab"cd"e"')
# Cases where quote removal is clearly safe should happen even after those.
self.assertEqual(cr.get("custom","ordinary"),"hello world")
# Cases without quotes should still parse correctly even after those, too.
self.assertEqual(cr.get("custom","unquoted"),"good evening")
deftest_get_values_works_without_requiring_any_other_calls_first(self):
file_obj=self._to_memcache(fixture_path("git_config_multiple"))
cr=GitConfigParser(file_obj,read_only=True)
self.assertEqual(cr.get_values("section0","option0"), ["value0"])
file_obj.seek(0)
cr=GitConfigParser(file_obj,read_only=True)
self.assertEqual(cr.get_values("section1","option1"), ["value1a","value1b"])
file_obj.seek(0)
cr=GitConfigParser(file_obj,read_only=True)
self.assertEqual(cr.get_values("section1","other_option1"), ["other_value1"])
deftest_multiple_values(self):
file_obj=self._to_memcache(fixture_path("git_config_multiple"))
withGitConfigParser(file_obj,read_only=False)ascw:
self.assertEqual(cw.get("section0","option0"),"value0")
self.assertEqual(cw.get_values("section0","option0"), ["value0"])
self.assertEqual(cw.items("section0"), [("option0","value0")])
# Where there are multiple values, "get" returns the last.
self.assertEqual(cw.get("section1","option1"),"value1b")
self.assertEqual(cw.get_values("section1","option1"), ["value1a","value1b"])
self.assertEqual(
cw.items("section1"),
[("option1","value1b"), ("other_option1","other_value1")],
)
self.assertEqual(
cw.items_all("section1"),
[
("option1", ["value1a","value1b"]),
("other_option1", ["other_value1"]),
],
)
withself.assertRaises(KeyError):
cw.get_values("section1","missing")
self.assertEqual(cw.get_values("section1","missing",1), [1])
self.assertEqual(cw.get_values("section1","missing","s"), ["s"])
deftest_multiple_values_rename(self):
file_obj=self._to_memcache(fixture_path("git_config_multiple"))
withGitConfigParser(file_obj,read_only=False)ascw:
cw.rename_section("section1","section2")
cw.write()
file_obj.seek(0)
cr=GitConfigParser(file_obj,read_only=True)
self.assertEqual(cr.get_value("section2","option1"),"value1b")
self.assertEqual(cr.get_values("section2","option1"), ["value1a","value1b"])
self.assertEqual(
cr.items("section2"),
[("option1","value1b"), ("other_option1","other_value1")],
)
self.assertEqual(
cr.items_all("section2"),
[
("option1", ["value1a","value1b"]),
("other_option1", ["other_value1"]),
],
)
deftest_multiple_to_single(self):
file_obj=self._to_memcache(fixture_path("git_config_multiple"))
withGitConfigParser(file_obj,read_only=False)ascw:
cw.set_value("section1","option1","value1c")
cw.write()
file_obj.seek(0)
cr=GitConfigParser(file_obj,read_only=True)
self.assertEqual(cr.get_value("section1","option1"),"value1c")
self.assertEqual(cr.get_values("section1","option1"), ["value1c"])
self.assertEqual(
cr.items("section1"),
[("option1","value1c"), ("other_option1","other_value1")],
)
self.assertEqual(
cr.items_all("section1"),
[("option1", ["value1c"]), ("other_option1", ["other_value1"])],
)
deftest_single_to_multiple(self):
file_obj=self._to_memcache(fixture_path("git_config_multiple"))
withGitConfigParser(file_obj,read_only=False)ascw:
cw.add_value("section1","other_option1","other_value1a")
cw.write()
file_obj.seek(0)
cr=GitConfigParser(file_obj,read_only=True)
self.assertEqual(cr.get_value("section1","option1"),"value1b")
self.assertEqual(cr.get_values("section1","option1"), ["value1a","value1b"])
self.assertEqual(cr.get_value("section1","other_option1"),"other_value1a")
self.assertEqual(
cr.get_values("section1","other_option1"),
["other_value1","other_value1a"],
)
self.assertEqual(
cr.items("section1"),
[("option1","value1b"), ("other_option1","other_value1a")],
)
self.assertEqual(
cr.items_all("section1"),
[
("option1", ["value1a","value1b"]),
("other_option1", ["other_value1","other_value1a"]),
],
)
deftest_add_to_multiple(self):
file_obj=self._to_memcache(fixture_path("git_config_multiple"))
withGitConfigParser(file_obj,read_only=False)ascw:
cw.add_value("section1","option1","value1c")
cw.write()
file_obj.seek(0)
cr=GitConfigParser(file_obj,read_only=True)
self.assertEqual(cr.get_value("section1","option1"),"value1c")
self.assertEqual(cr.get_values("section1","option1"), ["value1a","value1b","value1c"])
self.assertEqual(
cr.items("section1"),
[("option1","value1c"), ("other_option1","other_value1")],
)
self.assertEqual(
cr.items_all("section1"),
[
("option1", ["value1a","value1b","value1c"]),
("other_option1", ["other_value1"]),
],
)
deftest_setlast(self):
# Test directly, not covered by higher-level tests.
omd=_OMD()
omd.setlast("key","value1")
self.assertEqual(omd["key"],"value1")
self.assertEqual(omd.getall("key"), ["value1"])
omd.setlast("key","value2")
self.assertEqual(omd["key"],"value2")
self.assertEqual(omd.getall("key"), ["value2"])