@@ -439,22 +439,31 @@ def test_push_non_fast_forward_commits_to_remote_fails(origin, clone, remote):
439
439
remote .push (['refs/heads/master' ])
440
440
441
441
442
- @patch .object (pygit2 .callbacks , 'RemoteCallbacks' )
443
- def test_push_options (mock_callbacks , origin , clone , remote ):
444
- remote .push (['refs/heads/master' ])
445
- remote_push_options = mock_callbacks .return_value .push_options .remote_push_options
442
+ def test_push_options (origin , clone , remote ):
443
+ from pygit2 import RemoteCallbacks
444
+
445
+ callbacks = RemoteCallbacks ()
446
+ remote .push (['refs/heads/master' ], callbacks )
447
+ remote_push_options = callbacks .push_options .remote_push_options
446
448
assert remote_push_options .count == 0
447
449
448
- remote .push (['refs/heads/master' ], push_options = [])
449
- remote_push_options = mock_callbacks .return_value .push_options .remote_push_options
450
+ callbacks = RemoteCallbacks ()
451
+ remote .push (['refs/heads/master' ], callbacks , push_options = [])
452
+ remote_push_options = callbacks .push_options .remote_push_options
450
453
assert remote_push_options .count == 0
451
454
452
- remote .push (['refs/heads/master' ], push_options = ['foo' ])
453
- remote_push_options = mock_callbacks .return_value .push_options .remote_push_options
455
+ callbacks = RemoteCallbacks ()
456
+ # Local remotes don't support push_options, so pushing will raise an error.
457
+ # However, push_options should still be set in RemoteCallbacks.
458
+ with pytest .raises (pygit2 .GitError , match = 'push-options not supported by remote' ):
459
+ remote .push (['refs/heads/master' ], callbacks , push_options = ['foo' ])
460
+ remote_push_options = callbacks .push_options .remote_push_options
454
461
assert remote_push_options .count == 1
455
462
# strings pointed to by remote_push_options.strings[] are already freed
456
463
457
- remote .push (['refs/heads/master' ], push_options = ['Option A' , 'Option B' ])
458
- remote_push_options = mock_callbacks .return_value .push_options .remote_push_options
464
+ callbacks = RemoteCallbacks ()
465
+ with pytest .raises (pygit2 .GitError , match = 'push-options not supported by remote' ):
466
+ remote .push (['refs/heads/master' ], callbacks , push_options = ['Opt A' , 'Opt B' ])
467
+ remote_push_options = callbacks .push_options .remote_push_options
459
468
assert remote_push_options .count == 2
460
469
# strings pointed to by remote_push_options.strings[] are already freed
0 commit comments