buildframework/helium/tools/common/python/lib/cpythontest/test_relnotes.py
changeset 179 d8ac696cc51f
equal deleted inserted replaced
1:be27ed110b50 179:d8ac696cc51f
       
     1 #============================================================================ 
       
     2 #Name        : test_relnotes.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 #===============================================================================
       
    19 
       
    20 """ Unit tests for the relnotes tool.
       
    21 
       
    22 """
       
    23 import unittest
       
    24 import StringIO
       
    25 import rtfutils
       
    26 import logging
       
    27 import os
       
    28 
       
    29 def test_initialization():
       
    30     "Modules are imported properly, i.e. PyRTF is there etc."
       
    31     import PyRTF
       
    32 
       
    33 def test_pyrtf():
       
    34     import PyRTF
       
    35     
       
    36     DR = PyRTF.Renderer()
       
    37     doc     = PyRTF.Document()
       
    38     ss      = doc.StyleSheet
       
    39     section = PyRTF.Section()
       
    40     doc.Sections.append( section )
       
    41     
       
    42     string = StringIO.StringIO()
       
    43     DR.Write(doc, string)
       
    44     assert string.getvalue() != ""
       
    45     string.close()
       
    46     
       
    47 class RelNotesTest( unittest.TestCase ):
       
    48     
       
    49     def setUp(self):
       
    50         self.helium_home = os.environ["HELIUM_HOME"]
       
    51         self.logger = logging.getLogger('test.relnotes')
       
    52         logging.basicConfig(level=logging.INFO)
       
    53       
       
    54     def test_rtfconvert(self):
       
    55         props = {r'my.val1=hello world' : r'my.val1=hello world',
       
    56         r'my.val2=http://www.company.com/a' : r'my.val2={\\field{\\*\\fldinst HYPERLINK http://www.company.com/a}}',
       
    57         r'my.val3=ftp://ftp.company.com/a' : r'my.val3={\\field{\\*\\fldinst HYPERLINK ftp://ftp.company.com/a}}',
       
    58         r'my.val4=\\server\share1\dir' : r'my.val4={\\field{\\*\\fldinst HYPERLINK \\\\\\\\\\\\\\\\server\\\\\\\\share1\\\\\\\\dir}}',
       
    59         r'my.val5=.\projects' : r'my.val5={\\field{\\*\\fldinst HYPERLINK .\\\\\\\\projects}}'}
       
    60         
       
    61         for p, output in props.iteritems():
       
    62             self._check_rtfconvert(p, output)
       
    63         
       
    64     def _check_rtfconvert(self, value, correctoutput):
       
    65         output = StringIO.StringIO()
       
    66         rtfu = rtfutils.RTFUtils('')
       
    67         rtfu._rtfconvert([value], output)
       
    68         self.logger.info(output.getvalue())
       
    69         self.logger.info(correctoutput) 
       
    70         assert output.getvalue() == correctoutput #.strip()
       
    71         output.close()
       
    72 
       
    73     def test_rtftable(self):
       
    74         output = StringIO.StringIO()
       
    75         errors = ["component,error,warning", "app2,1,2"]
       
    76         input = ["text <tag> text"]
       
    77         
       
    78         rtfu = rtfutils.RTFUtils('')
       
    79         rtfu._rtftable(errors, output, '<tag>', input)
       
    80         
       
    81         self.logger.info(output.getvalue())
       
    82         output.close()
       
    83         
       
    84     def test_rtfimage(self):
       
    85         output = StringIO.StringIO()
       
    86         image = os.path.join(self.helium_home, 'extensions', 'nokia', 'config', 'relnotes', 'logo.png')
       
    87         input = ["text <tag> text"]
       
    88         
       
    89         rtfu = rtfutils.RTFUtils('')
       
    90         rtfu._rtfimage(image, output, '<tag>', input)
       
    91         
       
    92         self.logger.info(output.getvalue())
       
    93         output.close()