Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8364597

Browse files
committed
test,#525: allow disabling freeze errors separately
+ cmd: use DEVNULL for non PIPEs; no open-file.+ TCs: some unitestize-assertions on base & remote TCs.
1 parent6310480 commit8364597

File tree

4 files changed

+64
-54
lines changed

4 files changed

+64
-54
lines changed

‎git/cmd.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@ def execute(self, command,
539539
cmd_not_found_exception=OSError
540540
# end handle
541541

542+
stdout_sink= (PIPE
543+
ifwith_stdout
544+
elsegetattr(subprocess,'DEVNULL',open(os.devnull,'wb')))
542545
log.debug("Popen(%s, cwd=%s, universal_newlines=%s, shell=%s)",
543546
command,cwd,universal_newlines,shell)
544547
try:
@@ -548,9 +551,9 @@ def execute(self, command,
548551
bufsize=-1,
549552
stdin=istream,
550553
stderr=PIPE,
551-
stdout=PIPEifwith_stdoutelseopen(os.devnull,'wb'),
554+
stdout=stdout_sink,
552555
shell=shellisnotNoneandshellorself.USE_SHELL,
553-
close_fds=(is_posix),# unsupported on windows
556+
close_fds=is_posix,# unsupported on windows
554557
universal_newlines=universal_newlines,
555558
creationflags=PROC_CREATIONFLAGS,
556559
**subprocess_kwargs

‎git/test/test_base.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def tearDown(self):
4141
deftest_base_object(self):
4242
# test interface of base object classes
4343
types= (Blob,Tree,Commit,TagObject)
44-
assertlen(types)==len(self.type_tuples)
44+
self.assertEqual(len(types),len(self.type_tuples))
4545

4646
s=set()
4747
num_objs=0
@@ -55,12 +55,12 @@ def test_base_object(self):
5555
item=obj_type(self.rorepo,binsha,0,path)
5656
# END handle index objects
5757
num_objs+=1
58-
assertitem.hexsha==hexsha
59-
assertitem.type==typename
58+
self.assertEqual(item.hexsha,hexsha)
59+
self.assertEqual(item.type,typename)
6060
assertitem.size
61-
assertitem==item
62-
assertnotitem!=item
63-
assertstr(item)==item.hexsha
61+
self.assertEqual(item,item)
62+
self.assertNotEqual(notitem,item)
63+
self.assertEqual(str(item),item.hexsha)
6464
assertrepr(item)
6565
s.add(item)
6666

@@ -78,16 +78,16 @@ def test_base_object(self):
7878

7979
tmpfilename=tempfile.mktemp(suffix='test-stream')
8080
withopen(tmpfilename,'wb+')astmpfile:
81-
assertitem==item.stream_data(tmpfile)
81+
self.assertEqual(item,item.stream_data(tmpfile))
8282
tmpfile.seek(0)
83-
asserttmpfile.read()==data
83+
self.assertEqual(tmpfile.read(),data)
8484
os.remove(tmpfilename)
8585
# END for each object type to create
8686

8787
# each has a unique sha
88-
assertlen(s)==num_objs
89-
assertlen(s|s)==num_objs
90-
assertnum_index_objs==2
88+
self.assertEqual(len(s),num_objs)
89+
self.assertEqual(len(s|s),num_objs)
90+
self.assertEqual(num_index_objs,2)
9191

9292
deftest_get_object_type_by_name(self):
9393
fortnameinbase.Object.TYPES:
@@ -98,7 +98,7 @@ def test_get_object_type_by_name(self):
9898

9999
deftest_object_resolution(self):
100100
# objects must be resolved to shas so they compare equal
101-
assertself.rorepo.head.reference.object==self.rorepo.active_branch.object
101+
self.assertEqual(self.rorepo.head.reference.object,self.rorepo.active_branch.object)
102102

103103
@with_rw_repo('HEAD',bare=True)
104104
deftest_with_bare_rw_repo(self,bare_rw_repo):
@@ -110,6 +110,7 @@ def test_with_rw_repo(self, rw_repo):
110110
assertnotrw_repo.config_reader("repository").getboolean("core","bare")
111111
assertos.path.isdir(os.path.join(rw_repo.working_tree_dir,'lib'))
112112

113+
#@skipIf(HIDE_WINDOWS_FREEZE_ERRORS, "FIXME: Freezes! sometimes...")
113114
@with_rw_and_rw_remote_repo('0.1.6')
114115
deftest_with_rw_remote_and_rw_repo(self,rw_repo,rw_remote_repo):
115116
assertnotrw_repo.config_reader("repository").getboolean("core","bare")

‎git/test/test_remote.py

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

7-
fromgit.test.libimport (
8-
TestBase,
9-
with_rw_repo,
10-
with_rw_and_rw_remote_repo,
11-
fixture,
12-
GIT_DAEMON_PORT,
13-
assert_raises
14-
)
7+
importrandom
8+
importtempfile
9+
fromunittest.caseimportskipIf
10+
1511
fromgitimport (
1612
RemoteProgress,
1713
FetchInfo,
@@ -25,14 +21,19 @@
2521
Remote,
2622
GitCommandError
2723
)
28-
fromgit.utilimportIterableList,rmtree
24+
fromgit.cmdimportGit
2925
fromgit.compatimportstring_types
30-
importtempfile
26+
fromgit.test.libimport (
27+
TestBase,
28+
with_rw_repo,
29+
with_rw_and_rw_remote_repo,
30+
fixture,
31+
GIT_DAEMON_PORT,
32+
assert_raises
33+
)
34+
fromgit.utilimportIterableList,rmtree,HIDE_WINDOWS_FREEZE_ERRORS,HIDE_WINDOWS_KNOWN_ERRORS
3135
importos.pathasosp
32-
importrandom
33-
fromunittest.caseimportskipIf
34-
fromgit.utilimportHIDE_WINDOWS_KNOWN_ERRORS
35-
fromgit.cmdimportGit
36+
3637

3738
# assure we have repeatable results
3839
random.seed(0)
@@ -213,7 +214,7 @@ def get_info(res, remote, name):
213214
new_remote_branch.rename("other_branch_name")
214215
res=fetch_and_test(remote)
215216
other_branch_info=get_info(res,remote,new_remote_branch)
216-
assertother_branch_info.ref.commit==new_branch_info.ref.commit
217+
self.assertEqual(other_branch_info.ref.commit,new_branch_info.ref.commit)
217218

218219
# remove new branch
219220
Head.delete(new_remote_branch.repo,new_remote_branch)
@@ -223,34 +224,37 @@ def get_info(res, remote, name):
223224

224225
# prune stale tracking branches
225226
stale_refs=remote.stale_refs
226-
assertlen(stale_refs)==2andisinstance(stale_refs[0],RemoteReference)
227+
self.assertEqual(len(stale_refs),2)
228+
self.assertIsInstance(stale_refs[0],RemoteReference)
227229
RemoteReference.delete(rw_repo,*stale_refs)
228230

229231
# test single branch fetch with refspec including target remote
230232
res=fetch_and_test(remote,refspec="master:refs/remotes/%s/master"%remote)
231-
assertlen(res)==1andget_info(res,remote,'master')
233+
self.assertEqual(len(res),1)
234+
self.assertTrue(get_info(res,remote,'master'))
232235

233236
# ... with respec and no target
234237
res=fetch_and_test(remote,refspec='master')
235-
assertlen(res)==1
238+
self.assertEqual(len(res),1)
236239

237240
# ... multiple refspecs ... works, but git command returns with error if one ref is wrong without
238241
# doing anything. This is new in later binaries
239242
# res = fetch_and_test(remote, refspec=['master', 'fred'])
240-
#assertlen(res) == 1
243+
#self.assertEqual(len(res), 1)
241244

242245
# add new tag reference
243246
rtag=TagReference.create(remote_repo,"1.0-RV_hello.there")
244247
res=fetch_and_test(remote,tags=True)
245248
tinfo=res[str(rtag)]
246-
assertisinstance(tinfo.ref,TagReference)andtinfo.ref.commit==rtag.commit
249+
self.assertIsInstance(tinfo.ref,TagReference)
250+
self.assertEqual(tinfo.ref.commit,rtag.commit)
247251
asserttinfo.flags&tinfo.NEW_TAG
248252

249253
# adjust tag commit
250254
Reference.set_object(rtag,rhead.commit.parents[0].parents[0])
251255
res=fetch_and_test(remote,tags=True)
252256
tinfo=res[str(rtag)]
253-
asserttinfo.commit==rtag.commit
257+
self.assertEqual(tinfo.commit,rtag.commit)
254258
asserttinfo.flags&tinfo.TAG_UPDATE
255259

256260
# delete remote tag - local one will stay
@@ -326,7 +330,7 @@ def _assert_push_and_pull(self, remote, rw_repo, remote_repo):
326330

327331
# force rejected pull
328332
res=remote.push('+%s'%lhead.reference)
329-
assertres[0].flags&PushInfo.ERROR==0
333+
self.assertEqual(res[0].flags&PushInfo.ERROR,0)
330334
assertres[0].flags&PushInfo.FORCED_UPDATE
331335
self._do_test_push_result(res,remote)
332336

@@ -352,7 +356,8 @@ def _assert_push_and_pull(self, remote, rw_repo, remote_repo):
352356

353357
# push force this tag
354358
res=remote.push("+%s"%new_tag.path)
355-
assertres[-1].flags&PushInfo.ERROR==0andres[-1].flags&PushInfo.FORCED_UPDATE
359+
self.assertEqual(res[-1].flags&PushInfo.ERROR,0)
360+
self.assertTrue(res[-1].flags&PushInfo.FORCED_UPDATE)
356361

357362
# delete tag - have to do it using refspec
358363
res=remote.push(":%s"%new_tag.path)
@@ -485,7 +490,7 @@ def test_creation_and_removal(self, bare_rw_repo):
485490
new_name="test_new_one"
486491
arg_list= (new_name,"git@server:hello.git")
487492
remote=Remote.create(bare_rw_repo,*arg_list)
488-
assertremote.name=="test_new_one"
493+
self.assertEqual(remote.name,"test_new_one")
489494
assertremoteinbare_rw_repo.remotes
490495
assertremote.exists()
491496

@@ -520,7 +525,7 @@ def test_fetch_info(self):
520525
remote_info_line_fmt%"local/master",
521526
fetch_info_line_fmt%'remote-tracking branch')
522527
assertnotfi.ref.is_valid()
523-
assertfi.ref.name=="local/master"
528+
self.assertEqual(fi.ref.name,"local/master")
524529

525530
# handles non-default refspecs: One can specify a different path in refs/remotes
526531
# or a special path just in refs/something for instance
@@ -547,23 +552,23 @@ def test_fetch_info(self):
547552
fetch_info_line_fmt%'tag')
548553

