Last active
December 12, 2015 02:28
-
-
Save tpulmano/4698820 to your computer and use it in GitHub Desktop.
Mock + PyQt4 + unittest Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mock | |
# Example of patching QErrorMessage. Check that an error message is shown. | |
@mock.patch("PyQt4.QtGui.QErrorMessage", autospec=True) | |
def test_onSessionCreateFailed(self, MockErrorMessage): | |
self.widget.onSessionCreateFailed(ValueError("This is a test")) | |
self.assertTrue(MockErrorMessage.return_value.showMessage.called) | |
# example of mocking a method | |
dummyServer.getAllActiveJobs = mock.Mock(return_value=TEST_JOBS) | |
# example 2 of mocking a method | |
@mock.patch.object(QtGui.QDialog, "show") | |
def test_show(self, mockedMethod): | |
self.assertFalse(mockedMethod.called) | |
self.dialog.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment