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- from git .test .lib import (
8- TestBase ,
9- with_rw_repo ,
10- with_rw_and_rw_remote_repo ,
11- fixture ,
12- GIT_DAEMON_PORT ,
13- assert_raises
14- )
7+ import random
8+ import tempfile
9+ from unittest .case import skipIf
10+
1511from git import (
1612 RemoteProgress ,
1713 FetchInfo ,
2521 Remote ,
2622 GitCommandError
2723)
28- from git .util import IterableList , rmtree
24+ from git .cmd import Git
2925from git .compat import string_types
30- import tempfile
26+ from git .test .lib import (
27+ TestBase ,
28+ with_rw_repo ,
29+ with_rw_and_rw_remote_repo ,
30+ fixture ,
31+ GIT_DAEMON_PORT ,
32+ assert_raises
33+ )
34+ from git .util import IterableList , rmtree , HIDE_WINDOWS_FREEZE_ERRORS , HIDE_WINDOWS_KNOWN_ERRORS
3135import os .path as osp
32- import random
33- from unittest .case import skipIf
34- from git .util import HIDE_WINDOWS_KNOWN_ERRORS
35- from git .cmd import Git
36+
3637
3738# assure we have repeatable results
3839random .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- assert other_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- assert len (stale_refs ) == 2 and isinstance (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- assert len (res ) == 1 and get_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- assert len (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- # assert len(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- assert isinstance (tinfo .ref , TagReference ) and tinfo .ref .commit == rtag .commit
249+ self .assertIsInstance (tinfo .ref , TagReference )
250+ self .assertEqual (tinfo .ref .commit , rtag .commit )
247251 assert tinfo .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- assert tinfo .commit == rtag .commit
257+ self . assertEqual ( tinfo .commit , rtag .commit )
254258 assert tinfo .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- assert res [0 ].flags & PushInfo .ERROR == 0
333+ self . assertEqual ( res [0 ].flags & PushInfo .ERROR , 0 )
330334 assert res [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- assert res [- 1 ].flags & PushInfo .ERROR == 0 and res [- 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- assert remote .name == "test_new_one"
493+ self . assertEqual ( remote .name , "test_new_one" )
489494 assert remote in bare_rw_repo .remotes
490495 assert remote .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 assert not fi .ref .is_valid ()
523- assert fi .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 assert isinstance (fi .ref , TagReference )
550- assert fi .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 assert isinstance (fi .ref , RemoteReference )
558- assert fi .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 assert type (fi .ref ) is Reference
566- assert fi .ref .path == "refs/something/branch"
571+ self . assertEqual ( fi .ref .path , "refs/something/branch" )
567572
568573 def test_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 for stderr , fetch_line in zip (stderr_lines , fetch_lines )]
576581 assert len (res )
577- assert res [0 ].remote_ref_path == 'refs/pull/1/head'
578- assert res [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 assert isinstance (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- assert list (remote .urls ) == [test1 ]
596+ self . assertEqual ( list (remote .urls ), [test1 ])
592597
593598 # Testing replacing that single URL
594599 remote .set_url (test1 )
595- assert list (remote .urls ) == [test1 ]
600+ self . assertEqual ( list (remote .urls ), [test1 ])
596601 # Testing adding new URLs
597602 remote .set_url (test2 , add = True )
598- assert list (remote .urls ) == [test1 , test2 ]
603+ self . assertEqual ( list (remote .urls ), [test1 , test2 ])
599604 remote .set_url (test3 , add = True )
600- assert list (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- assert list (remote .urls ) == [test1 , test3 ]
608+ self . assertEqual ( list (remote .urls ), [test1 , test3 ])
604609 # Testing changing an URL
605610 remote .set_url (test3 , test2 )
606- assert list (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- assert list (remote .urls ) == [test1 , test2 ]
619+ self . assertEqual ( list (remote .urls ), [test1 , test2 ])
615620 remote .add_url (test3 )
616- assert list (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- assert list (remote .urls ) == [test1 , test3 ]
624+ self . assertEqual ( list (remote .urls ), [test1 , test3 ])
620625 remote .delete_url (test1 )
621- assert list (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 )
0 commit comments