buildframework/helium/tools/common/python/lib/cpythontest/test_relnotes.py
author wbernard
Wed, 23 Dec 2009 19:29:07 +0200
changeset 179 d8ac696cc51f
permissions -rw-r--r--
helium_7.0-r14027
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     1
#============================================================================ 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     2
#Name        : test_relnotes.py 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     3
#Part of     : Helium 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     4
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     6
#All rights reserved.
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     7
#This component and the accompanying materials are made available
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     9
#which accompanies this distribution, and is available
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    11
#
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    12
#Initial Contributors:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    14
#
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    15
#Contributors:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    16
#
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    17
#Description:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    18
#===============================================================================
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    19
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    20
""" Unit tests for the relnotes tool.
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    21
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    22
"""
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    23
import unittest
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    24
import StringIO
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    25
import rtfutils
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    26
import logging
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    27
import os
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    28
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    29
def test_initialization():
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    30
    "Modules are imported properly, i.e. PyRTF is there etc."
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    31
    import PyRTF
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    32
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    33
def test_pyrtf():
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    34
    import PyRTF
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    35
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    36
    DR = PyRTF.Renderer()
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    37
    doc     = PyRTF.Document()
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    38
    ss      = doc.StyleSheet
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    39
    section = PyRTF.Section()
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    40
    doc.Sections.append( section )
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    41
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    42
    string = StringIO.StringIO()
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    43
    DR.Write(doc, string)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    44
    assert string.getvalue() != ""
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    45
    string.close()
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    46
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    47
class RelNotesTest( unittest.TestCase ):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    48
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    49
    def setUp(self):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    50
        self.helium_home = os.environ["HELIUM_HOME"]
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    51
        self.logger = logging.getLogger('test.relnotes')
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    52
        logging.basicConfig(level=logging.INFO)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    53
      
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    54
    def test_rtfconvert(self):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    55
        props = {r'my.val1=hello world' : r'my.val1=hello world',
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    56
        r'my.val2=http://www.company.com/a' : r'my.val2={\\field{\\*\\fldinst HYPERLINK http://www.company.com/a}}',
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    57
        r'my.val3=ftp://ftp.company.com/a' : r'my.val3={\\field{\\*\\fldinst HYPERLINK ftp://ftp.company.com/a}}',
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    58
        r'my.val4=\\server\share1\dir' : r'my.val4={\\field{\\*\\fldinst HYPERLINK \\\\\\\\\\\\\\\\server\\\\\\\\share1\\\\\\\\dir}}',
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    59
        r'my.val5=.\projects' : r'my.val5={\\field{\\*\\fldinst HYPERLINK .\\\\\\\\projects}}'}
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    60
        
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    61
        for p, output in props.iteritems():
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    62
            self._check_rtfconvert(p, output)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    63
        
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    64
    def _check_rtfconvert(self, value, correctoutput):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    65
        output = StringIO.StringIO()
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    66
        rtfu = rtfutils.RTFUtils('')
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    67
        rtfu._rtfconvert([value], output)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    68
        self.logger.info(output.getvalue())
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    69
        self.logger.info(correctoutput) 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    70
        assert output.getvalue() == correctoutput #.strip()
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    71
        output.close()
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    72
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    73
    def test_rtftable(self):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    74
        output = StringIO.StringIO()
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    75
        errors = ["component,error,warning", "app2,1,2"]
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    76
        input = ["text <tag> text"]
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    77
        
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    78
        rtfu = rtfutils.RTFUtils('')
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    79
        rtfu._rtftable(errors, output, '<tag>', input)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    80
        
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    81
        self.logger.info(output.getvalue())
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    82
        output.close()
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    83
        
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    84
    def test_rtfimage(self):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    85
        output = StringIO.StringIO()
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    86
        image = os.path.join(self.helium_home, 'extensions', 'nokia', 'config', 'relnotes', 'logo.png')
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    87
        input = ["text <tag> text"]
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    88
        
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    89
        rtfu = rtfutils.RTFUtils('')
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    90
        rtfu._rtfimage(image, output, '<tag>', input)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    91
        
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    92
        self.logger.info(output.getvalue())
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    93
        output.close()