buildframework/helium/sf/python/pythoncore/lib/pythoncoretests/test_escapeddict.py
author wbernard
Tue, 27 Apr 2010 08:33:08 +0300
changeset 587 85df38eb4012
child 588 c7c26511138f
permissions -rw-r--r--
helium_9.0-a7879c935424
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_escapeddict.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
#===============================================================================
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
import unittest
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import escapeddict
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
logger = logging.getLogger('test.escapeddict')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
class EscapedDictTest(unittest.TestCase):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
    """ Acceptance tests for escapeddict.py """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
    def test_escape(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
        testdict = escapeddict.EscapedDict({'key1': 'value1', 'key2': 'value2 ${key1}'})
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
        for key in testdict.keys():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
            logger.info(testdict[key])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
        assert testdict['key1'] == 'value1'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
        assert testdict['key2'] == 'value2 value1'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
    def test_escape_no_value_present(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
        testdict = escapeddict.EscapedDict({'key1': 'value1', 'key2': 'value2 ${key_not_present} ${key1}'})
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
        for key in testdict.keys():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
            print testdict[key]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
        assert testdict['key1'] == 'value1'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
        assert testdict['key2'] == 'value2 ${key_not_present} value1'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
    def test_escape_value_as_list(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
        testdict = escapeddict.EscapedDict({'key1': 'value1', 'key2': ['value2', '${key1}']})
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
        for key in testdict.keys():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
            print testdict[key]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
        assert testdict['key1'] == 'value1'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
        assert testdict['key2'] == ['value2', 'value1']