4
4
# This module is part of GitPython and is released under
5
5
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
6
6
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
+
15
11
from git import (
16
12
RemoteProgress ,
17
13
FetchInfo ,
25
21
Remote ,
26
22
GitCommandError
27
23
)
28
- from git .util import IterableList , rmtree
24
+ from git .cmd import Git
29
25
from 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
31
35
import 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
+
36
37
37
38
# assure we have repeatable results
38
39
random .seed (0 )
@@ -213,7 +214,7 @@ def get_info(res, remote, name):
213
214
new_remote_branch .rename ("other_branch_name" )
214
215
res = fetch_and_test (remote )
215
216
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 )
217
218
218
219
# remove new branch
219
220
Head .delete (new_remote_branch .repo , new_remote_branch )
@@ -223,34 +224,37 @@ def get_info(res, remote, name):
223
224
224
225
# prune stale tracking branches
225
226
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 )
227
229
RemoteReference .delete (rw_repo , * stale_refs )
228
230
229
231
# test single branch fetch with refspec including target remote
230
232
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' ))
232
235
233
236
# ... with respec and no target
234
237
res = fetch_and_test (remote , refspec = 'master' )
235
- assert len (res ) == 1
238
+ self . assertEqual ( len (res ), 1 )
236
239
237
240
# ... multiple refspecs ... works, but git command returns with error if one ref is wrong without
238
241
# doing anything. This is new in later binaries
239
242
# res = fetch_and_test(remote, refspec=['master', 'fred'])
240
- # assert len(res) == 1
243
+ # self.assertEqual( len(res), 1)
241
244
242
245
# add new tag reference
243
246
rtag = TagReference .create (remote_repo , "1.0-RV_hello.there" )
244
247
res = fetch_and_test (remote , tags = True )
245
248
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 )
247
251
assert tinfo .flags & tinfo .NEW_TAG
248
252
249
253
# adjust tag commit
250
254
Reference .set_object (rtag , rhead .commit .parents [0 ].parents [0 ])
251
255
res = fetch_and_test (remote , tags = True )
252
256
tinfo = res [str (rtag )]
253
- assert tinfo .commit == rtag .commit
257
+ self . assertEqual ( tinfo .commit , rtag .commit )
254
258
assert tinfo .flags & tinfo .TAG_UPDATE
255
259
256
260
# delete remote tag - local one will stay
@@ -326,7 +330,7 @@ def _assert_push_and_pull(self, remote, rw_repo, remote_repo):
326
330
327
331
# force rejected pull
328
332
res = remote .push ('+%s' % lhead .reference )
329
- assert res [0 ].flags & PushInfo .ERROR == 0
333
+ self . assertEqual ( res [0 ].flags & PushInfo .ERROR , 0 )
330
334
assert res [0 ].flags & PushInfo .FORCED_UPDATE
331
335
self ._do_test_push_result (res , remote )
332
336
@@ -352,7 +356,8 @@ def _assert_push_and_pull(self, remote, rw_repo, remote_repo):
352
356
353
357
# push force this tag
354
358
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 )
356
361
357
362
# delete tag - have to do it using refspec
358
363
res = remote .push (":%s" % new_tag .path )
@@ -485,7 +490,7 @@ def test_creation_and_removal(self, bare_rw_repo):
485
490
new_name = "test_new_one"
486
491
arg_list = (new_name , "git@server:hello.git" )
487
492
remote = Remote .create (bare_rw_repo , * arg_list )
488
- assert remote .name == "test_new_one"
493
+ self . assertEqual ( remote .name , "test_new_one" )
489
494
assert remote in bare_rw_repo .remotes
490
495
assert remote .exists ()
491
496
@@ -520,7 +525,7 @@ def test_fetch_info(self):
520
525
remote_info_line_fmt % "local/master" ,
521
526
fetch_info_line_fmt % 'remote-tracking branch' )
522
527
assert not fi .ref .is_valid ()
523
- assert fi .ref .name == "local/master"
528
+ self . assertEqual ( fi .ref .name , "local/master" )
524
529
525
530
# handles non-default refspecs: One can specify a different path in refs/remotes
526
531
# or a special path just in refs/something for instance
@@ -547,23 +552,23 @@ def test_fetch_info(self):
547
552
fetch_info_line_fmt % 'tag' )
548
553
549
554
assert isinstance (fi .ref , TagReference )
550
- assert fi .ref .path == tag_path
555
+ self . assertEqual ( fi .ref .path , tag_path )
551
556
552
557
# branches default to refs/remotes
553
558
fi = FetchInfo ._from_line (self .rorepo ,
554
559
remote_info_line_fmt % "remotename/branch" ,
555
560
fetch_info_line_fmt % 'branch' )
556
561
557
562
assert isinstance (fi .ref , RemoteReference )
558
- assert fi .ref .remote_name == 'remotename'
563
+ self . assertEqual ( fi .ref .remote_name , 'remotename' )
559
564
560
565
# but you can force it anywhere, in which case we only have a references
561
566
fi = FetchInfo ._from_line (self .rorepo ,
562
567
remote_info_line_fmt % "refs/something/branch" ,
563
568
fetch_info_line_fmt % 'branch' )
564
569
565
570
assert type (fi .ref ) is Reference
566
- assert fi .ref .path == "refs/something/branch"
571
+ self . assertEqual ( fi .ref .path , "refs/something/branch" )
567
572
568
573
def test_uncommon_branch_names (self ):
569
574
stderr_lines = fixture ('uncommon_branch_prefix_stderr' ).decode ('ascii' ).splitlines ()
@@ -574,8 +579,8 @@ def test_uncommon_branch_names(self):
574
579
res = [FetchInfo ._from_line ('ShouldntMatterRepo' , stderr , fetch_line )
575
580
for stderr , fetch_line in zip (stderr_lines , fetch_lines )]
576
581
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' )
579
584
assert isinstance (res [0 ].ref , Head )
580
585
581
586
@with_rw_repo ('HEAD' , bare = False )
@@ -588,36 +593,36 @@ def test_multiple_urls(self, rw_repo):
588
593
remote = rw_repo .remotes [0 ]
589
594
# Testing setting a single URL
590
595
remote .set_url (test1 )
591
- assert list (remote .urls ) == [test1 ]
596
+ self . assertEqual ( list (remote .urls ), [test1 ])
592
597
593
598
# Testing replacing that single URL
594
599
remote .set_url (test1 )
595
- assert list (remote .urls ) == [test1 ]
600
+ self . assertEqual ( list (remote .urls ), [test1 ])
596
601
# Testing adding new URLs
597
602
remote .set_url (test2 , add = True )
598
- assert list (remote .urls ) == [test1 , test2 ]
603
+ self . assertEqual ( list (remote .urls ), [test1 , test2 ])
599
604
remote .set_url (test3 , add = True )
600
- assert list (remote .urls ) == [test1 , test2 , test3 ]
605
+ self . assertEqual ( list (remote .urls ), [test1 , test2 , test3 ])
601
606
# Testing removing an URL
602
607
remote .set_url (test2 , delete = True )
603
- assert list (remote .urls ) == [test1 , test3 ]
608
+ self . assertEqual ( list (remote .urls ), [test1 , test3 ])
604
609
# Testing changing an URL
605
610
remote .set_url (test3 , test2 )
606
- assert list (remote .urls ) == [test1 , test2 ]
611
+ self . assertEqual ( list (remote .urls ), [test1 , test2 ])
607
612
608
613
# will raise: fatal: --add --delete doesn't make sense
609
614
assert_raises (GitCommandError , remote .set_url , test2 , add = True , delete = True )
610
615
611
616
# Testing on another remote, with the add/delete URL
612
617
remote = rw_repo .create_remote ('another' , url = test1 )
613
618
remote .add_url (test2 )
614
- assert list (remote .urls ) == [test1 , test2 ]
619
+ self . assertEqual ( list (remote .urls ), [test1 , test2 ])
615
620
remote .add_url (test3 )
616
- assert list (remote .urls ) == [test1 , test2 , test3 ]
621
+ self . assertEqual ( list (remote .urls ), [test1 , test2 , test3 ])
617
622
# Testing removing all the URLs
618
623
remote .delete_url (test2 )
619
- assert list (remote .urls ) == [test1 , test3 ]
624
+ self . assertEqual ( list (remote .urls ), [test1 , test3 ])
620
625
remote .delete_url (test1 )
621
- assert list (remote .urls ) == [test3 ]
626
+ self . assertEqual ( list (remote .urls ), [test3 ])
622
627
# will raise fatal: Will not delete all non-push URLs
623
628
assert_raises (GitCommandError , remote .delete_url , test3 )
0 commit comments