549554
assertisinstance(fi.ref,TagReference)
550-
assertfi.ref.path==tag_path
555+
self.assertEqual(fi.ref.path,tag_path)
551556

552557
# branches default to refs/remotes
553558
fi=FetchInfo._from_line(self.rorepo,
554559
remote_info_line_fmt%"remotename/branch",
555560
fetch_info_line_fmt%'branch')
556561

557562
assertisinstance(fi.ref,RemoteReference)
558-
assertfi.ref.remote_name=='remotename'
563+
self.assertEqual(fi.ref.remote_name,'remotename')
559564

560565
# but you can force it anywhere, in which case we only have a references
561566
fi=FetchInfo._from_line(self.rorepo,
562567
remote_info_line_fmt%"refs/something/branch",
563568
fetch_info_line_fmt%'branch')
564569

565570
asserttype(fi.ref)isReference
566-
assertfi.ref.path=="refs/something/branch"
571+
self.assertEqual(fi.ref.path,"refs/something/branch")
567572

568573
deftest_uncommon_branch_names(self):
569574
stderr_lines=fixture('uncommon_branch_prefix_stderr').decode('ascii').splitlines()
@@ -574,8 +579,8 @@ def test_uncommon_branch_names(self):
574579
res= [FetchInfo._from_line('ShouldntMatterRepo',stderr,fetch_line)
575580
forstderr,fetch_lineinzip(stderr_lines,fetch_lines)]
576581
assertlen(res)
577-
assertres[0].remote_ref_path=='refs/pull/1/head'
578-
assertres[0].ref.path=='refs/heads/pull/1/head'
582+
self.assertEqual(res[0].remote_ref_path,'refs/pull/1/head')
583+
self.assertEqual(res[0].ref.path,'refs/heads/pull/1/head')
579584
assertisinstance(res[0].ref,Head)
580585

