buildframework/helium/sf/python/pythoncore/lib/pythoncoretests/test_configuration.py
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
child 645 b8d81fa19e7d
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
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_configuration.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
#===============================================================================
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    19
""" test configuration """
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    20
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    21
# pylint: disable=R0201
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import StringIO
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import unittest
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import tempfile
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import sys
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
import configuration
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
_logger = logging.getLogger('test.configuration')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
logging.basicConfig(level=logging.INFO)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
class NestedConfigurationBuilderTest(unittest.TestCase):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
    """ Acceptance tests for NestedConfigurationBuilder of configuration.py """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
    def setUp(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
        """ Setup. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
        config_file = open(os.path.join(os.environ['TEST_DATA'], 'data/config_test.cfg.xml'), 'r')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
        self._builder = configuration.NestedConfigurationBuilder(config_file)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
    def test_config_parsing(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
        """A basic configuration can be parsed."""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
        config_set = self._builder.getConfiguration()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
        configs = config_set.getConfigurations()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
        assert len(configs) == 10
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
        for config in configs:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
            print
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
            for k in config.keys():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
                print k + ': ' + str(config[k])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
        assert configs[0]['A'] == 'foo'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
        assert configs[0]['B'] == 'child -> foo'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
        assert configs[0]['C'] == 'missing value test ${does_not_exist}'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
        assert configs[0]['node.content'].strip() == 'This is the value!'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
        assert configs[1]['A'] == 'foo'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
        assert configs[1]['B'] == 'parent: foo'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
        assert configs[1]['C'] == ['one', 'two']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
        assert 'C' in configs[1]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
        assert 'Z' not in configs[1]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        configs = config_set.getConfigurations('spec.with.type')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
        assert len(configs) == 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
        assert configs[0].type == 'test.type', "config.type must match 'test.type'."
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
        
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    66
        configs = config_set.getConfigurations(type_='test.type')
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
        assert len(configs) == 2
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
        assert configs[0].type == 'test.type', "config.type must match 'test.type'."
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    70
        configs = config_set.getConfigurations(name='test_spec', type_='test.type')
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        assert len(configs) == 2
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
        assert configs[0].type == 'test.type', "config.type must match 'test.type'."
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
    def test_append(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        """A child value can be appended to a parent value."""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        configs = self._builder.getConfigurations()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
        config = configs[4]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
        assert config['A'] == ['foo', 'bar']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
    def test_parent_interpolated_by_child(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
        """ A child value can be interpolated into a parent template. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
        configs = self._builder.getConfigurations()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
        parent_config = configs[5]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
        child_config = configs[6]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
        assert parent_config['template'] == 'value -> from parent'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
        assert child_config['template'] == 'value -> from child'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
     
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
    def test_property_escaping(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
        """ Property values can be escaped in the values of other properties. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
        config_text = """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
<build>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
    <config name="test_spec">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
        <set name="A" value="foo"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
        <set name="B" value="A = ${A}"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
    </config>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
</build>"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
        builder = configuration.NestedConfigurationBuilder(StringIO.StringIO(config_text))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
        config = builder.getConfiguration().getConfigurations()[0]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
        print config['B']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
        #assert configs[1]['C'] == ['one', 'two']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
    def test_any_root_element(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
        """ Any root element name can be used. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
        config_text = """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
<someConfigData>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
    <config name="test_spec">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
        <set name="A" value="foo"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
    </config>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
</someConfigData>"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
        builder = configuration.NestedConfigurationBuilder(StringIO.StringIO(config_text))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
        config = builder.getConfiguration().getConfigurations()[0]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
        assert config['A'] == 'foo'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
    def test_list_templating(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
        """ Testing list templating. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
        configs = self._builder.getConfigurations('test_list_config1')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
        # should return only one config.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
        assert len(configs) == 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
        _logger.debug(configs[0].get_list('include', []))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
        result = configs[0].get_list('include', [])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
        result.sort()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   125
        print result
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
        assert len(result) == 3
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
        assert result == [u'bar1_config1', u'bar2_config1', u'foo_config1']        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
    def test_list_templating2(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
        """ Testing list templating 2. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
        configs = self._builder.getConfigurations('test_list_config2')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
        # should return only one config.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
        assert len(configs) == 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
        _logger.debug(configs[0].get_list('include', []))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
        result = configs[0].get_list('include', [])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
        result.sort()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
        print result
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
        assert len(result) == 3
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
        assert result == [u'bar1_config2', u'bar2_config2', u'foo_config2']        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
    def test_append_list(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
        """ Testing if append handles the list correctly..."""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
        config_text = """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
<build>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   147
<config name="prebuild_zip" abstract="true">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
   <set name="exclude" value="**/_ccmwaid.inf" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
   <set name="exclude" value="build/**" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
   <set name="exclude" value="config/**" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
   <set name="exclude" value="ncp_sw/**" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
   <set name="exclude" value="ppd_sw/**" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
   <set name="exclude" value="psw/**" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   154
   <set name="exclude" value="tools/**" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
   <set name="include" value="foo/**" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   156
   <config>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   157
    <set name="root.dir" value="X:/rootdir" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
    <set name="name" value="PF5250_200832_internal_code" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   159
    <set name="include" value="**/internal/**" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   160
    <set name="grace.filters" value="tsrc" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   161
    <set name="grace.default" value="false" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162
   </config>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   163
   <config>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   164
    <set name="root.dir" value="X:/rootdir" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   165
    <set name="name" value="PF5250_200832_doc" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   166
    <append name="include" value="**/doc/**" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   167
    <set name="include" value="**/docs/**" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
    <append name="exclude" value="**/internal/**" />                            <!-- set changed to append -->
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   169
    <set name="grace.filters" value="tsrc" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   170
    <set name="grace.default" value="false" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   171
   </config>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   172
  </config>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   173
</build>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   174
"""        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   175
        builder = configuration.NestedConfigurationBuilder(StringIO.StringIO(config_text))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   176
        configs = builder.getConfigurations()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
        config = configs[1]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
        print config['exclude']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
        print config['include']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   180
        exclude_match = [u'**/_ccmwaid.inf', u'build/**', u'config/**',
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   181
                                          u'ncp_sw/**', u'ppd_sw/**', u'psw/**', u'tools/**',
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
                                          u'**/internal/**']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   183
        exclude_result = config['exclude']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   184
        exclude_match.sort()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   185
        exclude_result.sort()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   186
        assert len(config['include']) == 3
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
        assert exclude_result == exclude_match
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
        config = configs[0]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
        assert config['include'] == '**/internal/**'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
        assert len(config['exclude']) == 7
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
    def test_writeToXML(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   194
        """ To write the configurations into XML file. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
        config_text = """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
<build>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
    <config name="test_spec">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
        <set name="A" value="foo"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
        <set name="B" value="A = ${A}"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
        <config name="test_spec_1">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   201
            <set name="A" value="foo"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   202
            <set name="B" value="A = ${A}"/>        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   203
        </config>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   204
        <config name="test_spec_2">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   205
            <set name="A" value="foo"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   206
            <set name="B" value="A = ${A}"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
            <config name="test_spec_3">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
                <set name="A" value="foo"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
                <set name="B" value="A = ${A}"/>        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
            </config>        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
        </config>        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   212
    </config>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
</build>"""    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   215
        builder = configuration.NestedConfigurationBuilder(StringIO.StringIO(config_text))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   216
        configSet = builder.getConfiguration()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   217
        configs = configSet.getConfigurations('test_spec_1')
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   218
        (_, outputFile) = tempfile.mkstemp('.tmp', 'zip_test')
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   219
        builder.writeToXML(outputFile, configs, 'test_spec_1')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
        builder = configuration.NestedConfigurationBuilder(open(outputFile), 'r')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   222
        configSet = builder.getConfiguration()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   223
        configs = configSet.getConfigurations('test_spec_1')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   224
        config = configs[0]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   225
        assert config['A'] == 'foo'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   226
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   227
        builder = configuration.NestedConfigurationBuilder(StringIO.StringIO(config_text))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   228
        configSet = builder.getConfiguration()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   229
        configs = configSet.getConfigurations('test_spec')
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   230
        (_, outputFile) = tempfile.mkstemp('.tmp', 'zip_test')
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   231
        builder.writeToXML(outputFile, configs )
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   232
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   233
        builder = configuration.NestedConfigurationBuilder(open(outputFile), 'r')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   234
        configSet = builder.getConfiguration()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   235
        configs = configSet.getConfigurations('test_spec')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   236
        config = configs[0]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   237
        assert config['B'] == 'A = foo'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   238
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   239
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   240
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   241
class PropertiesConfigurationTest(unittest.TestCase):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   242
    """ Test plain text configuration files. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   243
    def test_text_config(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   244
        """ Basic text properties can be read. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   245
        config = configuration.PropertiesConfiguration(open(os.path.join(os.environ['TEST_DATA'], 'data/ant_config_test.txt'), 'r'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   246
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   247
        assert config['text.a'] == 'text.value.A'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   248
        assert config['text.b'] == 'text.value.B'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   249
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   250
    def test_text_config_store(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   251
        """ Basic text properties can be read. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   252
        config = configuration.PropertiesConfiguration(open(os.path.join(os.environ['TEST_DATA'], 'data/ant_config_test.txt'), 'r'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   253
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   254
        config['foo'] = "bar"
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   255
        (f_d, filename) = tempfile.mkstemp()
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   256
        f_file = os.fdopen(f_d, 'w')
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   257
        config.store(f_file)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   258
        config = configuration.PropertiesConfiguration(open(filename))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   259
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   260
        assert config['text.a'] == 'text.value.A'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   261
        assert config['text.b'] == 'text.value.B'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   262
        assert config['foo'] == 'bar'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   263
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   264