Skip to content
Permalink
Browse files

Added test for logger

  • Loading branch information
timlinux committed Aug 17, 2012
1 parent 13ed8b8 commit 5a0fd2998255bb62e4f19f741e9ba7603d4b5291
Showing with 43 additions and 0 deletions.
  1. +1 −0 tests/src/python/CMakeLists.txt
  2. +42 −0 tests/src/python/test_qgslogger.py
@@ -4,3 +4,4 @@ ADD_PYTHON_TEST(PyQgsComposerMap test_qgscomposermap.py)
ADD_PYTHON_TEST(PyQgsGeometry test_qgsgeometry.py)
ADD_PYTHON_TEST(PyQgsRasterLayer test_qgsrasterlayer.py)
ADD_PYTHON_TEST(PyQgsMemoryProvider test_qgsmemoryprovider.py)
ADD_PYTHON_TEST(PyQgsLogger test_qgslogger.py)
@@ -0,0 +1,42 @@
import tempfile
import os
import unittest

from qgis.core import QgsLogger

# Convenience instances in case you may need them
# not used in this test
#from utilities import getQgisTestApp
#QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()

class TestQgsLogger(unittest.TestCase):

def testLogger(self):
(myFileHandle, myFilename) = tempfile.mkstemp()
try:
myFile = os.fdopen(myFileHandle, "w")
myFile.write("QGIS Logger Unit Test\n")
myFile.close()
os.environ['QGIS_DEBUG'] = '2'
os.environ['QGIS_LOG_FILE'] = myFilename
myLogger = QgsLogger()
myLogger.debug('This is a debug')
myLogger.warning('This is a warning')
myLogger.critical('This is critical')
#myLogger.fatal('Aaaargh...fatal'); #kills QGIS not testable
myFile = open(myFilename, 'rt')
myText = myFile.readlines()
myExpectedText = ['QGIS Logger Unit Test\n',
'This is a debug\n',
'This is a warning\n',
'This is critical\n']
myMessage = ('Expected:\n---\n%s\n---\nGot:\n---\n%s\n---\n' %
(myExpectedText, myText))
self.assertEquals(myText, myExpectedText, myMessage)
finally:
pass
os.remove(myFilename)

if __name__ == '__main__':
unittest.main()

0 comments on commit 5a0fd29

Please sign in to comment.
You can’t perform that action at this time.