buildframework/helium/tools/common/python/lib/test/test_atsconfiguration.py
changeset 179 d8ac696cc51f
parent 1 be27ed110b50
child 180 e02a83d4c571
child 592 3215c239276a
equal deleted inserted replaced
1:be27ed110b50 179:d8ac696cc51f
     1 # -*- encoding: latin-1 -*-
       
     2 
       
     3 #============================================================================ 
       
     4 #Name    : test_ATSconfiguration.py 
       
     5 #Part of     : Helium 
       
     6 
       
     7 #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     8 #All rights reserved.
       
     9 #This component and the accompanying materials are made available
       
    10 #under the terms of the License "Eclipse Public License v1.0"
       
    11 #which accompanies this distribution, and is available
       
    12 #at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    13 #
       
    14 #Initial Contributors:
       
    15 #Nokia Corporation - initial contribution.
       
    16 #
       
    17 #Contributors:
       
    18 #
       
    19 #Description:
       
    20 #===============================================================================
       
    21 
       
    22 """ Testing the ATS configuration file """
       
    23 
       
    24 import logging
       
    25 import StringIO
       
    26 import unittest
       
    27 
       
    28 import configuration
       
    29 import ats3.parsers
       
    30 
       
    31 _logger = logging.getLogger('test.atsconfiguration')
       
    32 logging.basicConfig(level=logging.INFO)
       
    33 
       
    34 
       
    35 
       
    36 def test_ATS_element():
       
    37     """ ATS elements can be used in configuration. """
       
    38     config_text = """
       
    39 <ATSConfigData>
       
    40     <config name="properties">
       
    41     <set name="PA" value="foo"/>
       
    42     </config>
       
    43     <config name="attributes">
       
    44     <set name="attrs" value="foo"/>
       
    45     <set name="AB" value="100"/>
       
    46     <set name="AC" value="101"/>
       
    47     </config>
       
    48 </ATSConfigData>"""
       
    49 
       
    50     builder = configuration.NestedConfigurationBuilder(StringIO.StringIO(config_text))
       
    51     config = builder.getConfiguration().getConfigurations()
       
    52     assert config[0]['PA'] == 'foo'
       
    53     assert config[1]['AB'] == '100'
       
    54 
       
    55 
       
    56 
       
    57 def test_ATS_config_attirbutes():
       
    58     """ ATS elements can be used attributes only. """
       
    59     config_text = """
       
    60 <ATSConfigData>
       
    61     <config name="attributes">
       
    62     <set name="attrs" value="foo"/>
       
    63     <set name="AB" value="100"/>
       
    64     <set name="AC" value="101"/>
       
    65     </config>
       
    66 </ATSConfigData>"""
       
    67     (params, attrs) = ats3.parsers.split_config_to_attributes_and_properties(StringIO.StringIO(config_text))
       
    68 
       
    69     print attrs
       
    70     print params
       
    71     assert params ==  {}
       
    72     assert attrs ==  {u'attrs': u'foo', u'AC': u'101', u'AB': u'100'}
       
    73 
       
    74 def test_ATS_config_properties():
       
    75     """ ATS elements can be used properties only. """
       
    76     config_text = """
       
    77 <ATSConfigData>
       
    78     <config name="noattributes">
       
    79     <set name="attrs" value="foo"/>
       
    80     <set name="AB" value="100"/>
       
    81     <set name="AC" value="101"/>
       
    82     </config>
       
    83     <config name="properties">
       
    84     <set name="HW" value="foo"/>
       
    85     </config>
       
    86 </ATSConfigData>"""
       
    87     (params, attrs) = ats3.parsers.split_config_to_attributes_and_properties(StringIO.StringIO(config_text))
       
    88 
       
    89     print attrs
       
    90     print params
       
    91     assert params ==  {u'HW': u'foo' }
       
    92     assert attrs ==  { }
       
    93 
       
    94 
       
    95 def test_ATS_element3():
       
    96     """ All alements can be used and several times. """
       
    97     config_text = """
       
    98 <ATSConfigData>
       
    99     <config name="attributes">
       
   100     <set name="attrs" value="foo"/>
       
   101     <set name="AB" value="100"/>
       
   102     <set name="AC" value="101"/>
       
   103     </config>
       
   104     <config name="properties">
       
   105     <set name="PA" value="foo"/>
       
   106     </config>
       
   107     <config name="properties">
       
   108     <set name="HW" value="bar"/>
       
   109     </config>
       
   110 </ATSConfigData>"""
       
   111     	
       
   112     (params, attrs) = ats3.parsers.split_config_to_attributes_and_properties(StringIO.StringIO(config_text))
       
   113 
       
   114     print attrs
       
   115     print params
       
   116     assert params ==  {u'PA': u'foo' , u'HW': u'bar'}
       
   117     assert attrs ==  {u'attrs': u'foo', u'AC': u'101', u'AB': u'100'}
       
   118 
       
   119 
       
   120