buildframework/helium/sf/python/pythoncore/lib/pythoncorecpythontests/test_atsconfigparser.py
author lorewang
Wed, 01 Dec 2010 16:05:36 +0800
changeset 715 e0739b8406dd
parent 645 b8d81fa19e7d
permissions -rw-r--r--
Specify extenal tool with path
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_atsconfigparser.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
""" Testing the ATS configuration file """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import tempfile
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import unittest
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import ats3.atsconfigparser
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
_logger = logging.getLogger('test.atsconfigparser')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
logging.basicConfig(level=logging.INFO)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
class AtsConfigParserTest(unittest.TestCase):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
    """class used to test ATS config parser"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
    def test_converttestxml(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
        """setup test data, call the convert to XML method (part being tested) 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
        then check it is correct"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
        spectext = """<ATSConfigData>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
    <config name="common" abstract="true">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
        <!-- Properties to add/modify -->
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
        <config type="properties">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
           <set name="HARNESS" value="STIFx" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
           <set name="HARNESS2" value="STIF2"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
           <set name="HARNESS3" value="STIF2"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
           <set name="2" value="3" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
        </config>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
        <!-- Attributes to modify -->
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
        <config type="attributes">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
           <set name="xyz" value="2" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
           <set name="significant" value="true" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
        </config>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
        <!-- Settings to add/modify -->
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
        <config type="settings">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
           <set name="HARNESS" value="STIF" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
           <set name="2" value="3" />
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
        </config>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
    </config>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
</ATSConfigData>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
        testxmldata = """<test>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
  <name>helium_clock</name>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
  <target>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
    <device alias="DEFAULT_STIF" rank="none">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
      <property name="HARNESS" value="STIF"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
      <property name="HARNESS2" value="STIF"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
      <property name="HARNESS3" value="STIF"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
    </device>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
    <device alias="DEFAULT_EUIT" rank="none">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
      <property name="HARNESS" value="STIF"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
      <property name="HARNESS2" value="STIF3"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
    </device>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
  </target>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
  <plan passrate="100" harness="STIF" enabled="true" name="helium_clock Plan" significant="false">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
    <session passrate="100" harness="STIF" enabled="true" name="session" significant="false">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
      <set passrate="100" harness="STIF" enabled="true" name="set0" significant="false">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
        <target>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
          <device alias="DEFAULT_STIF" rank="master"/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
        </target>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
      </set>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
    </session>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
  </plan>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
</test>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
        (file_descriptor, filename) = tempfile.mkstemp()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
        file_handle = os.fdopen(file_descriptor, 'w')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
        file_handle.write(spectext)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
        file_handle.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
        output = ats3.atsconfigparser.converttestxml(filename, testxmldata)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
        os.remove(filename)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
        _logger.info(output)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
        self.assert_( '<property name="2" value="3"/>' in output)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
        self.assert_( '<property name="HARNESS" value="STIFx"/>' in output)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
        self.assert_( '<property name="HARNESS" value="STIF"/>' not in output)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
        self.assert_( '<property name="HARNESS2" value="STIF2"/>' in output)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
        self.assert_( '<property name="HARNESS2" value="STIF3"/>' not in output)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
        self.assert_( '<property name="HARNESS3" value="STIF2"/>' in output)
645
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   103
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   104
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   105
    def test_converttestxml_ats4(self):
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   106
        spectext = """<ATSConfigData>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   107
    <config name="common" abstract="true">
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   108
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   109
        <!-- Properties to add/modify -->
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   110
        <config type="properties">
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   111
           <set name="HARNESS" value="STIFx" />
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   112
           <set name="HARNESS2" value="STIF2"/>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   113
           <set name="HARNESS3" value="STIF2"/>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   114
           <set name="2" value="3" />
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   115
        </config>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   116
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   117
        <!-- Attributes to modify -->
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   118
        <config type="attributes">
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   119
           <set name="xyz" value="2" />
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   120
           <set name="significant" value="true" />
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   121
        </config>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   122
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   123
    </config>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   124
</ATSConfigData>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   125
        """
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   126
        testxmldataats4 = """<testrun>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   127
    <metadata>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   128
        <meta name="name">mybuild</meta> 
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   129
    </metadata>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   130
    
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   131
    <agents>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   132
        <agent alias="DEFAULT_GENERIC">
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   133
            <property name="hardware" value="product"/>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   134
        </agent>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   135
    </agents>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   136
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   137
    <execution defaultAgent="DEFAULT_GENERIC">
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   138
        <initialization>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   139
        </initialization>    
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   140
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   141
        <finalization>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   142
        </finalization>    
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   143
    </execution>    
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   144
    
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   145
    <postActions>        
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   146
    </postActions>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   147
</testrun>
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   148
        """
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   149
        
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   150
        (file_descriptor, filename) = tempfile.mkstemp()
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   151
        file_handle = os.fdopen(file_descriptor, 'w')
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   152
        file_handle.write(spectext)
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   153
        file_handle.close()
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   154
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   155
        output = ats3.atsconfigparser.converttestxml(filename, testxmldataats4)
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   156
        os.remove(filename)
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   157
        
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   158
        self.assert_( '<property name="2" value="3"/>' in output)
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   159
        self.assert_( '<property name="HARNESS" value="STIFx"/>' in output)
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   160
        self.assert_( '<property name="HARNESS" value="STIF"/>' not in output)
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   161
        self.assert_( '<property name="HARNESS2" value="STIF2"/>' in output)
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   162
        self.assert_( '<property name="HARNESS2" value="STIF3"/>' not in output)
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents: 587
diff changeset
   163
        self.assert_( '<property name="HARNESS3" value="STIF2"/>' in output)