641
|
1 |
|
|
2 |
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
|
|
9 |
'''
|
|
10 |
Test the HTML class in plugins/filter_html.py
|
|
11 |
'''
|
|
12 |
|
|
13 |
import os
|
|
14 |
import shutil
|
|
15 |
import sys
|
|
16 |
import unittest
|
|
17 |
|
|
18 |
test_data = os.path.join(os.getcwd(),"unit_suite","data","html_filter")
|
|
19 |
|
|
20 |
# add the plugins directory to the python path
|
|
21 |
sys.path.append(os.path.join(os.environ['SBS_HOME'], "python", "plugins"))
|
|
22 |
# so that we can import the filter module directly
|
|
23 |
import filter_html
|
|
24 |
import generic_path
|
|
25 |
|
|
26 |
class Mock(object):
|
|
27 |
'''empty object for attaching arbitrary attributes and functions.'''
|
|
28 |
pass
|
|
29 |
|
|
30 |
class TestFilterHtml(unittest.TestCase):
|
|
31 |
'''test cases for the HTML log filter.
|
|
32 |
|
|
33 |
This is a minimal set of tests for starters. As people start using this
|
|
34 |
filter and reporting bugs and niggles we can add test cases here to
|
|
35 |
avoid regressions.'''
|
|
36 |
|
|
37 |
def setUp(self):
|
|
38 |
self.mock_params = Mock()
|
|
39 |
self.mock_params.configPath = [generic_path.Path("config")]
|
|
40 |
self.mock_params.home = generic_path.Path(test_data)
|
|
41 |
self.mock_params.logFileName = generic_path.Path("tmp/foo")
|
|
42 |
self.mock_params.timestring = "now"
|
|
43 |
|
|
44 |
# where do we expect the output to be written
|
|
45 |
self.html_dir = str(self.mock_params.logFileName) + "_html"
|
|
46 |
|
|
47 |
def tearDown(self):
|
|
48 |
'''remove all the generated output files and directories.'''
|
|
49 |
if os.path.isdir(self.html_dir):
|
|
50 |
shutil.rmtree(self.html_dir)
|
|
51 |
|
|
52 |
def testPass(self):
|
|
53 |
'''are the setUp and tearDown methods sane.'''
|
|
54 |
pass
|
|
55 |
|
|
56 |
def testConstructor(self):
|
|
57 |
'''simply construct an HTML object.'''
|
|
58 |
html = filter_html.HTML()
|
|
59 |
|
|
60 |
def testMinimalLog(self):
|
|
61 |
'''process a minimal log file.'''
|
|
62 |
html = filter_html.HTML()
|
|
63 |
self.assertTrue( html.open(self.mock_params) )
|
|
64 |
self.assertTrue( html.write('<?xml version="1.0" encoding="ISO-8859-1" ?>\n') )
|
|
65 |
self.assertTrue( html.write('<buildlog sbs_version="2.99.9 [hi]">') )
|
|
66 |
self.assertTrue( html.write('</buildlog>') )
|
|
67 |
self.assertTrue( html.close() )
|
|
68 |
|
|
69 |
self.assertTrue( os.path.isfile(self.html_dir + "/index.html") )
|
|
70 |
self.assertTrue( os.path.isfile(self.html_dir + "/style.css") )
|
|
71 |
|
|
72 |
# run all the tests
|
|
73 |
|
|
74 |
from raptor_tests import SmokeTest
|
|
75 |
|
|
76 |
def run():
|
|
77 |
t = SmokeTest()
|
|
78 |
t.name = "filter_html_unit"
|
|
79 |
|
|
80 |
tests = unittest.makeSuite(TestFilterHtml)
|
|
81 |
result = unittest.TextTestRunner(verbosity=2).run(tests)
|
|
82 |
|
|
83 |
if result.wasSuccessful():
|
|
84 |
t.result = SmokeTest.PASS
|
|
85 |
else:
|
|
86 |
t.result = SmokeTest.FAIL
|
|
87 |
|
|
88 |
return t
|