Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix silliness in test
  • Loading branch information
nyalldawson committed Jun 18, 2018
1 parent 063b169 commit 5b47f94
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions tests/src/python/test_qgsmessagelog.py
Expand Up @@ -31,71 +31,61 @@
class TestQgsMessageLog(unittest.TestCase):

def testSignals(self):
local_log = QgsMessageLog()
app_log = QgsApplication.messageLog()

# signals should only be emitted by application log, not local log
local_spy = QSignalSpy(local_log.messageReceived)
local_spy_received = QSignalSpy(local_log.messageReceived[bool])
# signals should be emitted by application log
app_spy = QSignalSpy(app_log.messageReceived)
app_spy_received = QSignalSpy(app_log.messageReceived[bool])

local_log.logMessage('test', 'tag', Qgis.Info, notifyUser=True)
self.assertEqual(len(local_spy), 0)
self.assertEqual(len(local_spy_received), 0)
QgsMessageLog.logMessage('test', 'tag', Qgis.Info, notifyUser=True)
self.assertEqual(len(app_spy), 1)
self.assertEqual(app_spy[-1], ['test', 'tag', Qgis.Info])
# info message, so messageReceived(bool) should not be emitted
self.assertEqual(len(app_spy_received), 0)

local_log.logMessage('test', 'tag', Qgis.Warning, notifyUser=True)
self.assertEqual(len(local_spy), 0)
self.assertEqual(len(local_spy_received), 0)
QgsMessageLog.logMessage('test', 'tag', Qgis.Warning, notifyUser=True)
self.assertEqual(len(app_spy), 2)
self.assertEqual(app_spy[-1], ['test', 'tag', Qgis.Warning])
# warning message, so messageReceived(bool) should be emitted
self.assertEqual(len(app_spy_received), 1)

local_log.logMessage('test', 'tag', Qgis.Warning, notifyUser=False)
self.assertEqual(len(local_spy), 0)
self.assertEqual(len(local_spy_received), 0)
QgsMessageLog.logMessage('test', 'tag', Qgis.Warning, notifyUser=False)
self.assertEqual(len(app_spy), 3)
# notifyUser was False
self.assertEqual(len(app_spy_received), 1)

def testBlocker(self):
local_log = QgsMessageLog()
app_log = QgsApplication.messageLog()

spy = QSignalSpy(app_log.messageReceived)
spy_received = QSignalSpy(app_log.messageReceived[bool])

local_log.logMessage('test', 'tag', Qgis.Warning, notifyUser=True)
QgsMessageLog.logMessage('test', 'tag', Qgis.Warning, notifyUser=True)
self.assertEqual(len(spy), 1)
self.assertEqual(spy[-1], ['test', 'tag', Qgis.Warning])
self.assertEqual(len(spy_received), 1)

# block notifications
b = QgsMessageLogNotifyBlocker()
local_log.logMessage('test', 'tag', Qgis.Warning, notifyUser=True)
QgsMessageLog.logMessage('test', 'tag', Qgis.Warning, notifyUser=True)
self.assertEqual(len(spy), 2) # should not be blocked
self.assertEqual(len(spy_received), 1) # should be blocked

# another blocker
b2 = QgsMessageLogNotifyBlocker()
local_log.logMessage('test', 'tag', Qgis.Warning, notifyUser=True)
QgsMessageLog.logMessage('test', 'tag', Qgis.Warning, notifyUser=True)
self.assertEqual(len(spy), 3) # should not be blocked
self.assertEqual(len(spy_received), 1) # should be blocked

del b
# still blocked because of b2
local_log.logMessage('test', 'tag', Qgis.Warning, notifyUser=True)
QgsMessageLog.logMessage('test', 'tag', Qgis.Warning, notifyUser=True)
self.assertEqual(len(spy), 4) # should not be blocked
self.assertEqual(len(spy_received), 1) # should be blocked

del b2
# not blocked
local_log.logMessage('test', 'tag', Qgis.Warning, notifyUser=True)
QgsMessageLog.logMessage('test', 'tag', Qgis.Warning, notifyUser=True)
self.assertEqual(len(spy), 5) # should not be blocked
self.assertEqual(len(spy_received), 2) # should not be blocked

Expand Down

0 comments on commit 5b47f94

Please sign in to comment.