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