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 (
1612RemoteProgress ,
1713FetchInfo ,
2521Remote ,
2622GitCommandError
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):
213214new_remote_branch .rename ("other_branch_name" )
214215res = fetch_and_test (remote )
215216other_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
219220Head .delete (new_remote_branch .repo ,new_remote_branch )
@@ -223,34 +224,37 @@ def get_info(res, remote, name):
223224
224225# prune stale tracking branches
225226stale_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 )
227229RemoteReference .delete (rw_repo ,* stale_refs )
228230
229231# test single branch fetch with refspec including target remote
230232res = 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
234237res = 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
243246rtag = TagReference .create (remote_repo ,"1.0-RV_hello.there" )
244247res = fetch_and_test (remote ,tags = True )
245248tinfo = 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 )
247251assert tinfo .flags & tinfo .NEW_TAG
248252
249253# adjust tag commit
250254Reference .set_object (rtag ,rhead .commit .parents [0 ].parents [0 ])
251255res = fetch_and_test (remote ,tags = True )
252256tinfo = res [str (rtag )]
253- assert tinfo .commit == rtag .commit
257+ self . assertEqual ( tinfo .commit , rtag .commit )
254258assert 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
328332res = remote .push ('+%s' % lhead .reference )
329- assert res [0 ].flags & PushInfo .ERROR == 0
333+ self . assertEqual ( res [0 ].flags & PushInfo .ERROR , 0 )
330334assert res [0 ].flags & PushInfo .FORCED_UPDATE
331335self ._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
354358res = 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
358363res = remote .push (":%s" % new_tag .path )
@@ -485,7 +490,7 @@ def test_creation_and_removal(self, bare_rw_repo):
485490new_name = "test_new_one"
486491arg_list = (new_name ,"git@server:hello.git" )
487492remote = Remote .create (bare_rw_repo ,* arg_list )
488- assert remote .name == "test_new_one"
493+ self . assertEqual ( remote .name , "test_new_one" )
489494assert remote in bare_rw_repo .remotes
490495assert remote .exists ()
491496
@@ -520,7 +525,7 @@ def test_fetch_info(self):
520525remote_info_line_fmt % "local/master" ,
521526fetch_info_line_fmt % 'remote-tracking branch' )
522527assert 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):
547552fetch_info_line_fmt % 'tag' )
548553
549554assert 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
553558fi = FetchInfo ._from_line (self .rorepo ,
554559remote_info_line_fmt % "remotename/branch" ,
555560fetch_info_line_fmt % 'branch' )
556561
557562assert 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
561566fi = FetchInfo ._from_line (self .rorepo ,
562567remote_info_line_fmt % "refs/something/branch" ,
563568fetch_info_line_fmt % 'branch' )
564569
565570assert type (fi .ref )is Reference
566- assert fi .ref .path == "refs/something/branch"
571+ self . assertEqual ( fi .ref .path , "refs/something/branch" )
567572
568573def test_uncommon_branch_names (self ):
569574stderr_lines = fixture ('uncommon_branch_prefix_stderr' ).decode ('ascii' ).splitlines ()
@@ -574,8 +579,8 @@ def test_uncommon_branch_names(self):
574579res = [FetchInfo ._from_line ('ShouldntMatterRepo' ,stderr ,fetch_line )
575580for stderr ,fetch_line in zip (stderr_lines ,fetch_lines )]
576581assert 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' )
579584assert isinstance (res [0 ].ref ,Head )
580585
581586@with_rw_repo ('HEAD' ,bare = False )
@@ -588,36 +593,36 @@ def test_multiple_urls(self, rw_repo):
588593remote = rw_repo .remotes [0 ]
589594# Testing setting a single URL
590595remote .set_url (test1 )
591- assert list (remote .urls )== [test1 ]
596+ self . assertEqual ( list (remote .urls ), [test1 ])
592597
593598# Testing replacing that single URL
594599remote .set_url (test1 )
595- assert list (remote .urls )== [test1 ]
600+ self . assertEqual ( list (remote .urls ), [test1 ])
596601# Testing adding new URLs
597602remote .set_url (test2 ,add = True )
598- assert list (remote .urls )== [test1 ,test2 ]
603+ self . assertEqual ( list (remote .urls ), [test1 ,test2 ])
599604remote .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
602607remote .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
605610remote .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
609614assert_raises (GitCommandError ,remote .set_url ,test2 ,add = True ,delete = True )
610615
611616# Testing on another remote, with the add/delete URL
612617remote = rw_repo .create_remote ('another' ,url = test1 )
613618remote .add_url (test2 )
614- assert list (remote .urls )== [test1 ,test2 ]
619+ self . assertEqual ( list (remote .urls ), [test1 ,test2 ])
615620remote .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
618623remote .delete_url (test2 )
619- assert list (remote .urls )== [test1 ,test3 ]
624+ self . assertEqual ( list (remote .urls ), [test1 ,test3 ])
620625remote .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
623628assert_raises (GitCommandError ,remote .delete_url ,test3 )