581586
@with_rw_repo('HEAD',bare=False)
@@ -588,36 +593,36 @@ def test_multiple_urls(self, rw_repo):
588593
remote=rw_repo.remotes[0]
589594
# Testing setting a single URL
590595
remote.set_url(test1)
591-
assertlist(remote.urls)==[test1]
596+
self.assertEqual(list(remote.urls),[test1])
592597

593598
# Testing replacing that single URL
594599
remote.set_url(test1)
595-
assertlist(remote.urls)==[test1]
600+
self.assertEqual(list(remote.urls),[test1])
596601
# Testing adding new URLs
597602
remote.set_url(test2,add=True)
598-
assertlist(remote.urls)==[test1,test2]
603+
self.assertEqual(list(remote.urls),[test1,test2])
599604
remote.set_url(test3,add=True)
600-
assertlist(remote.urls)==[test1,test2,test3]
605+
self.assertEqual(list(remote.urls),[test1,test2,test3])
601606
# Testing removing an URL
602607
remote.set_url(test2,delete=True)
603-
assertlist(remote.urls)==[test1,test3]
608+
self.assertEqual(list(remote.urls),[test1,test3])
604609
# Testing changing an URL
605610
remote.set_url(test3,test2)
606-
assertlist(remote.urls)==[test1,test2]
611+
self.assertEqual(list(remote.urls),[test1,test2])
607612

