Skip to content

Instantly share code, notes, and snippets.

View tpulmano's full-sized avatar

Tomas Pulmano tpulmano

View GitHub Profile
@tpulmano
tpulmano / gist:4698820
Last active December 12, 2015 02:28
Mock + PyQt4 + unittest Examples
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)
@tpulmano
tpulmano / gist:4349575
Created December 20, 2012 23:36
PyQt4 Drag And Drop Example
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtCore import Qt
class DragFromWidget(QtGui.QDockWidget):
def __init__(self, parent=None):
super(DragFromWidget, self).__init__(parent=parent)