Skip to content

Commit 7bccdff

Browse files
committed
Rewrite test_push_options without mocking RemoteCallbacks
This has been spurred by the introduction of RemoteCallbacks.push_transfer_progress.
1 parent 3d02993 commit 7bccdff

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

test/test_remote.py

+19-10
Original file line numberDiff line numberDiff line change
@@ -439,22 +439,31 @@ def test_push_non_fast_forward_commits_to_remote_fails(origin, clone, remote):
439439
remote.push(['refs/heads/master'])
440440

441441

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
446448
assert remote_push_options.count == 0
447449

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
450453
assert remote_push_options.count == 0
451454

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
454461
assert remote_push_options.count == 1
455462
# strings pointed to by remote_push_options.strings[] are already freed
456463

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
459468
assert remote_push_options.count == 2
460469
# strings pointed to by remote_push_options.strings[] are already freed

0 commit comments

Comments
 (0)