buildframework/helium/sf/python/pythoncore/lib/pythoncorecpythontests/test_logger.py
author lorewang
Wed, 01 Dec 2010 16:05:36 +0800
changeset 715 e0739b8406dd
parent 645 b8d81fa19e7d
permissions -rw-r--r--
Specify extenal tool with path
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
#============================================================================ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
#Name        : test_logger.py 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
#Part of     : Helium 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
#All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
#This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
#which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
#Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
#Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
#Description:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
#===============================================================================
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    19
""" test logger"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import unittest
645
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 588
diff changeset
    24
import urllib2
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import helium.logger
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import helium.outputer
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
# Uncomment this line to enable logging in this module, or configure logging elsewhere
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
#logging.basicConfig(level=logging.DEBUG)
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    32
_logger = logging.getLogger('test.helium.logger')
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
class TestHeliumLogger(unittest.TestCase):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
    """ Unit test case for HeliumLogger """        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
    def test_mc_logger_xml_generation(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
        """ Test simple XML logging generation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
        mclogger = helium.logger.Logger()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
        mclogger.SetInterface("http://fawww.europe.company.com/isis/isis_interface/")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
        mclogger.SetTitle("Validate Overlay")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
        mclogger.SetSubTitle("Validating: ")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
        mclogger.OpenMainContent("test")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
        mclogger.PrintRaw("<a href=\"google.com\">test</a>")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
        mclogger.Print("test")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
        mclogger.Print(u"\u00A9")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
        mclogger.error("test")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
        mclogger.CloseMainContent()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
        mclogger.OpenMainContent("test2")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
        mclogger.OpenEvent("test2")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
        mclogger.Print("test2")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
        mclogger.error("test2")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
        mclogger.CloseEvent()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
        mclogger.CloseMainContent()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
        mclogger.WriteToFile('log.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
        
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    57
        _logger.info(mclogger)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
        os.unlink('log.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
        #out = helium.outputer.XML2XHTML("log.xml")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        #out.generate()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
        #out.WriteToFile("log.html")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
    def test_helium_logger_unicode_handling(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
        """ Test simple XML logging generation with unicode handling. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
        mclogger = helium.logger.Logger()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
        mclogger.SetInterface("http://fawww.europe.company.com/isis/isis_interface/")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
        mclogger.SetTitle("Validate Overlay")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
        mclogger.SetSubTitle("Validating: ")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        mclogger.OpenMainContent("test")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
        mclogger.Print(u"Test unicode handling: \u00A9")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
        mclogger.CloseMainContent()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
        mclogger.WriteToFile('log.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    76
        _logger.info(mclogger)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
        os.unlink('log.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
    def test_helium_logger_outputer(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
        """ Test simple XML logging generation with unicode handling and XHTML generation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
        mclogger = helium.logger.Logger()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
        mclogger.SetInterface("http://fawww.europe.company.com/isis/isis_interface/")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
        mclogger.SetTitle("Validate Overlay")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
        mclogger.SetSubTitle("Validating: ")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
        mclogger.OpenMainContent("test")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
        mclogger.Print(u"Test unicode handling: \u00A9")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
        mclogger.CloseMainContent()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
        mclogger.WriteToFile('log.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
        
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    91
        _logger.info(mclogger)
645
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 588
diff changeset
    92
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 588
diff changeset
    93
        try:
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 588
diff changeset
    94
            out = helium.outputer.XML2XHTML('log.xml')
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 588
diff changeset
    95
            out.generate()
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 588
diff changeset
    96
            out.WriteToFile('log.html')
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 588
diff changeset
    97
        except urllib2.URLError, e:
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 588
diff changeset
    98
            _logger.warning('Test cannont run properly as the configuration url cannot be accessed properly.')
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
        os.unlink('log.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
        os.unlink('log.html')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
if __name__ == '__main__':
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
    unittest.main()