608613
# will raise: fatal: --add --delete doesn't make sense
609614
assert_raises(GitCommandError,remote.set_url,test2,add=True,delete=True)
610615

611616
# Testing on another remote, with the add/delete URL
612617
remote=rw_repo.create_remote('another',url=test1)
613618
remote.add_url(test2)
614-
assertlist(remote.urls)==[test1,test2]
619+
self.assertEqual(list(remote.urls),[test1,test2])
615620
remote.add_url(test3)
616-
assertlist(remote.urls)==[test1,test2,test3]
621+
self.assertEqual(list(remote.urls),[test1,test2,test3])
617622
# Testing removing all the URLs
618623
remote.delete_url(test2)
619-
assertlist(remote.urls)==[test1,test3]
624+
self.assertEqual(list(remote.urls),[test1,test3])
620625
remote.delete_url(test1)
621-
assertlist(remote.urls)==[test3]
626+
self.assertEqual(list(remote.urls),[test3])
622627
# will raise fatal: Will not delete all non-push URLs
623628
assert_raises(GitCommandError,remote.delete_url,test3)

‎git/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#: so the errors marked with this var are considered "acknowledged" ones, awaiting remedy,
5252
#: till then, we wish to hide them.
5353
HIDE_WINDOWS_KNOWN_ERRORS=is_winandos.environ.get('HIDE_WINDOWS_KNOWN_ERRORS',True)
54+
HIDE_WINDOWS_FREEZE_ERRORS=is_winandos.environ.get('HIDE_WINDOWS_FREEZE_ERRORS',HIDE_WINDOWS_KNOWN_ERRORS)
5455

5556
#{ Utility Methods
5657

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp